diff --git a/rector.php b/rector.php index 73ca57400..9a9ffea44 100644 --- a/rector.php +++ b/rector.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector; use Rector\TypeDeclaration\Rector\ClassMethod\StrictStringParamConcatRector; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; @@ -15,6 +16,9 @@ LevelSetList::UP_TO_PHP_80, SetList::TYPE_DECLARATION, ]) + ->withRules([ + DeclareStrictTypesRector::class, + ]) ->withSkip([ StrictStringParamConcatRector::class => [ __DIR__ . '/src/Database/Adapters/Idiorm/Statements/Criteria.php', diff --git a/src/App/Adapters/AppAdapter.php b/src/App/Adapters/AppAdapter.php index ebf5a41de..db9cd43fa 100644 --- a/src/App/Adapters/AppAdapter.php +++ b/src/App/Adapters/AppAdapter.php @@ -1,5 +1,7 @@ get('cors') as $key => $value) { - $response->setHeader($key, $value); + $response->setHeader($key, (string) $value); } } } diff --git a/src/Archive/Adapters/PharAdapter.php b/src/Archive/Adapters/PharAdapter.php index 81bf5a722..163c7e3e1 100644 --- a/src/Archive/Adapters/PharAdapter.php +++ b/src/Archive/Adapters/PharAdapter.php @@ -1,5 +1,7 @@ get($envFilePath); $envFileContent = preg_replace('/^' . preg_quote($row, '/') . '/m', $key . '=' . $value, $envFileContent); - fs()->put($envFilePath, $envFileContent); + fs()->put($envFilePath, (string) $envFileContent); } else { fs()->append($envFilePath, PHP_EOL . $key . '=' . $value . PHP_EOL); } diff --git a/src/Environment/Server.php b/src/Environment/Server.php index 7f183cc1d..9dd0c6c7b 100644 --- a/src/Environment/Server.php +++ b/src/Environment/Server.php @@ -1,5 +1,7 @@ get('SERVER_PORT'); + $port = $this->get('SERVER_PORT'); + + if ($port === null) { + return null; + } + + return (string) $port; } public function contentType(bool $exact = false): ?string diff --git a/src/Hasher/Enums/ExceptionMessages.php b/src/Hasher/Enums/ExceptionMessages.php index 2d08717df..4721d90a6 100644 --- a/src/Hasher/Enums/ExceptionMessages.php +++ b/src/Hasher/Enums/ExceptionMessages.php @@ -1,5 +1,7 @@ addChild($tag, htmlspecialchars($value)); + $child = $simpleXML->addChild($tag, htmlspecialchars((string) $value)); if ($attributes) { foreach ($attributes as $attrKey => $attrVal) { diff --git a/src/Http/Traits/Response/Header.php b/src/Http/Traits/Response/Header.php index 05f425453..ea5f74e03 100644 --- a/src/Http/Traits/Response/Header.php +++ b/src/Http/Traits/Response/Header.php @@ -1,5 +1,7 @@ = 80000 ? false : 0); if ($params !== []) { extract($params); diff --git a/src/Renderer/Adapters/TwigAdapter.php b/src/Renderer/Adapters/TwigAdapter.php index 3f273a4ce..305641ace 100644 --- a/src/Renderer/Adapters/TwigAdapter.php +++ b/src/Renderer/Adapters/TwigAdapter.php @@ -1,5 +1,7 @@ $serviceClass + * @return T * @throws BaseException * @throws DiException * @throws ReflectionException @@ -47,6 +50,9 @@ public static function get(string $serviceClass, array $args = []): QtService /** * Creates new service instance + * @template T of QtService + * @param class-string $serviceClass + * @return T * @throws BaseException * @throws DiException * @throws ReflectionException diff --git a/src/Service/QtService.php b/src/Service/QtService.php index 62351cf2f..f588a25b9 100644 --- a/src/Service/QtService.php +++ b/src/Service/QtService.php @@ -1,5 +1,7 @@ dropboxApp->contentRequest( @@ -90,7 +92,7 @@ public function put(string $filename, string $content, ?string $parentId = null) /** * @inheritDoc */ - public function append(string $filename, string $content) + public function append(string $filename, $content) { $fileContent = $this->get($filename); diff --git a/src/Storage/Adapters/GoogleDrive/GoogleDriveApp.php b/src/Storage/Adapters/GoogleDrive/GoogleDriveApp.php index 3fdf54a63..e91de5b8a 100644 --- a/src/Storage/Adapters/GoogleDrive/GoogleDriveApp.php +++ b/src/Storage/Adapters/GoogleDrive/GoogleDriveApp.php @@ -1,5 +1,7 @@ isFile($filename)) { @@ -110,7 +112,7 @@ public function put(string $filename, string $content, ?string $parentId = null) /** * @inheritDoc */ - public function append(string $filename, string $content) + public function append(string $filename, $content) { $fileContent = $this->get($filename); diff --git a/src/Storage/Adapters/Local/LocalFileSystemAdapter.php b/src/Storage/Adapters/Local/LocalFileSystemAdapter.php index 4c0c0b207..7d36837e4 100644 --- a/src/Storage/Adapters/Local/LocalFileSystemAdapter.php +++ b/src/Storage/Adapters/Local/LocalFileSystemAdapter.php @@ -1,5 +1,7 @@ 10, 'C' => 12, 'D' => 13, 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, 'L' => 21, 'M' => 22, @@ -105,16 +109,17 @@ protected function iban(string $value): bool /** * Checks for a valid format human name */ - protected function name(string $value): bool + protected function name($value): bool { - return preg_match("/^([a-z \p{L} '-])+$/i", $value) === 1; + return preg_match("/^([a-z \p{L} '-])+$/i", (string) $value) === 1; } /** * Checks that the provided string is a likely street address. */ - protected function streetAddress(string $value): bool + protected function streetAddress($value): bool { + $value = (string) $value; $hasLetter = preg_match('/[a-zA-Z]/', $value); $hasDigit = preg_match('/\d/', $value); $hasSpace = preg_match('/\s/', $value); @@ -125,8 +130,9 @@ protected function streetAddress(string $value): bool /** * Validates the phone number // 555-555-5555 , 5555425555, 555 555 5555, 1(519) 555-4444, 1 (519) 555-4422, +1-555-555-5555 */ - protected function phoneNumber(string $value): bool + protected function phoneNumber($value): bool { + $value = (string) $value; $regex = '/^(\+*\d[\s-]?)?[\(\[\s-]{0,2}?\d{3}[\)\]\s-]{0,2}?\d{3}[\s-]?\d{4}$/i'; return preg_match($regex, $value) === 1; @@ -135,8 +141,9 @@ protected function phoneNumber(string $value): bool /** * Determines if the provided input is a valid date */ - protected function date(string $value, ?string $format = null): bool + protected function date($value, ?string $format = null): bool { + $value = (string) $value; if (!$format) { $cdate1 = date('Y-m-d', strtotime($value)); $cdate2 = date('Y-m-d H:i:s', strtotime($value)); @@ -152,25 +159,25 @@ protected function date(string $value, ?string $format = null): bool /** * Ensures the value starts with a certain character / set of character */ - protected function starts(string $value, ?string $text = null): bool + protected function starts($value, ?string $text = null): bool { - return strpos($value, (string) $text) === 0; + return strpos((string) $value, (string) $text) === 0; } /** * Custom regex validator */ - protected function regex(string $value, string $pattern): bool + protected function regex($value, string $pattern): bool { - return preg_match($pattern, $value) === 1; + return preg_match($pattern, (string) $value) === 1; } /** * Validates JSON string */ - protected function jsonString(string $value): bool + protected function jsonString($value): bool { - $value = htmlspecialchars_decode($value, ENT_QUOTES); + $value = htmlspecialchars_decode((string) $value, ENT_QUOTES); return is_object(json_decode($value)); } @@ -178,7 +185,7 @@ protected function jsonString(string $value): bool /** * Validates same value for both fields */ - protected function same(string $value, string $otherField): bool + protected function same($value, string $otherField): bool { return $value == $this->data[$otherField]; } @@ -222,10 +229,10 @@ protected function exists($value, string $className, string $columnName): bool * @throws DiException * @throws ReflectionException */ - protected function captcha(string $value): bool + protected function captcha($value): bool { $captcha = CaptchaFactory::get(); - return $captcha->verify($value); + return $captcha->verify((string) $value); } } diff --git a/src/Validation/Traits/Length.php b/src/Validation/Traits/Length.php index b473110e8..720446986 100644 --- a/src/Validation/Traits/Length.php +++ b/src/Validation/Traits/Length.php @@ -1,5 +1,7 @@ = $minValue); } @@ -100,7 +102,7 @@ protected function minNumeric(string $value, $minValue): bool * Determines if the provided numeric value is higher to a specific value * @param $maxValue */ - protected function maxNumeric(string $value, $maxValue): bool + protected function maxNumeric($value, $maxValue): bool { return is_numeric($value) && is_numeric($maxValue) && ($value <= $maxValue); } diff --git a/src/Validation/Validator.php b/src/Validation/Validator.php index c51e63acb..cea8642fc 100644 --- a/src/Validation/Validator.php +++ b/src/Validation/Validator.php @@ -1,5 +1,7 @@ convertToHtml($content); + $html = (string) $converter->convertToHtml($content); if ($purifier instanceof HTMLPurifier) { return $purifier->purify($html); diff --git a/src/View/QtView.php b/src/View/QtView.php index 77cb42934..9fb08f3bc 100644 --- a/src/View/QtView.php +++ b/src/View/QtView.php @@ -1,5 +1,7 @@ setQueryParam('name', 'John'); - $request->setQueryParam('age', 36); + $request->setQueryParam('age', '36'); $this->assertEquals('John', $request->getQueryParam('name'));