From d36e96cb8510b31067f0ba04c783fbd5842f3104 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 6 Aug 2023 20:17:43 +0000 Subject: [PATCH] fixed various exception docblocks --- Ai/Ocr/BasicOcr.php | 4 + Algorithm/PathFinding/JumpPointSearch.php | 2 + Application/ApplicationInfo.php | 4 + Application/ApplicationManager.php | 8 +- Application/InstallerAbstract.php | 8 +- Application/StatusAbstract.php | 11 +- Application/UninstallerAbstract.php | 2 +- Autoloader.php | 8 +- DataStorage/Cache/Connection/FileCache.php | 6 + DataStorage/Cache/Connection/MemCached.php | 6 + DataStorage/Cache/Connection/RedisCache.php | 2 + .../Database/Connection/MysqlConnection.php | 2 +- .../Connection/PostgresConnection.php | 2 +- .../Database/Connection/SQLiteConnection.php | 4 +- .../Connection/SqlServerConnection.php | 2 +- DataStorage/Database/GrammarAbstract.php | 2 + DataStorage/Database/Mapper/UpdateMapper.php | 2 + DataStorage/Database/Mapper/WriteMapper.php | 2 + DataStorage/Database/Query/Builder.php | 9 ++ .../Database/Query/Grammar/Grammar.php | 2 + DataStorage/Session/HttpSession.php | 27 +++- DataStorage/Session/JWT.php | 134 ++++++++++++++++++ Localization/L11nManager.php | 2 - Localization/LanguageDetection/Language.php | 2 + Localization/LanguageDetection/Trainer.php | 2 + Localization/Localization.php | 2 + Log/FileLogger.php | 2 + Math/Matrix/LUDecomposition.php | 3 + Math/Matrix/Matrix.php | 6 +- Math/Matrix/QRDecomposition.php | 3 + Math/Number/Complex.php | 2 - Math/Number/Integer.php | 2 +- Math/Parser/Evaluator.php | 2 - Math/Statistic/Average.php | 4 + .../Regression/LevelLogRegression.php | 2 + .../Regression/LogLevelRegression.php | 2 + .../Forecast/Regression/LogLogRegression.php | 2 + Math/Statistic/MeasureOfDispersion.php | 1 - Math/Topology/Metrics2D.php | 4 + Math/Topology/MetricsND.php | 16 +++ Message/Cli/CliRequest.php | 2 + Message/Http/HttpHeader.php | 12 +- Message/Http/HttpRequest.php | 4 +- Message/Http/HttpResponse.php | 2 - Message/Mail/Email.php | 4 +- Message/Socket/SocketResponse.php | 2 - Module/InstallerAbstract.php | 8 +- Module/ModuleInfo.php | 4 + Module/ModuleManager.php | 8 +- Module/PackageManager.php | 2 + Module/StatusAbstract.php | 7 +- Module/UninstallerAbstract.php | 2 +- Stdlib/Base/EnumArray.php | 2 +- Stdlib/Base/Iban.php | 2 + System/File/Ftp/Directory.php | 4 + System/File/Ftp/File.php | 4 + System/File/Ftp/FtpStorage.php | 14 ++ System/File/Local/Directory.php | 8 +- System/File/Local/File.php | 4 + System/File/Local/FileAbstract.php | 4 + System/File/Local/LocalStorage.php | 14 ++ System/SystemUtils.php | 6 + Uri/HttpUri.php | 2 + Utils/ArrayUtils.php | 5 + Utils/Barcode/BarAbstract.php | 2 + Utils/Barcode/CodeAbstract.php | 4 + Utils/Barcode/TwoDAbstract.php | 2 + Utils/Compression/LZW.php | 2 + Utils/Converter/Currency.php | 6 - Utils/Converter/Measurement.php | 44 ++++++ Utils/Converter/Numeric.php | 2 - Utils/Encoding/Base64Url.php | 59 ++++++++ Utils/Encoding/Huffman/Dictionary.php | 4 +- Utils/Encoding/Huffman/Huffman.php | 2 + Utils/Git/Repository.php | 8 +- Utils/IO/Zip/Gz.php | 4 +- Utils/IO/Zip/Tar.php | 10 +- Utils/IO/Zip/TarGz.php | 4 +- Utils/IO/Zip/Zip.php | 10 +- Utils/ImageUtils.php | 3 + .../Presentation/PresentationWriter.php | 3 +- .../Parser/Spreadsheet/SpreadsheetParser.php | 3 + Utils/RnG/UUID.php | 3 + Utils/TaskSchedule/Cron.php | 10 ++ tests/Autoloader.php | 4 +- .../Database/Query/BuilderTest.php | 120 ++++++++-------- .../Database/Schema/BuilderTest.php | 14 +- tests/System/File/Ftp/DirectoryTest.php | 2 +- tests/System/File/Ftp/FileTest.php | 2 +- tests/System/File/Ftp/FtpStorageTest.php | 4 +- tests/System/File/Local/DirectoryTest.php | 2 +- tests/System/File/Local/FileTest.php | 2 +- tests/System/File/Local/LocalStorageTest.php | 4 +- tests/Utils/Git/RepositoryTest.php | 2 +- 94 files changed, 597 insertions(+), 178 deletions(-) create mode 100644 DataStorage/Session/JWT.php create mode 100644 Utils/Encoding/Base64Url.php diff --git a/Ai/Ocr/BasicOcr.php b/Ai/Ocr/BasicOcr.php index 764433035..260298e7f 100755 --- a/Ai/Ocr/BasicOcr.php +++ b/Ai/Ocr/BasicOcr.php @@ -77,6 +77,8 @@ final class BasicOcr * * @return array * + * @throws PathException + * * @since 1.0.0 */ private function readImages(string $path, int $limit = 0) : array @@ -145,6 +147,8 @@ final class BasicOcr * * @return array * + * @throws PathException + * * @since 1.0.0 */ private function readLabels(string $path, int $limit = 0) : array diff --git a/Algorithm/PathFinding/JumpPointSearch.php b/Algorithm/PathFinding/JumpPointSearch.php index 0c775ef35..085570237 100755 --- a/Algorithm/PathFinding/JumpPointSearch.php +++ b/Algorithm/PathFinding/JumpPointSearch.php @@ -503,6 +503,8 @@ final class JumpPointSearch implements PathFinderInterface * * @return null|JumpPointNode * + * @throws \Exception + * * @since 1.0.0 */ private static function jumpStraight(?JumpPointNode $node, ?JumpPointNode $pNode, JumpPointNode $endNode, Grid $grid) : ?JumpPointNode diff --git a/Application/ApplicationInfo.php b/Application/ApplicationInfo.php index 7fc1f16b2..3c842ca9c 100755 --- a/Application/ApplicationInfo.php +++ b/Application/ApplicationInfo.php @@ -96,6 +96,8 @@ final class ApplicationInfo * * @return void * + * @throws PathException + * * @since 1.0.0 */ public function update() : void @@ -116,6 +118,8 @@ final class ApplicationInfo * * @return void * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public function set(string $path, mixed $data, string $delim = '/') : void diff --git a/Application/ApplicationManager.php b/Application/ApplicationManager.php index 9dcd24a1e..1c84b8508 100755 --- a/Application/ApplicationManager.php +++ b/Application/ApplicationManager.php @@ -66,6 +66,8 @@ final class ApplicationManager * * @return ApplicationInfo * + * @throws PathException + * * @since 1.0.0 */ private function loadInfo(string $appPath) : ApplicationInfo @@ -117,7 +119,7 @@ final class ApplicationManager $classPath = \substr($path . '/Admin/Installer', (int) \strlen((string) \realpath(__DIR__ . '/../../'))); // @var class-string $class - $class = \str_replace('/', '\\', $classPath); + $class = \strtr($classPath, '/', '\\'); $class::install($this->app, $info, $this->app->appSettings); return true; @@ -149,7 +151,7 @@ final class ApplicationManager $classPath = \substr($path . '/Admin/Uninstaller', (int) \strlen((string) \realpath(__DIR__ . '/../../'))); // @var class-string $class - $class = \str_replace('/', '\\', $classPath); + $class = \strtr($classPath, '/', '\\'); $class::uninstall($this->app->dbPool, $info, $this->app->appSettings); $this->uninstallFiles($source); @@ -182,7 +184,7 @@ final class ApplicationManager // @var class-string $class $classPath = \substr($path . '/Admin/Installer', (int) \strlen((string) \realpath(__DIR__ . '/../../'))); - $class = \str_replace('/', '\\', $classPath); + $class = \strtr($classPath, '/', '\\'); /** @var $class InstallerAbstract */ $class::reInit($info); diff --git a/Application/InstallerAbstract.php b/Application/InstallerAbstract.php index dbd9f8d7f..83ff95c81 100755 --- a/Application/InstallerAbstract.php +++ b/Application/InstallerAbstract.php @@ -134,6 +134,8 @@ abstract class InstallerAbstract * * @return void * + * @throws \UnexpectedValueException + * * @since 1.0.0 */ protected static function activate(ApplicationAbstract $app, ApplicationInfo $info) : void @@ -145,7 +147,7 @@ abstract class InstallerAbstract $classPath = \substr($path . '/Status', (int) \strlen((string) \realpath(__DIR__ . '/../../'))); // @var class-string $class - $class = \str_replace('/', '\\', $classPath); + $class = \strtr($classPath, '/', '\\'); if (!Autoloader::exists($class)) { throw new \UnexpectedValueException($class); // @codeCoverageIgnore @@ -161,6 +163,8 @@ abstract class InstallerAbstract * * @return void * + * @throws \UnexpectedValueException + * * @since 1.0.0 */ public static function reInit(ApplicationInfo $info) : void @@ -172,7 +176,7 @@ abstract class InstallerAbstract $classPath = \substr($path . '/Status', (int) \strlen((string) \realpath(__DIR__ . '/../../'))); // @var class-string $class - $class = \str_replace('/', '\\', $classPath); + $class = \strtr($classPath, '/', '\\'); if (!Autoloader::exists($class)) { throw new \UnexpectedValueException($class); // @codeCoverageIgnore diff --git a/Application/StatusAbstract.php b/Application/StatusAbstract.php index d23f0fc04..2d41ba886 100755 --- a/Application/StatusAbstract.php +++ b/Application/StatusAbstract.php @@ -61,8 +61,6 @@ abstract class StatusAbstract * * @return void * - * @throws PermissionException - * * @since 1.0.0 */ public static function activateRoutes(ApplicationInfo $appInfo = null) : void @@ -77,8 +75,6 @@ abstract class StatusAbstract * * @return void * - * @throws PermissionException - * * @since 1.0.0 */ public static function activateHooks(ApplicationInfo $appInfo = null) : void @@ -94,6 +90,7 @@ abstract class StatusAbstract * * @return void * + * @throws PathException * @throws PermissionException * * @since 1.0.0 @@ -131,9 +128,6 @@ abstract class StatusAbstract * * @return void * - * @throws PathException - * @throws PermissionException - * * @since 1.0.0 */ public static function clearRoutes() : void @@ -146,9 +140,6 @@ abstract class StatusAbstract * * @return void * - * @throws PathException - * @throws PermissionException - * * @since 1.0.0 */ public static function clearHooks() : void diff --git a/Application/UninstallerAbstract.php b/Application/UninstallerAbstract.php index cfdd050e5..eacab27b8 100755 --- a/Application/UninstallerAbstract.php +++ b/Application/UninstallerAbstract.php @@ -68,7 +68,7 @@ abstract class UninstallerAbstract { $classPath = \substr(\realpath(static::PATH) . '/Status', \strlen(\realpath(__DIR__ . '/../../'))); - $class = \str_replace('/', '\\', $classPath); + $class = \strtr($classPath, '/', '\\'); $class::deactivate($dbPool, $info); }*/ diff --git a/Autoloader.php b/Autoloader.php index ed51ac661..602e5a77f 100755 --- a/Autoloader.php +++ b/Autoloader.php @@ -87,7 +87,7 @@ final class Autoloader { $found = []; $class = \ltrim($class, '\\'); - $class = \str_replace(['_', '\\'], '/', $class); + $class = \strtr($class, '_\\', '//'); foreach (self::$paths as $path) { if (\is_file($file = $path . $class . '.php')) { @@ -107,14 +107,12 @@ final class Autoloader * * @return void * - * @throws AutoloadException Throws this exception if the class to autoload doesn't exist. This could also be related to a wrong namespace/file path correlation. - * * @since 1.0.0 */ public static function defaultAutoloader(string $class) : void { $class = \ltrim($class, '\\'); - $class = \str_replace(['_', '\\'], '/', $class); + $class = \strtr($class, '_\\', '//'); foreach (self::$paths as $path) { if (\is_file($file = $path . $class . '.php')) { @@ -139,7 +137,7 @@ final class Autoloader public static function exists(string $class) : bool { $class = \ltrim($class, '\\'); - $class = \str_replace(['_', '\\'], '/', $class); + $class = \strtr($class, '_\\', '//'); foreach (self::$paths as $path) { if (\is_file($path . $class . '.php')) { diff --git a/DataStorage/Cache/Connection/FileCache.php b/DataStorage/Cache/Connection/FileCache.php index aef052249..c8cd5ecb5 100755 --- a/DataStorage/Cache/Connection/FileCache.php +++ b/DataStorage/Cache/Connection/FileCache.php @@ -87,6 +87,12 @@ final class FileCache extends ConnectionAbstract * Connect to cache * * @param null|array{0:string} $data Cache data (path to cache directory) + * + * @return void + * + * @throws InvalidConnectionConfigException + * + * @since 1.0.0 */ public function connect(array $data = null) : void { diff --git a/DataStorage/Cache/Connection/MemCached.php b/DataStorage/Cache/Connection/MemCached.php index 40fe60ecf..5051eafb6 100755 --- a/DataStorage/Cache/Connection/MemCached.php +++ b/DataStorage/Cache/Connection/MemCached.php @@ -70,6 +70,8 @@ final class MemCached extends ConnectionAbstract * * @return void * + * @throws InvalidConnectionConfigException + * * @since 1.0.0 */ public function connect(array $data = null) : void @@ -88,6 +90,8 @@ final class MemCached extends ConnectionAbstract /** * {@inheritdoc} + * + * @throws \InvalidArgumentException */ public function set(int | string $key, mixed $value, int $expire = -1) : void { @@ -104,6 +108,8 @@ final class MemCached extends ConnectionAbstract /** * {@inheritdoc} + * + * @throws \InvalidArgumentException */ public function add(int | string $key, mixed $value, int $expire = -1) : bool { diff --git a/DataStorage/Cache/Connection/RedisCache.php b/DataStorage/Cache/Connection/RedisCache.php index 93d3d0035..6d5f66f10 100755 --- a/DataStorage/Cache/Connection/RedisCache.php +++ b/DataStorage/Cache/Connection/RedisCache.php @@ -62,6 +62,8 @@ final class RedisCache extends ConnectionAbstract * * @return void * + * @throws InvalidConnectionConfigException + * * @since 1.0.0 */ public function connect(array $data = null) : void diff --git a/DataStorage/Database/Connection/MysqlConnection.php b/DataStorage/Database/Connection/MysqlConnection.php index 6a678907e..85ccedc71 100755 --- a/DataStorage/Database/Connection/MysqlConnection.php +++ b/DataStorage/Database/Connection/MysqlConnection.php @@ -80,7 +80,7 @@ final class MysqlConnection extends ConnectionAbstract $this->con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $this->status = DatabaseStatus::OK; - } catch (\PDOException $e) { + } catch (\PDOException $_) { $this->con = new NullPDO(); $this->status = DatabaseStatus::MISSING_DATABASE; } finally { diff --git a/DataStorage/Database/Connection/PostgresConnection.php b/DataStorage/Database/Connection/PostgresConnection.php index 5ed1239c1..faa449a37 100755 --- a/DataStorage/Database/Connection/PostgresConnection.php +++ b/DataStorage/Database/Connection/PostgresConnection.php @@ -80,7 +80,7 @@ final class PostgresConnection extends ConnectionAbstract $this->con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $this->status = DatabaseStatus::OK; - } catch (\PDOException $e) { + } catch (\PDOException $_) { $this->con = new NullPDO(); $this->status = DatabaseStatus::MISSING_DATABASE; } finally { diff --git a/DataStorage/Database/Connection/SQLiteConnection.php b/DataStorage/Database/Connection/SQLiteConnection.php index 858cae824..d068e6acd 100755 --- a/DataStorage/Database/Connection/SQLiteConnection.php +++ b/DataStorage/Database/Connection/SQLiteConnection.php @@ -62,6 +62,8 @@ final class SQLiteConnection extends ConnectionAbstract * * @return void * + * @throws \PDOException + * * @since 1.0.0 */ public function connect(array $dbdata = null) : void @@ -90,7 +92,7 @@ final class SQLiteConnection extends ConnectionAbstract $this->con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $this->status = DatabaseStatus::OK; - } catch (\PDOException $e) { + } catch (\PDOException $_) { $this->con = new NullPDO(); $this->status = DatabaseStatus::MISSING_DATABASE; } finally { diff --git a/DataStorage/Database/Connection/SqlServerConnection.php b/DataStorage/Database/Connection/SqlServerConnection.php index acecbe10c..355049032 100755 --- a/DataStorage/Database/Connection/SqlServerConnection.php +++ b/DataStorage/Database/Connection/SqlServerConnection.php @@ -80,7 +80,7 @@ final class SqlServerConnection extends ConnectionAbstract $this->con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $this->status = DatabaseStatus::OK; - } catch (\PDOException $e) { + } catch (\PDOException $_) { $this->con = new NullPDO(); $this->status = DatabaseStatus::MISSING_DATABASE; } finally { diff --git a/DataStorage/Database/GrammarAbstract.php b/DataStorage/Database/GrammarAbstract.php index 9fcaa7eb9..2a1675cfb 100755 --- a/DataStorage/Database/GrammarAbstract.php +++ b/DataStorage/Database/GrammarAbstract.php @@ -186,6 +186,8 @@ abstract class GrammarAbstract * * @return string * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ protected function expressionizeTableColumn(array $elements, bool $column = true) : string diff --git a/DataStorage/Database/Mapper/UpdateMapper.php b/DataStorage/Database/Mapper/UpdateMapper.php index 8055f2095..cc80ca949 100755 --- a/DataStorage/Database/Mapper/UpdateMapper.php +++ b/DataStorage/Database/Mapper/UpdateMapper.php @@ -220,6 +220,8 @@ final class UpdateMapper extends DataMapperAbstract * * @return void * + * @throws InvalidMapperException + * * @since 1.0.0 */ private function updateHasMany(\ReflectionClass $refClass, object $obj, mixed $objId) : void diff --git a/DataStorage/Database/Mapper/WriteMapper.php b/DataStorage/Database/Mapper/WriteMapper.php index 37e957602..0645aaee4 100755 --- a/DataStorage/Database/Mapper/WriteMapper.php +++ b/DataStorage/Database/Mapper/WriteMapper.php @@ -254,6 +254,8 @@ final class WriteMapper extends DataMapperAbstract * * @return void * + * @throws InvalidMapperException + * * @since 1.0.0 */ private function createHasMany(\ReflectionClass $refClass, object $obj, mixed $objId) : void diff --git a/DataStorage/Database/Query/Builder.php b/DataStorage/Database/Query/Builder.php index 3aefb90de..881294d0c 100755 --- a/DataStorage/Database/Query/Builder.php +++ b/DataStorage/Database/Query/Builder.php @@ -269,6 +269,8 @@ class Builder extends BuilderAbstract * * @return Builder * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public function select(mixed ...$columns) : self @@ -488,6 +490,8 @@ class Builder extends BuilderAbstract * * @return Builder * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public function from(mixed ...$tables) : self @@ -655,6 +659,8 @@ class Builder extends BuilderAbstract * * @return Builder * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public function groupBy(mixed ...$columns) : self @@ -1026,6 +1032,7 @@ class Builder extends BuilderAbstract * @return Builder * * @throws \Exception + * @throws \InvalidArgumentException * * @since 1.0.0 */ @@ -1296,6 +1303,8 @@ class Builder extends BuilderAbstract * * @return Builder * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public function on(string | array $columns, string | array $operator = null, mixed $values = null, string | array $boolean = 'and', string $table = null) : self diff --git a/DataStorage/Database/Query/Grammar/Grammar.php b/DataStorage/Database/Query/Grammar/Grammar.php index 0e700f357..ccf5d93a9 100755 --- a/DataStorage/Database/Query/Grammar/Grammar.php +++ b/DataStorage/Database/Query/Grammar/Grammar.php @@ -37,6 +37,8 @@ class Grammar extends GrammarAbstract { /** * {@inheritdoc} + * + * @throws \InvalidArgumentException */ protected function compileComponents(BuilderAbstract $query) : array { diff --git a/DataStorage/Session/HttpSession.php b/DataStorage/Session/HttpSession.php index ecc31f024..0b14a84c3 100755 --- a/DataStorage/Session/HttpSession.php +++ b/DataStorage/Session/HttpSession.php @@ -16,6 +16,8 @@ namespace phpOMS\DataStorage\Session; use phpOMS\DataStorage\LockException; use phpOMS\Log\FileLogger; +use phpOMS\Message\RequestAbstract; +use phpOMS\Session\JWT; use phpOMS\Uri\UriFactory; /** @@ -69,8 +71,6 @@ final class HttpSession implements SessionInterface * @param string $sid Session id * @param int $inactivityInterval Interval for session activity * - * @throws LockException throws this exception if the session is alrady locked for further interaction - * * @since 1.0.0 */ public function __construct(int $liftetime = 3600, string $sid = '', int $inactivityInterval = 0) @@ -141,6 +141,29 @@ final class HttpSession implements SessionInterface UriFactory::setQuery('$CSRF', $csrf); /* @phpstan-ignore-line */ } + public function populateFromRequest(string $secret, RequestAbstract $request) : void + { + $authentication = $request->header->get('Authorization'); + if (\count($authentication) !== 1) { + return; + } + + $explode = \explode(' ', $authentication[0]); + if (\count($explode) !== 2) { + return; + } + + $token = \trim($explode[1]); + $header = JWT::getHeader($token); + + if (($header['typ'] ?? '') !== 'jwt' || !JWT::validateJWT($secret, $token)) { + return; + } + + $payload = JWT::getPayload($token); + $this->set('UID', (int) ($payload['uid'] ?? 0)); + } + /** * {@inheritdoc} */ diff --git a/DataStorage/Session/JWT.php b/DataStorage/Session/JWT.php new file mode 100644 index 000000000..741206d8c --- /dev/null +++ b/DataStorage/Session/JWT.php @@ -0,0 +1,134 @@ +locale = \str_replace('-', '_', $locals[0]); // @codeCoverageIgnore + $this->locale = \strtr($locals[0], '-', '_'); // @codeCoverageIgnore return $this->locale; } @@ -661,6 +661,8 @@ final class HttpRequest extends RequestAbstract * * @return int * + * @throws \Exception + * * @since 1.0.0 */ public function getRouteVerb() : int diff --git a/Message/Http/HttpResponse.php b/Message/Http/HttpResponse.php index 348755ff6..68b074a93 100755 --- a/Message/Http/HttpResponse.php +++ b/Message/Http/HttpResponse.php @@ -136,8 +136,6 @@ final class HttpResponse extends ResponseAbstract implements RenderableInterface * * @return string * - * @throws \Exception - * * @since 1.0.0 */ private function getRaw(bool $optimize = false) : string diff --git a/Message/Mail/Email.php b/Message/Mail/Email.php index bb7d2fdad..bb4802090 100755 --- a/Message/Mail/Email.php +++ b/Message/Mail/Email.php @@ -1677,7 +1677,7 @@ class Email implements MessageInterface } if (\preg_match_all("/[{$pattern}]/", $encoded, $matches) !== false) { - return \str_replace(' ', '_', $encoded); + return \strtr($encoded, ' ', '_'); } $matches = []; @@ -1696,7 +1696,7 @@ class Email implements MessageInterface // Replace spaces with _ (more readable than =20) // RFC 2047 section 4.2(2) - return \str_replace(' ', '_', $encoded); + return \strtr($encoded, ' ', '_'); } /** diff --git a/Message/Socket/SocketResponse.php b/Message/Socket/SocketResponse.php index fd969f422..1e6c5561a 100755 --- a/Message/Socket/SocketResponse.php +++ b/Message/Socket/SocketResponse.php @@ -110,8 +110,6 @@ final class SocketResponse extends ResponseAbstract implements RenderableInterfa * * @return string * - * @throws \Exception - * * @since 1.0.0 */ private function getRaw(bool $optimize = false) : string diff --git a/Module/InstallerAbstract.php b/Module/InstallerAbstract.php index f790300b9..316520c04 100755 --- a/Module/InstallerAbstract.php +++ b/Module/InstallerAbstract.php @@ -98,6 +98,8 @@ abstract class InstallerAbstract * * @return void * + * @throws \UnexpectedValueException + * * @since 1.0.0 */ protected static function activate(ApplicationAbstract $app, ModuleInfo $info) : void @@ -109,7 +111,7 @@ abstract class InstallerAbstract $classPath = \substr($path . '/Status', (int) \strlen((string) \realpath(__DIR__ . '/../../'))); /** @var class-string $class */ - $class = \str_replace('/', '\\', $classPath); + $class = \strtr($classPath, '/', '\\'); if (!Autoloader::exists($class)) { throw new \UnexpectedValueException($class); // @codeCoverageIgnore @@ -126,6 +128,8 @@ abstract class InstallerAbstract * * @return void * + * @throws \UnexpectedValueException + * * @since 1.0.0 */ public static function reInit(ModuleInfo $info, ApplicationInfo $appInfo = null) : void @@ -137,7 +141,7 @@ abstract class InstallerAbstract $classPath = \substr($path . '/Status', \strlen((string) \realpath(__DIR__ . '/../../'))); /** @var class-string $class */ - $class = \str_replace('/', '\\', $classPath); + $class = \strtr($classPath, '/', '\\'); if (!Autoloader::exists($class)) { throw new \UnexpectedValueException($class); // @codeCoverageIgnore diff --git a/Module/ModuleInfo.php b/Module/ModuleInfo.php index 145629aa4..3da723c1b 100755 --- a/Module/ModuleInfo.php +++ b/Module/ModuleInfo.php @@ -96,6 +96,8 @@ final class ModuleInfo * * @return void * + * @throws PathException + * * @since 1.0.0 */ public function update() : void @@ -116,6 +118,8 @@ final class ModuleInfo * * @return void * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public function set(string $path, $data, string $delim = '/') : void diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index 5f6508b66..ea9f47862 100755 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -547,6 +547,8 @@ final class ModuleManager * * @return bool * + * @throws InvalidModuleException + * * @since 1.0.0 */ public function uninstall(string $module) : bool @@ -638,7 +640,7 @@ final class ModuleManager return; } - $from = \str_replace('/', '\\', $from); + $from = \strtr($from, '/', '\\'); $class = $from . '\\Admin\\Install\\' . $for; $class::install($this->app, $this->modulePath); @@ -654,8 +656,6 @@ final class ModuleManager * * @return object|\phpOMS\Module\ModuleAbstract * - * @throws \Exception - * * @todo Remove docblock type hint hack "object". * The return type object is only used to stop the annoying warning that a method doesn't exist * if you chain call the methods part of the returned ModuleAbstract implementation. @@ -685,8 +685,6 @@ final class ModuleManager * * @return void * - * @throws \Exception - * * @since 1.0.0 */ private function initModuleController(string $module, string $ctlName = null) : void diff --git a/Module/PackageManager.php b/Module/PackageManager.php index 45c7fa60c..88f3b96bd 100755 --- a/Module/PackageManager.php +++ b/Module/PackageManager.php @@ -148,6 +148,8 @@ final class PackageManager * * @return string Hash value of files * + * @throws \Exception + * * @since 1.0.0 */ private function hashFiles() : string diff --git a/Module/StatusAbstract.php b/Module/StatusAbstract.php index 0797e83d0..f4109077f 100755 --- a/Module/StatusAbstract.php +++ b/Module/StatusAbstract.php @@ -67,8 +67,6 @@ abstract class StatusAbstract * * @return void * - * @throws PermissionException - * * @since 1.0.0 */ public static function activateRoutes(ModuleInfo $info, ApplicationInfo $appInfo = null) : void @@ -84,6 +82,7 @@ abstract class StatusAbstract * * @return void * + * @throws PathException * @throws PermissionException * * @since 1.0.0 @@ -124,8 +123,6 @@ abstract class StatusAbstract * * @return void * - * @throws PermissionException - * * @since 1.0.0 */ public static function activateHooks(ModuleInfo $info, ApplicationInfo $appInfo = null) : void @@ -141,8 +138,6 @@ abstract class StatusAbstract * * @return void * - * @throws PermissionException - * * @since 1.0.0 */ public static function activateRoutesHooks(ModuleInfo $info, ApplicationInfo $appInfo = null, string $type) : void diff --git a/Module/UninstallerAbstract.php b/Module/UninstallerAbstract.php index 233230d05..289c1ff47 100755 --- a/Module/UninstallerAbstract.php +++ b/Module/UninstallerAbstract.php @@ -74,7 +74,7 @@ abstract class UninstallerAbstract $classPath = \substr($path . '/Status', \strlen((string) \realpath(__DIR__ . '/../../'))); /** @var StatusAbstract $class */ - $class = \str_replace('/', '\\', $classPath); + $class = \strtr($classPath, '/', '\\'); $class::deactivate($app, $info); } diff --git a/Stdlib/Base/EnumArray.php b/Stdlib/Base/EnumArray.php index 0f88047ee..bc4fb6d93 100755 --- a/Stdlib/Base/EnumArray.php +++ b/Stdlib/Base/EnumArray.php @@ -85,7 +85,7 @@ abstract class EnumArray * * @return mixed * - * @throws \Exception + * @throws \OutOfBoundsException * * @since 1.0.0 */ diff --git a/Stdlib/Base/Iban.php b/Stdlib/Base/Iban.php index 1498808e5..2754d36ad 100755 --- a/Stdlib/Base/Iban.php +++ b/Stdlib/Base/Iban.php @@ -54,6 +54,8 @@ class Iban implements SerializableInterface * * @return void * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ private function parse(string $iban) : void diff --git a/System/File/Ftp/Directory.php b/System/File/Ftp/Directory.php index 9f89a9c9a..7b2522f93 100755 --- a/System/File/Ftp/Directory.php +++ b/System/File/Ftp/Directory.php @@ -323,6 +323,8 @@ class Directory extends FileAbstract implements DirectoryInterface /** * {@inheritdoc} + * + * @throws PathException */ public static function changed(\FTP\Connection $con, string $path) : \DateTime { @@ -340,6 +342,8 @@ class Directory extends FileAbstract implements DirectoryInterface /** * {@inheritdoc} + * + * @throws PathException */ public static function owner(\FTP\Connection $con, string $path) : string { diff --git a/System/File/Ftp/File.php b/System/File/Ftp/File.php index d0edda8ed..1aab9bcf7 100755 --- a/System/File/Ftp/File.php +++ b/System/File/Ftp/File.php @@ -256,6 +256,8 @@ class File extends FileAbstract implements FileInterface /** * {@inheritdoc} + * + * @throws PathException */ public static function changed(\FTP\Connection $con, string $path) : \DateTime { @@ -285,6 +287,8 @@ class File extends FileAbstract implements FileInterface /** * {@inheritdoc} + * + * @throws PathException */ public static function owner(\FTP\Connection $con, string $path) : string { diff --git a/System/File/Ftp/FtpStorage.php b/System/File/Ftp/FtpStorage.php index b435fe65f..b5bcbee4d 100755 --- a/System/File/Ftp/FtpStorage.php +++ b/System/File/Ftp/FtpStorage.php @@ -63,6 +63,8 @@ class FtpStorage extends StorageAbstract /** * {@inheritdoc} + * + * @throws PathException */ public static function put(string $path, string $content, int $mode = 0) : bool { @@ -75,6 +77,8 @@ class FtpStorage extends StorageAbstract /** * {@inheritdoc} + * + * @throws PathException */ public static function get(string $path) : string { @@ -97,6 +101,8 @@ class FtpStorage extends StorageAbstract /** * {@inheritdoc} + * + * @throws PathException */ public static function list(string $path, string $filter = '*', bool $recursive = false) : array { @@ -109,6 +115,8 @@ class FtpStorage extends StorageAbstract /** * {@inheritdoc} + * + * @throws PathException */ public static function set(string $path, string $content) : bool { @@ -121,6 +129,8 @@ class FtpStorage extends StorageAbstract /** * {@inheritdoc} + * + * @throws PathException */ public static function append(string $path, string $content) : bool { @@ -133,6 +143,8 @@ class FtpStorage extends StorageAbstract /** * {@inheritdoc} + * + * @throws PathException */ public static function prepend(string $path, string $content) : bool { @@ -145,6 +157,8 @@ class FtpStorage extends StorageAbstract /** * {@inheritdoc} + * + * @throws PathException */ public static function extension(string $path) : string { diff --git a/System/File/Local/Directory.php b/System/File/Local/Directory.php index 68ac9d082..63398116a 100755 --- a/System/File/Local/Directory.php +++ b/System/File/Local/Directory.php @@ -102,7 +102,7 @@ final class Directory extends FileAbstract implements DirectoryInterface continue; } - $list[] = \substr(\str_replace('\\', '/', $iterator->getPathname()), \strlen($path) + 1); + $list[] = \substr(\strtr($iterator->getPathname(), '\\', '/'), \strlen($path) + 1); } /** @var string[] $list */ @@ -147,7 +147,7 @@ final class Directory extends FileAbstract implements DirectoryInterface if ((empty($extension) || $item->getExtension() === $extension) && (empty($exclude) || (!(bool) \preg_match('/' . $exclude . '/', $subPath))) ) { - $list[] = \str_replace('\\', '/', $subPath); + $list[] = \strtr($subPath, '\\', '/'); } } @@ -329,7 +329,7 @@ final class Directory extends FileAbstract implements DirectoryInterface */ public static function parent(string $path) : string { - $path = \explode('/', \str_replace('\\', '/', $path)); + $path = \explode('/', \strtr($path, '\\', '/')); \array_pop($path); return \implode('/', $path); @@ -337,6 +337,8 @@ final class Directory extends FileAbstract implements DirectoryInterface /** * {@inheritdoc} + * + * @throws PathException */ public static function owner(string $path) : int { diff --git a/System/File/Local/File.php b/System/File/Local/File.php index cfbf3ab0c..9f86c1bde 100755 --- a/System/File/Local/File.php +++ b/System/File/Local/File.php @@ -107,6 +107,8 @@ final class File extends FileAbstract implements FileInterface * * @return string Content of file * + * @throws PathException + * * @since 1.0.0 */ public static function get(string $path) : string @@ -217,6 +219,8 @@ final class File extends FileAbstract implements FileInterface /** * {@inheritdoc} + * + * @throws PathException */ public static function owner(string $path) : int { diff --git a/System/File/Local/FileAbstract.php b/System/File/Local/FileAbstract.php index 640c2080e..08f0e3f9f 100755 --- a/System/File/Local/FileAbstract.php +++ b/System/File/Local/FileAbstract.php @@ -118,6 +118,8 @@ abstract class FileAbstract implements LocalContainerInterface /** * {@inheritdoc} + * + * @throws PathException */ public static function created(string $path) : \DateTime { @@ -132,6 +134,8 @@ abstract class FileAbstract implements LocalContainerInterface /** * {@inheritdoc} + * + * @throws PathException */ public static function changed(string $path) : \DateTime { diff --git a/System/File/Local/LocalStorage.php b/System/File/Local/LocalStorage.php index c4ef8fc4b..48c5542bf 100755 --- a/System/File/Local/LocalStorage.php +++ b/System/File/Local/LocalStorage.php @@ -39,6 +39,8 @@ class LocalStorage extends StorageAbstract /** * {@inheritdoc} + * + * @throws PathException */ public static function put(string $path, string $content, int $mode = 0) : bool { @@ -51,6 +53,8 @@ class LocalStorage extends StorageAbstract /** * {@inheritdoc} + * + * @throws PathException */ public static function get(string $path) : string { @@ -63,6 +67,8 @@ class LocalStorage extends StorageAbstract /** * {@inheritdoc} + * + * @throws PathException */ public static function list(string $path, string $filter = '*', bool $recursive = false) : array { @@ -85,6 +91,8 @@ class LocalStorage extends StorageAbstract /** * {@inheritdoc} + * + * @throws PathException */ public static function set(string $path, string $content) : bool { @@ -97,6 +105,8 @@ class LocalStorage extends StorageAbstract /** * {@inheritdoc} + * + * @throws PathException */ public static function append(string $path, string $content) : bool { @@ -109,6 +119,8 @@ class LocalStorage extends StorageAbstract /** * {@inheritdoc} + * + * @throws PathException */ public static function prepend(string $path, string $content) : bool { @@ -121,6 +133,8 @@ class LocalStorage extends StorageAbstract /** * {@inheritdoc} + * + * @throws PathException */ public static function extension(string $path) : string { diff --git a/System/SystemUtils.php b/System/SystemUtils.php index d4f25eca5..7378a7246 100755 --- a/System/SystemUtils.php +++ b/System/SystemUtils.php @@ -153,6 +153,12 @@ final class SystemUtils * @param string $executable Path or name of the executable * @param string $cmd Command to execute * @param bool $async Execute async + * + * @return array + * + * @throws \Exception + * + * @since 1.0.0 */ public static function runProc(string $executable, string $cmd, bool $async = false) : array { diff --git a/Uri/HttpUri.php b/Uri/HttpUri.php index 12485b852..0815e0c8b 100755 --- a/Uri/HttpUri.php +++ b/Uri/HttpUri.php @@ -172,6 +172,8 @@ final class HttpUri implements UriInterface /** * {@inheritdoc} + * + * @throws \Exception */ public function set(string $uri) : void { diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index abe59e165..fcf808ead 100755 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -45,6 +45,8 @@ final class ArrayUtils * * @return array * + * @throws \Exception + * * @since 1.0.0 */ public static function unsetArray(string $path, array $data, string $delim = '/') : array @@ -506,6 +508,9 @@ final class ArrayUtils * * @return array * + * @throws InvalidDimensionException + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public static function dot(array $value1, array $value2) : int|float|array diff --git a/Utils/Barcode/BarAbstract.php b/Utils/Barcode/BarAbstract.php index a13c6820b..e828d9cae 100755 --- a/Utils/Barcode/BarAbstract.php +++ b/Utils/Barcode/BarAbstract.php @@ -133,6 +133,8 @@ abstract class BarAbstract extends CodeAbstract * * @return \GdImage * + * @throws \Exception + * * @since 1.0.0 */ protected function createImage(string $codeString) : mixed diff --git a/Utils/Barcode/CodeAbstract.php b/Utils/Barcode/CodeAbstract.php index 9c99e57bb..7a612e264 100755 --- a/Utils/Barcode/CodeAbstract.php +++ b/Utils/Barcode/CodeAbstract.php @@ -124,6 +124,8 @@ abstract class CodeAbstract * * @return void * + * @throws \OutOfBoundsException + * * @since 1.0.0 */ public function setDimension(int $width, int $height) : void @@ -161,6 +163,8 @@ abstract class CodeAbstract * * @return void * + * @throws InvalidEnumValue + * * @since 1.0.0 */ public function setOrientation(int $orientation) : void diff --git a/Utils/Barcode/TwoDAbstract.php b/Utils/Barcode/TwoDAbstract.php index cce612cda..5b369f610 100755 --- a/Utils/Barcode/TwoDAbstract.php +++ b/Utils/Barcode/TwoDAbstract.php @@ -51,6 +51,8 @@ abstract class TwoDAbstract extends CodeAbstract * * @return \GdImage * + * @throws \Exception + * * @since 1.0.0 */ protected function createImage(array $codeArray) : mixed diff --git a/Utils/Compression/LZW.php b/Utils/Compression/LZW.php index 71c67d5cc..6a40a065c 100755 --- a/Utils/Compression/LZW.php +++ b/Utils/Compression/LZW.php @@ -61,6 +61,8 @@ class LZW implements CompressionInterface /** * {@inheritdoc} + * + * @throws \Exception */ public function decompress(string $compressed) : string { diff --git a/Utils/Converter/Currency.php b/Utils/Converter/Currency.php index c275e4e93..23d12b303 100755 --- a/Utils/Converter/Currency.php +++ b/Utils/Converter/Currency.php @@ -70,8 +70,6 @@ final class Currency * * @return float * - * @throws \InvalidArgumentException This exception is thrown if the currency to convert to doesn't exist - * * @since 1.0.0 */ public static function fromEurTo(float $value, string $to) : float @@ -137,8 +135,6 @@ final class Currency * * @return float * - * @throws \InvalidArgumentException This exception is thrown if the currency to convert from doesn't exist - * * @since 1.0.0 */ public static function fromToEur(float $value, string $from) : float @@ -162,8 +158,6 @@ final class Currency * * @return float * - * @throws \InvalidArgumentException This exception is thrown if either the from or to currency doesn't exist - * * @since 1.0.0 */ public static function convertCurrency(float $value, string $from, string $to) : float diff --git a/Utils/Converter/Measurement.php b/Utils/Converter/Measurement.php index 765a55536..ae33a002a 100755 --- a/Utils/Converter/Measurement.php +++ b/Utils/Converter/Measurement.php @@ -43,6 +43,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public static function convertTemperature(float $value, string $from = TemperatureType::FAHRENHEIT, string $to = TemperatureType::CELSIUS) : float @@ -89,6 +91,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ private static function normalizeTemperature(float $value, string $from) : float @@ -133,6 +137,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public static function convertWeight(float $value, string $from = WeightType::GRAM, string $to = WeightType::KILOGRAM) : float @@ -197,6 +203,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ private static function normalizeWeight(float $value, string $from) : float @@ -259,6 +267,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public static function convertLength(float $value, string $from = LengthType::METERS, string $to = LengthType::KILOMETERS) : float @@ -347,6 +357,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ private static function normalizeLength(float $value, string $from) : float @@ -433,6 +445,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public static function convertArea(float $value, string $from = AreaType::SQUARE_METERS, string $to = AreaType::SQUARE_KILOMETERS) : float @@ -494,6 +508,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ private static function normalizeArea(float $value, string $from) : float @@ -553,6 +569,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public static function convertVolume(float $value, string $from = VolumeType::LITER, string $to = VolumeType::LITER) : float @@ -689,6 +707,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ private static function normalizeVolume(float $value, string $from) : float @@ -823,6 +843,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public static function convertSpeed(float $value, string $from = SpeedType::KILOMETERS_PER_HOUR, string $to = SpeedType::KILOMETERS_PER_HOUR) : float @@ -947,6 +969,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ private static function normalizeSpeed(float $value, string $from) : float @@ -1069,6 +1093,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public static function convertTime(float $value, string $from = TimeType::SECONDS, string $to = TimeType::HOURS) : float @@ -1118,6 +1144,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ private static function normalizeTime(float $value, string $from) : float @@ -1165,6 +1193,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public static function convertAngle(float $value, string $from = AngleType::DEGREE, string $to = AngleType::DEGREE) : float @@ -1217,6 +1247,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ private static function normalizeAngle(float $value, string $from) : float @@ -1267,6 +1299,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public static function convertPressure(float $value, string $from = PressureType::PASCALS, string $to = PressureType::BAR) : float @@ -1327,6 +1361,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ private static function normalizePressure(float $value, string $from) : float @@ -1385,6 +1421,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public static function convertEnergy(float $value, string $from = EnergyPowerType::JOULS, string $to = EnergyPowerType::KILOWATT_HOUERS) : float @@ -1432,6 +1470,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ private static function normalizeEnergy(float $value, string $from) : float @@ -1478,6 +1518,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public static function convertFileSize(float $value, string $from = FileSizeType::BYTE, string $to = FileSizeType::MEGABYTE) : float @@ -1530,6 +1572,8 @@ final class Measurement * * @return float * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ private static function normalizeFileSize(float $value, string $from) : float diff --git a/Utils/Converter/Numeric.php b/Utils/Converter/Numeric.php index e4ce51b39..70dc71853 100755 --- a/Utils/Converter/Numeric.php +++ b/Utils/Converter/Numeric.php @@ -55,8 +55,6 @@ final class Numeric * * @return string * - * @throws \Exception This exception is thrown if one of the bases or the number is invalid - * * @since 1.0.0 */ public static function convertBase(string $numberInput, string $fromBaseInput, string $toBaseInput) : string diff --git a/Utils/Encoding/Base64Url.php b/Utils/Encoding/Base64Url.php new file mode 100644 index 000000000..eb13cf429 --- /dev/null +++ b/Utils/Encoding/Base64Url.php @@ -0,0 +1,59 @@ +name)) { $path = $this->getDirectoryPath(); - $path = \str_replace('\\', '/', $path); + $path = \strtr($path, '\\', '/'); $path = \explode('/', $path); $this->name = $path[\count($path) - ($this->bare ? 1 : 2)]; } @@ -633,8 +631,6 @@ class Repository * * @return int * - * @throws \Exception - * * @since 1.0.0 */ public function countFiles() : int @@ -651,8 +647,6 @@ class Repository * * @return int * - * @throws \Exception - * * @since 1.0.0 */ public function getLoc(array $extensions = ['*']) : int diff --git a/Utils/IO/Zip/Gz.php b/Utils/IO/Zip/Gz.php index dc73611ae..24b8cfd95 100755 --- a/Utils/IO/Zip/Gz.php +++ b/Utils/IO/Zip/Gz.php @@ -31,7 +31,7 @@ class Gz implements ArchiveInterface */ public static function pack(string | array $source, string $destination, bool $overwrite = false) : bool { - $destination = \str_replace('\\', '/', $destination); + $destination = \strtr($destination, '\\', '/'); if ($destination === false || \is_array($source) || (!$overwrite && \is_file($destination)) @@ -61,7 +61,7 @@ class Gz implements ArchiveInterface */ public static function unpack(string $source, string $destination) : bool { - $destination = \str_replace('\\', '/', $destination); + $destination = \strtr($destination, '\\', '/'); if (\is_file($destination) || !\is_file($source)) { return false; } diff --git a/Utils/IO/Zip/Tar.php b/Utils/IO/Zip/Tar.php index dfc8d5653..98fefacf5 100755 --- a/Utils/IO/Zip/Tar.php +++ b/Utils/IO/Zip/Tar.php @@ -38,7 +38,7 @@ class Tar implements ArchiveInterface */ public static function pack(string | array $sources, string $destination, bool $overwrite = false) : bool { - $destination = FileUtils::absolute(\str_replace('\\', '/', $destination)); + $destination = FileUtils::absolute(\strtr($destination, '\\', '/')); if ((!$overwrite && \is_file($destination)) || \is_dir($destination) ) { @@ -59,8 +59,8 @@ class Tar implements ArchiveInterface $source = $relative; } - $source = FileUtils::absolute(\str_replace('\\', '/', $source)); - $relative = \str_replace('\\', '/', $relative); + $source = FileUtils::absolute(\strtr($source, '\\', '/')); + $relative = \strtr($relative, '\\', '/'); if (\is_dir($source)) { /** @var string[] $files */ @@ -70,7 +70,7 @@ class Tar implements ArchiveInterface ); foreach ($files as $file) { - $file = \str_replace('\\', '/', $file); + $file = \strtr($file, '\\', '/'); /* Ignore . and .. */ if (($pos = \mb_strrpos($file, '/')) === false @@ -113,7 +113,7 @@ class Tar implements ArchiveInterface } try { - $destination = \str_replace('\\', '/', $destination); + $destination = \strtr($destination, '\\', '/'); $destination = \rtrim($destination, '/'); $tar = new \PharData($source); diff --git a/Utils/IO/Zip/TarGz.php b/Utils/IO/Zip/TarGz.php index d462d9925..27fcf58c5 100755 --- a/Utils/IO/Zip/TarGz.php +++ b/Utils/IO/Zip/TarGz.php @@ -33,7 +33,7 @@ class TarGz implements ArchiveInterface */ public static function pack(string | array $source, string $destination, bool $overwrite = false) : bool { - $destination = \str_replace('\\', '/', $destination); + $destination = \strtr($destination, '\\', '/'); if (!$overwrite && \is_file($destination)) { return false; } @@ -56,7 +56,7 @@ class TarGz implements ArchiveInterface */ public static function unpack(string $source, string $destination) : bool { - $destination = \str_replace('\\', '/', $destination); + $destination = \strtr($destination, '\\', '/'); if (!\is_dir($destination) || !\is_file($source)) { return false; } diff --git a/Utils/IO/Zip/Zip.php b/Utils/IO/Zip/Zip.php index d53a87fc5..1bb1a4132 100755 --- a/Utils/IO/Zip/Zip.php +++ b/Utils/IO/Zip/Zip.php @@ -34,7 +34,7 @@ class Zip implements ArchiveInterface */ public static function pack(string | array $sources, string $destination, bool $overwrite = false) : bool { - $destination = FileUtils::absolute(\str_replace('\\', '/', $destination)); + $destination = FileUtils::absolute(\strtr($destination, '\\', '/')); if ((!$overwrite && \is_file($destination)) || \is_dir($destination) ) { @@ -58,8 +58,8 @@ class Zip implements ArchiveInterface $source = $relative; } - $source = FileUtils::absolute(\str_replace('\\', '/', $source)); - $relative = \str_replace('\\', '/', $relative); + $source = FileUtils::absolute(\strtr($source, '\\', '/')); + $relative = \strtr($relative, '\\', '/'); if (\is_dir($source)) { /** @var string[] $files */ @@ -69,7 +69,7 @@ class Zip implements ArchiveInterface ); foreach ($files as $file) { - $file = \str_replace('\\', '/', $file); + $file = \strtr($file, '\\', '/'); /* Ignore . and .. */ if (($pos = \mb_strrpos($file, '/')) === false @@ -111,7 +111,7 @@ class Zip implements ArchiveInterface Directory::create($destination, recursive: true); } - $destination = \str_replace('\\', '/', $destination); + $destination = \strtr($destination, '\\', '/'); $destination = \rtrim($destination, '/'); try { diff --git a/Utils/ImageUtils.php b/Utils/ImageUtils.php index f94e6c02a..1376f0190 100755 --- a/Utils/ImageUtils.php +++ b/Utils/ImageUtils.php @@ -108,6 +108,9 @@ final class ImageUtils * @param bool $crop Crop image * * @return void + * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public static function resize(string $srcPath, string $dstPath, int $width, int $height, bool $crop = false) : void diff --git a/Utils/Parser/Presentation/PresentationWriter.php b/Utils/Parser/Presentation/PresentationWriter.php index d97158f87..93a48a8fc 100755 --- a/Utils/Parser/Presentation/PresentationWriter.php +++ b/Utils/Parser/Presentation/PresentationWriter.php @@ -44,7 +44,7 @@ class PresentationWriter /** * Presentation object * - * @var Presentation + * @var PhpPresentation * @since 1.0.0 */ protected PhpPresentation $oPhpPresentation; @@ -213,7 +213,6 @@ class PresentationWriter $this->append('
'); $this->append('
'); $this->append('
HashCode
' . $oSlide->getHashCode() . '
'); - $this->append('
Slide Layout
Layout::' . $this->getConstantName('\PhpOffice\PhpPresentation\Slide\Layout', $oSlide->getSlideLayout()) . '
'); $this->append('
Offset X
' . $oSlide->getOffsetX() . '
'); $this->append('
Offset Y
' . $oSlide->getOffsetY() . '
'); diff --git a/Utils/Parser/Spreadsheet/SpreadsheetParser.php b/Utils/Parser/Spreadsheet/SpreadsheetParser.php index a5a8ab057..07847522b 100755 --- a/Utils/Parser/Spreadsheet/SpreadsheetParser.php +++ b/Utils/Parser/Spreadsheet/SpreadsheetParser.php @@ -58,6 +58,8 @@ class SpreadsheetParser $spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE); IOFactory::registerWriter('custom', \phpOMS\Utils\Parser\Spreadsheet\SpreadsheetWriter::class); + + /** @var \phpOMS\Utils\Parser\Spreadsheet\SpreadsheetWriter $writer */ $writer = IOFactory::createWriter($spreadsheet, 'custom'); return $writer->toPdfString(); @@ -65,6 +67,7 @@ class SpreadsheetParser $spreadsheet = IOFactory::load($path); IOFactory::registerWriter('custom', \phpOMS\Utils\Parser\Spreadsheet\SpreadsheetWriter::class); + /** @var \phpOMS\Utils\Parser\Spreadsheet\SpreadsheetWriter $writer */ $writer = IOFactory::createWriter($spreadsheet, 'custom'); return $writer->generateHtmlAll(); diff --git a/Utils/RnG/UUID.php b/Utils/RnG/UUID.php index bafcda305..3dcf94611 100755 --- a/Utils/RnG/UUID.php +++ b/Utils/RnG/UUID.php @@ -30,6 +30,9 @@ final class UUID * @param int<8, max> $length Result length in bytes * * @return string + * + * @throws \InvalidArgumentException + * * @since 1.0.0 */ public static function default(int $length = 16) : string diff --git a/Utils/TaskSchedule/Cron.php b/Utils/TaskSchedule/Cron.php index 0be366c5a..13c2ad9b1 100755 --- a/Utils/TaskSchedule/Cron.php +++ b/Utils/TaskSchedule/Cron.php @@ -29,6 +29,8 @@ class Cron extends SchedulerAbstract { /** * {@inheritdoc} + * + * @throws \Exception */ public function create(TaskAbstract $task) : void { @@ -51,6 +53,8 @@ class Cron extends SchedulerAbstract /** * {@inheritdoc} + * + * @throws \Exception */ public function update(TaskAbstract $task) : void { @@ -94,6 +98,8 @@ class Cron extends SchedulerAbstract /** * {@inheritdoc} + * + * @throws \Exception */ public function deleteByName(string $name) : void { @@ -129,6 +135,8 @@ class Cron extends SchedulerAbstract /** * {@inheritdoc} + * + * @throws \Exception */ public function getAll() : array { @@ -172,6 +180,8 @@ class Cron extends SchedulerAbstract /** * {@inheritdoc} + * + * @throws \Exception */ public function getAllByName(string $name, bool $exact = true) : array { diff --git a/tests/Autoloader.php b/tests/Autoloader.php index e734b0fdc..17681af64 100755 --- a/tests/Autoloader.php +++ b/tests/Autoloader.php @@ -40,7 +40,7 @@ class Autoloader public static function defaultAutoloader(string $class) : void { $class = \ltrim($class, '\\'); - $class = \str_replace(['_', '\\'], '/', $class); + $class = \strtr($class, '_\\', '//'); if (!\is_file($path = __DIR__ . '/../../' . $class . '.php')) { return; @@ -64,7 +64,7 @@ class Autoloader public static function exists(string $class) : bool { $class = \ltrim($class, '\\'); - $class = \str_replace(['_', '\\'], '/', $class); + $class = \strtr($class, '_\\', '//'); return \is_file(__DIR__ . '/../../' . $class . '.php'); } diff --git a/tests/DataStorage/Database/Query/BuilderTest.php b/tests/DataStorage/Database/Query/BuilderTest.php index 1a8598951..46e3aa6aa 100755 --- a/tests/DataStorage/Database/Query/BuilderTest.php +++ b/tests/DataStorage/Database/Query/BuilderTest.php @@ -63,34 +63,34 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] as t FROM [a] as b WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->selectAs('a.test', 't')->fromAs('a', 'b')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'SELECT DISTINCT [a].[test] FROM [a] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->distinct()->from('a')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test], [b].[test] FROM [a], [b] WHERE [a].[test] = \'abc\';'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test', 'b.test')->from('a', 'b')->where('a.test', '=', 'abc')->toSql()); $query = new Builder($con); $datetime = new \DateTime('now'); $sql = 'SELECT [a].[test], [b].[test] FROM [a], [b] WHERE [a].[test] = \'' . $datetime->format('Y-m-d H:i:s') . '\';'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test', 'b.test')->from('a', 'b')->where('a.test', '=', $datetime)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test], [b].[test] FROM [a], [b] WHERE [a].[test] = \'abc\' ORDER BY [a].[test] ASC, [b].[test] DESC;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test', 'b.test') ->from('a', 'b') @@ -101,7 +101,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'SELECT [a].[test], [b].[test] FROM [a], [b] WHERE [a].[test] = :abcValue ORDER BY [a].[test] ASC, [b].[test] DESC;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test', 'b.test') ->from('a', 'b') @@ -122,7 +122,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] as b WHERE [a].[test] = 1 ORDER BY \rand() LIMIT 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->random('a.test')->fromAs('a', 'b')->where('a.test', '=', 1)->toSql()); } @@ -135,7 +135,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] as b ORDER BY RANDOM() LIMIT 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->random('a.test')->fromAs('a', 'b')->where('a.test', '=', 1)->toSql()); } @@ -148,7 +148,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] as b ORDER BY RANDOM() LIMIT 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->random('a.test')->fromAs('a', 'b')->where('a.test', '=', 1)->toSql()); } @@ -161,7 +161,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'SELECT TOP 1 [a].[test] FROM [a] as b ORDER BY IDX FETCH FIRST 1 ROWS ONLY;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->random('a.test')->fromAs('a', 'b')->where('a.test', '=', 1)->toSql()); } @@ -183,32 +183,32 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 ORDER BY [a].[test] DESC;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->newest('a.test')->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 ORDER BY [a].[test] ASC;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->oldest('a.test')->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 ORDER BY [a].[test] DESC;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->orderBy('a.test', 'DESC')->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 ORDER BY [a].[test] ASC;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->orderBy('a.test', 'ASC')->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 ORDER BY [a].[test] DESC, [a].[test2] DESC;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->orderBy(['a.test', 'a.test2'], ['DESC', 'DESC'])->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 ORDER BY [a].[test] ASC, [a].[test2] ASC;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->orderBy(['a.test', 'a.test2'], 'ASC')->toSql()); } @@ -230,12 +230,12 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 LIMIT 3;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->limit(3)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 OFFSET 3;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->offset(3)->toSql()); } @@ -257,12 +257,12 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 GROUP BY [a];'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->groupBy('a')->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 GROUP BY [a], [b];'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->groupBy('a')->groupBy('b')->toSql()); $query = new Builder($con); @@ -270,7 +270,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = :test GROUP BY [a], [b];'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', new Parameter('test'))->groupBy('a', 'b')->toSql()); } @@ -292,72 +292,72 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 0;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', false)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', true)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = \'string\';'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 'string')->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1.23;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1.23)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 AND [a].[test2] = 2;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->where('a.test2', '=', 2, 'and')->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 AND [a].[test2] = 2;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->andWhere('a.test2', '=', 2)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 OR [a].[test2] = 2;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->where('a.test2', '=', 2, 'or')->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 OR [a].[test2] = 2;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->orWhere('a.test2', '=', 2)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 OR [a].[test2] IS NULL;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->whereNull('a.test2', 'or')->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 OR [a].[test2] IS NOT NULL;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->whereNotNull('a.test2', 'or')->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 OR [a].[test2] IN (1, 2, 3);'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->whereIn('a.test2', [1, 2, 3], 'or')->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = 1 OR [a].[test2] IN (\'a\', \'b\', \'c\');'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->whereIn('a.test2', ['a', 'b', 'c'], 'or')->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] WHERE [a].[test] = :testWhere OR [a].[test2] IN (\'a\', :bValue, \'c\');'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', new Parameter('testWhere'))->whereIn('a.test2', ['a', new Parameter('bValue'), 'c'], 'or')->toSql()); } @@ -379,72 +379,72 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] JOIN [b] ON [a].[id] = [b].[id] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->join('b')->on('a.id', '=', 'b.id')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] JOIN [b] ON [a].[id] = [b].[id] OR [a].[id2] = [b].[id2] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->join('b')->on('a.id', '=', 'b.id')->orOn('a.id2', '=', 'b.id2')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] JOIN [b] ON [a].[id] = [b].[id] AND [a].[id2] = [b].[id2] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->join('b')->on('a.id', '=', 'b.id')->andOn('a.id2', '=', 'b.id2')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] LEFT JOIN [b] ON [a].[id] = [b].[id] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->leftJoin('b')->on('a.id', '=', 'b.id')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] LEFT OUTER JOIN [b] ON [a].[id] = [b].[id] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->leftOuterJoin('b')->on('a.id', '=', 'b.id')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] LEFT INNER JOIN [b] ON [a].[id] = [b].[id] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->leftInnerJoin('b')->on('a.id', '=', 'b.id')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] RIGHT JOIN [b] ON [a].[id] = [b].[id] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->rightJoin('b')->on('a.id', '=', 'b.id')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] RIGHT OUTER JOIN [b] ON [a].[id] = [b].[id] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->rightOuterJoin('b')->on('a.id', '=', 'b.id')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] RIGHT INNER JOIN [b] ON [a].[id] = [b].[id] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->rightInnerJoin('b')->on('a.id', '=', 'b.id')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] OUTER JOIN [b] ON [a].[id] = [b].[id] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->outerJoin('b')->on('a.id', '=', 'b.id')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] INNER JOIN [b] ON [a].[id] = [b].[id] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->innerJoin('b')->on('a.id', '=', 'b.id')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] CROSS JOIN [b] ON [a].[id] = [b].[id] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->crossJoin('b')->on('a.id', '=', 'b.id')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] FULL JOIN [b] ON [a].[id] = [b].[id] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->fullJoin('b')->on('a.id', '=', 'b.id')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'SELECT [a].[test] FROM [a] FULL OUTER JOIN [b] ON [a].[id] = [b].[id] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->select('a.test')->from('a')->fullOuterJoin('b')->on('a.id', '=', 'b.id')->where('a.test', '=', 1)->toSql()); } @@ -466,28 +466,28 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'INSERT INTO [a] VALUES (1, \'test\');'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->insert()->into('a')->values(1, 'test')->toSql()); $query = new Builder($con); $sql = 'INSERT INTO [a] VALUES (1, \'test\');'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->insert()->into('a')->value([1, 'test'])->toSql()); $query = new Builder($con); $sql = 'INSERT INTO [a] ([test], [test2]) VALUES (1, \'test\');'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->insert('test', 'test2')->into('a')->values(1, 'test')->toSql()); self::assertEquals([[1, 'test']], $query->getValues()); $query = new Builder($con); $sql = 'INSERT INTO [a] ([test], [test2]) VALUES (1, \'test\'), (2, \'test2\');'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->insert('test', 'test2')->into('a')->values(1, 'test')->values(2, 'test2')->toSql()); $query = new Builder($con); $sql = 'INSERT INTO [a] ([test], [test2]) VALUES (:test, :test2);'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->insert('test', 'test2')->into('a')->values(new Parameter('test'), new Parameter('test2'))->toSql()); } @@ -509,12 +509,12 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'DELETE FROM [a] WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->delete()->from('a')->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'DELETE FROM [a] WHERE [a].[test] = :testVal;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->delete()->from('a')->where('a.test', '=', new Parameter('testVal'))->toSql()); } @@ -536,17 +536,17 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'UPDATE [a] SET [a].[test] = 1, [a].[test2] = 2 WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->update('a')->set(['a.test' => 1])->set(['a.test2' => 2])->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'UPDATE [a] SET [a].[test] = 1, [a].[test2] = 2 WHERE [a].[test] = 1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->update('a')->sets('a.test', 1)->sets('a.test2', 2)->where('a.test', '=', 1)->toSql()); $query = new Builder($con); $sql = 'UPDATE [a] SET [a].[test] = 1, [a].[test2] = :test2 WHERE [a].[test] = :test3;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->update('a')->set(['a.test' => 1])->set(['a.test2' => new Parameter('test2')])->where('a.test', '=', new Parameter('test3'))->toSql()); } diff --git a/tests/DataStorage/Database/Schema/BuilderTest.php b/tests/DataStorage/Database/Schema/BuilderTest.php index 7f0545198..0e08841a1 100755 --- a/tests/DataStorage/Database/Schema/BuilderTest.php +++ b/tests/DataStorage/Database/Schema/BuilderTest.php @@ -62,7 +62,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'DROP DATABASE [test];'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->dropDatabase('test')->toSql()); } @@ -84,7 +84,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'DROP TABLE [test];'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->dropTable('test')->toSql()); } @@ -106,7 +106,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'SELECT [table_name] FROM [information_schema].[tables] WHERE [table_schema] = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\';'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->selectTables()->toSql()); } @@ -128,7 +128,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'SELECT * FROM [information_schema].[columns] WHERE [table_schema] = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\' AND table_name = \'test\';'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals($sql, $query->selectFields('test')->toSql()); } @@ -150,7 +150,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'CREATE TABLE IF NOT EXISTS [user_roles] (user_id INT AUTO_INCREMENT, role_id VARCHAR(10) DEFAULT \'1\' NULL, PRIMARY KEY (user_id), FOREIGN KEY (user_id) REFERENCES users (ext1_id), FOREIGN KEY (role_id) REFERENCES roles (ext2_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals( $sql, $query->createTable('user_roles') @@ -174,7 +174,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'CREATE TABLE IF NOT EXISTS user_roles (user_id INT NOT NULL AUTO_INCREMENT, role_id VARCHAR(10) DEFAULT \'1\' NULL, PRIMARY KEY (user_id), FOREIGN KEY (user_id) REFERENCES users (ext1_id), FOREIGN KEY (role_id) REFERENCES roles (ext2_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals( $sql, $query->createTable('user_roles') @@ -204,7 +204,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase $query = new Builder($con); $sql = 'DROP TABLE [test], [test_foreign];'; - $sql = \str_replace(['[', ']'], [$iS, $iE], $sql); + $sql = \strtr($sql, '[]', $iS . $iE); self::assertEquals( $sql, diff --git a/tests/System/File/Ftp/DirectoryTest.php b/tests/System/File/Ftp/DirectoryTest.php index 2f91bc100..1c83e6106 100755 --- a/tests/System/File/Ftp/DirectoryTest.php +++ b/tests/System/File/Ftp/DirectoryTest.php @@ -199,7 +199,7 @@ final class DirectoryTest extends \PHPUnit\Framework\TestCase { $dirPath = __DIR__ . '/test'; - self::assertEquals(\str_replace('\\', '/', \realpath(__DIR__)), Directory::parent($dirPath)); + self::assertEquals(\strtr(\realpath(__DIR__), '\\', '/'), Directory::parent($dirPath)); } /** diff --git a/tests/System/File/Ftp/FileTest.php b/tests/System/File/Ftp/FileTest.php index 4b519a856..99be3d833 100755 --- a/tests/System/File/Ftp/FileTest.php +++ b/tests/System/File/Ftp/FileTest.php @@ -302,7 +302,7 @@ final class FileTest extends \PHPUnit\Framework\TestCase { $testFile = __DIR__ . '/test.txt'; - self::assertEquals(\str_replace('\\', '/', \realpath(__DIR__ . '/../')), File::parent($testFile)); + self::assertEquals(\strtr(\realpath(__DIR__ . '/../'), '\\', '/'), File::parent($testFile)); } /** diff --git a/tests/System/File/Ftp/FtpStorageTest.php b/tests/System/File/Ftp/FtpStorageTest.php index 6a42e358e..57ea442f0 100755 --- a/tests/System/File/Ftp/FtpStorageTest.php +++ b/tests/System/File/Ftp/FtpStorageTest.php @@ -180,7 +180,7 @@ final class FtpStorageTest extends \PHPUnit\Framework\TestCase { $dirPath = __DIR__ . '/test'; - self::assertEquals(\str_replace('\\', '/', \realpath(__DIR__)), FtpStorage::parent($dirPath)); + self::assertEquals(\strtr(\realpath(__DIR__), '\\', '/'), FtpStorage::parent($dirPath)); } /** @@ -664,7 +664,7 @@ final class FtpStorageTest extends \PHPUnit\Framework\TestCase { $testFile = __DIR__ . '/test.txt'; - self::assertEquals(\str_replace('\\', '/', \realpath(__DIR__ . '/../')), FtpStorage::parent($testFile)); + self::assertEquals(\strtr(\realpath(__DIR__ . '/../'), '\\', '/'), FtpStorage::parent($testFile)); } /** diff --git a/tests/System/File/Local/DirectoryTest.php b/tests/System/File/Local/DirectoryTest.php index 44f3261ab..10dfe8cf6 100755 --- a/tests/System/File/Local/DirectoryTest.php +++ b/tests/System/File/Local/DirectoryTest.php @@ -133,7 +133,7 @@ final class DirectoryTest extends \PHPUnit\Framework\TestCase { $dirPath = __DIR__ . '/test'; - self::assertEquals(\str_replace('\\', '/', \realpath(__DIR__)), Directory::parent($dirPath)); + self::assertEquals(\strtr(\realpath(__DIR__), '\\', '/'), Directory::parent($dirPath)); } /** diff --git a/tests/System/File/Local/FileTest.php b/tests/System/File/Local/FileTest.php index a35ebbed7..b7b2fd361 100755 --- a/tests/System/File/Local/FileTest.php +++ b/tests/System/File/Local/FileTest.php @@ -297,7 +297,7 @@ final class FileTest extends \PHPUnit\Framework\TestCase { $testFile = __DIR__ . '/test.txt'; - self::assertEquals(\str_replace('\\', '/', \realpath(__DIR__ . '/../')), File::parent($testFile)); + self::assertEquals(\strtr(\realpath(__DIR__ . '/../'), '\\', '/'), File::parent($testFile)); } /** diff --git a/tests/System/File/Local/LocalStorageTest.php b/tests/System/File/Local/LocalStorageTest.php index 05470ab05..eddd691a3 100755 --- a/tests/System/File/Local/LocalStorageTest.php +++ b/tests/System/File/Local/LocalStorageTest.php @@ -124,7 +124,7 @@ final class LocalStorageTest extends \PHPUnit\Framework\TestCase { $dirPath = __DIR__ . '/test'; - self::assertEquals(\str_replace('\\', '/', \realpath(__DIR__)), LocalStorage::parent($dirPath)); + self::assertEquals(\strtr(\realpath(__DIR__), '\\', '/'), LocalStorage::parent($dirPath)); } /** @@ -604,7 +604,7 @@ final class LocalStorageTest extends \PHPUnit\Framework\TestCase { $testFile = __DIR__ . '/test.txt'; - self::assertEquals(\str_replace('\\', '/', \realpath(__DIR__ . '/../')), LocalStorage::parent($testFile)); + self::assertEquals(\strtr(\realpath(__DIR__ . '/../'), '\\', '/'), LocalStorage::parent($testFile)); } /** diff --git a/tests/Utils/Git/RepositoryTest.php b/tests/Utils/Git/RepositoryTest.php index cb3956db9..ea4f1963b 100755 --- a/tests/Utils/Git/RepositoryTest.php +++ b/tests/Utils/Git/RepositoryTest.php @@ -32,7 +32,7 @@ final class RepositoryTest extends \PHPUnit\Framework\TestCase { $repo = new Repository(\realpath(__DIR__ . '/../../../')); self::assertTrue($repo->getName() === 'phpOMS' || $repo->getName() === 'build'); - self::assertEquals(\str_replace('\\', '/', \realpath(__DIR__ . '/../../../.git')), \str_replace('\\', '/', $repo->getDirectoryPath())); + self::assertEquals(\strtr(\realpath(__DIR__ . '/../../../.git'), '\\', '/'), \strtr($repo->getDirectoryPath(), '\\', '/')); self::assertEquals(\realpath(__DIR__ . '/../../../'), $repo->getPath()); } }