From f656b3a8bc44c373c0a81e9e87e891aa916521df Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 24 Aug 2026 11:04:43 +0100 Subject: [PATCH] Resolve the remaining static analysis baseline entries --- phpstan-baseline.neon | 24 ------------------ src/Parser/Lexer.php | 2 +- src/Repository/Adapter/EnvConstAdapter.php | 25 ++++++++++--------- src/Repository/Adapter/ServerConstAdapter.php | 25 ++++++++++--------- src/Util/Str.php | 2 +- 5 files changed, 28 insertions(+), 50 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 69f549bb..827cbcdc 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,31 +1,7 @@ parameters: ignoreErrors: - - - message: '#^Only booleans are allowed in a negated boolean, int\|false given\.$#' - identifier: booleanNot.exprNotBoolean - count: 1 - path: src/Parser/Lexer.php - - message: '#^Parameter \#1 \$pattern of function preg_match expects string, mixed given\.$#' identifier: argument.type count: 1 path: src/Parser/Lexer.php - - - - message: '#^Cannot cast mixed to string\.$#' - identifier: cast.string - count: 1 - path: src/Repository/Adapter/EnvConstAdapter.php - - - - message: '#^Cannot cast mixed to string\.$#' - identifier: cast.string - count: 1 - path: src/Repository/Adapter/ServerConstAdapter.php - - - - message: '#^Loose comparison via "\=\=" is not allowed\.$#' - identifier: equal.notAllowed - count: 1 - path: src/Util/Str.php diff --git a/src/Parser/Lexer.php b/src/Parser/Lexer.php index 981af24f..dc060e8c 100644 --- a/src/Parser/Lexer.php +++ b/src/Parser/Lexer.php @@ -46,7 +46,7 @@ public static function lex(string $content) $offset = 0; while (isset($content[$offset])) { - if (!\preg_match($regex, $content, $matches, 0, $offset)) { + if (\preg_match($regex, $content, $matches, 0, $offset) !== 1) { throw new \Error(\sprintf('Lexer encountered unexpected character [%s].', $content[$offset])); } diff --git a/src/Repository/Adapter/EnvConstAdapter.php b/src/Repository/Adapter/EnvConstAdapter.php index f8d18550..0fe62c34 100644 --- a/src/Repository/Adapter/EnvConstAdapter.php +++ b/src/Repository/Adapter/EnvConstAdapter.php @@ -38,22 +38,23 @@ public static function create() */ public function read(string $name) { - /** @var \PhpOption\Option */ - return Option::fromArraysValue($_ENV, $name) + /** @var \PhpOption\Option */ + $value = Option::fromArraysValue($_ENV, $name) ->filter(static function ($value) { return \is_scalar($value); - }) - ->map(static function ($value) { - if ($value === false) { - return 'false'; - } + }); - if ($value === true) { - return 'true'; - } + return $value->map(static function ($value) { + if ($value === false) { + return 'false'; + } - return (string) $value; - }); + if ($value === true) { + return 'true'; + } + + return (string) $value; + }); } /** diff --git a/src/Repository/Adapter/ServerConstAdapter.php b/src/Repository/Adapter/ServerConstAdapter.php index 07016953..41f2799c 100644 --- a/src/Repository/Adapter/ServerConstAdapter.php +++ b/src/Repository/Adapter/ServerConstAdapter.php @@ -38,22 +38,23 @@ public static function create() */ public function read(string $name) { - /** @var \PhpOption\Option */ - return Option::fromArraysValue($_SERVER, $name) + /** @var \PhpOption\Option */ + $value = Option::fromArraysValue($_SERVER, $name) ->filter(static function ($value) { return \is_scalar($value); - }) - ->map(static function ($value) { - if ($value === false) { - return 'false'; - } + }); - if ($value === true) { - return 'true'; - } + return $value->map(static function ($value) { + if ($value === false) { + return 'false'; + } - return (string) $value; - }); + if ($value === true) { + return 'true'; + } + + return (string) $value; + }); } /** diff --git a/src/Util/Str.php b/src/Util/Str.php index 3877d315..f408f633 100644 --- a/src/Util/Str.php +++ b/src/Util/Str.php @@ -56,7 +56,7 @@ public static function utf8(string $input, ?string $encoding = null) * @see https://en.wikipedia.org/wiki/Byte_order_mark * @see https://github.com/vlucas/phpdotenv/issues/500 */ - if (\substr($converted, 0, 3) == "\xEF\xBB\xBF") { + if (\substr($converted, 0, 3) === "\xEF\xBB\xBF") { $converted = \substr($converted, 3); }