From ce9b3758b8de79f1dd66de1037faa421ab0dc770 Mon Sep 17 00:00:00 2001 From: Sjors Ottjes Date: Sat, 15 Aug 2026 10:47:31 +0200 Subject: [PATCH 1/5] update quickdump.php --- Build/phpstan/phpstan-baseline.neon | 6 ++++++ bin/quickdump.php | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon index 4c021e00c..b7e7c0e34 100644 --- a/Build/phpstan/phpstan-baseline.neon +++ b/Build/phpstan/phpstan-baseline.neon @@ -1,5 +1,11 @@ parameters: ignoreErrors: + - + message: '#^Function file_get_contents is unsafe to use\. It can return FALSE instead of throwing an exception\. Please add ''use function Safe\\file_get_contents;'' at the beginning of the file to use the variant provided by the ''thecodingmachine/safe'' library\.$#' + identifier: theCodingMachineSafe.function + count: 1 + path: ../../bin/quickdump.php + - message: '#^Function preg_match is unsafe to use\. It can return FALSE instead of throwing an exception\. Please add ''use function Safe\\preg_match;'' at the beginning of the file to use the variant provided by the ''thecodingmachine/safe'' library\.$#' identifier: theCodingMachineSafe.function diff --git a/bin/quickdump.php b/bin/quickdump.php index dc0fe8697..cc47a817d 100755 --- a/bin/quickdump.php +++ b/bin/quickdump.php @@ -5,15 +5,16 @@ use Sabberworm\CSS\Parser; -use function Safe\file_get_contents; - /** * This script is used for generating the examples in the README. */ require_once(__DIR__ . '/../vendor/autoload.php'); -$source = file_get_contents('php://stdin'); +$source = \file_get_contents('php://stdin'); +if ($source === false) { + throw new \RuntimeException('Failed to read from stdin.'); +} $parser = new Parser($source); $document = $parser->parse(); From 0870e432138547a7f9eb454f82b974c344bd8dfd Mon Sep 17 00:00:00 2001 From: Sjors Ottjes Date: Sat, 15 Aug 2026 10:55:26 +0200 Subject: [PATCH 2/5] update ParserTest --- Build/phpstan/phpstan-baseline.neon | 12 ++++++++++++ tests/ParserTest.php | 9 +++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon index b7e7c0e34..360ef6b64 100644 --- a/Build/phpstan/phpstan-baseline.neon +++ b/Build/phpstan/phpstan-baseline.neon @@ -60,6 +60,18 @@ parameters: count: 1 path: ../../src/Value/Value.php + - + message: '#^Function file_get_contents is unsafe to use\. It can return FALSE instead of throwing an exception\. Please add ''use function Safe\\file_get_contents;'' at the beginning of the file to use the variant provided by the ''thecodingmachine/safe'' library\.$#' + identifier: theCodingMachineSafe.function + count: 2 + path: ../../tests/ParserTest.php + + - + message: '#^Function opendir is unsafe to use\. It can return FALSE instead of throwing an exception\. Please add ''use function Safe\\opendir;'' at the beginning of the file to use the variant provided by the ''thecodingmachine/safe'' library\.$#' + identifier: theCodingMachineSafe.function + count: 1 + path: ../../tests/ParserTest.php + - message: '#^Parameter \#1 \$value of method Sabberworm\\CSS\\Property\\Declaration\:\:setValue\(\) expects Sabberworm\\CSS\\Value\\RuleValueList\|string\|null, Sabberworm\\CSS\\Value\\Size given\.$#' identifier: argument.type diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 6680bc0f0..1e4c357cf 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -30,9 +30,6 @@ use Sabberworm\CSS\Value\URL; use Sabberworm\CSS\Value\ValueList; -use function Safe\file_get_contents; -use function Safe\opendir; - /** * @covers \Sabberworm\CSS\Parser */ @@ -61,7 +58,7 @@ public function parseForOneDeclarationBlockReturnsDocumentWithOneDeclarationBloc public function files(): void { $directory = __DIR__ . '/fixtures'; - $directoryHandle = opendir($directory); + $directoryHandle = \opendir($directory); /* This is the correct way to loop over the directory. */ while (false !== ($filename = \readdir($directoryHandle))) { @@ -76,7 +73,7 @@ public function files(): void // or a future test of an as-of-now missing feature continue; } - $parser = new Parser(file_get_contents($directory . '/' . $filename)); + $parser = new Parser(\file_get_contents($directory . '/' . $filename)); self::assertNotSame('', $parser->parse()->render()); } @@ -895,7 +892,7 @@ public function missingPropertyValueLenient(): void public static function parsedStructureForFile($filename, $settings = null): Document { $filename = __DIR__ . "/fixtures/$filename.css"; - $parser = new Parser(file_get_contents($filename), $settings); + $parser = new Parser(\file_get_contents($filename), $settings); return $parser->parse(); } From 03d0eadbe78e736fe56abcd9b736d874966cc15a Mon Sep 17 00:00:00 2001 From: Sjors Ottjes Date: Sat, 15 Aug 2026 10:58:16 +0200 Subject: [PATCH 3/5] update LenientParsingTest --- Build/phpstan/phpstan-baseline.neon | 6 ++++++ tests/RuleSet/LenientParsingTest.php | 22 ++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon index 360ef6b64..454b61a4e 100644 --- a/Build/phpstan/phpstan-baseline.neon +++ b/Build/phpstan/phpstan-baseline.neon @@ -78,6 +78,12 @@ parameters: count: 3 path: ../../tests/RuleSet/DeclarationBlockTest.php + - + message: '#^Function file_get_contents is unsafe to use\. It can return FALSE instead of throwing an exception\. Please add ''use function Safe\\file_get_contents;'' at the beginning of the file to use the variant provided by the ''thecodingmachine/safe'' library\.$#' + identifier: theCodingMachineSafe.function + count: 10 + path: ../../tests/RuleSet/LenientParsingTest.php + - message: '#^Parameter \#1 \$type of class Sabberworm\\CSS\\CSSList\\AtRuleBlockList constructor expects non\-empty\-string, '''' given\.$#' identifier: argument.type diff --git a/tests/RuleSet/LenientParsingTest.php b/tests/RuleSet/LenientParsingTest.php index ae249701d..c014f021b 100644 --- a/tests/RuleSet/LenientParsingTest.php +++ b/tests/RuleSet/LenientParsingTest.php @@ -10,8 +10,6 @@ use Sabberworm\CSS\Parsing\UnexpectedTokenException; use Sabberworm\CSS\Settings; -use function Safe\file_get_contents; - /** * @coversNothing */ @@ -25,7 +23,7 @@ public function faultToleranceOff(): void $this->expectException(UnexpectedTokenException::class); $pathToFile = __DIR__ . '/../fixtures/-fault-tolerance.css'; - $parser = new Parser(file_get_contents($pathToFile), Settings::create()->beStrict()); + $parser = new Parser(\file_get_contents($pathToFile), Settings::create()->beStrict()); $parser->parse(); } @@ -35,7 +33,7 @@ public function faultToleranceOff(): void public function faultToleranceOn(): void { $pathToFile = __DIR__ . '/../fixtures/-fault-tolerance.css'; - $parser = new Parser(file_get_contents($pathToFile), Settings::create()->withLenientParsing(true)); + $parser = new Parser(\file_get_contents($pathToFile), Settings::create()->withLenientParsing(true)); $result = $parser->parse(); self::assertSame( '.test1 {}' . "\n" . '.test2 {hello: 2.2;hello: 2000000000000.2;}' . "\n" . '#test {}' . "\n" @@ -52,7 +50,7 @@ public function endToken(): void $this->expectException(UnexpectedTokenException::class); $pathToFile = __DIR__ . '/../fixtures/-end-token.css'; - $parser = new Parser(file_get_contents($pathToFile), Settings::create()->beStrict()); + $parser = new Parser(\file_get_contents($pathToFile), Settings::create()->beStrict()); $parser->parse(); } @@ -64,7 +62,7 @@ public function endToken2(): void $this->expectException(UnexpectedTokenException::class); $pathToFile = __DIR__ . '/../fixtures/-end-token-2.css'; - $parser = new Parser(file_get_contents($pathToFile), Settings::create()->beStrict()); + $parser = new Parser(\file_get_contents($pathToFile), Settings::create()->beStrict()); $parser->parse(); } @@ -74,7 +72,7 @@ public function endToken2(): void public function endTokenPositive(): void { $pathToFile = __DIR__ . '/../fixtures/-end-token.css'; - $parser = new Parser(file_get_contents($pathToFile), Settings::create()->withLenientParsing(true)); + $parser = new Parser(\file_get_contents($pathToFile), Settings::create()->withLenientParsing(true)); $result = $parser->parse(); self::assertSame('', $result->render()); } @@ -85,7 +83,7 @@ public function endTokenPositive(): void public function endToken2Positive(): void { $pathToFile = __DIR__ . '/../fixtures/-end-token-2.css'; - $parser = new Parser(file_get_contents($pathToFile), Settings::create()->withLenientParsing(true)); + $parser = new Parser(\file_get_contents($pathToFile), Settings::create()->withLenientParsing(true)); $result = $parser->parse(); self::assertSame( '#home .bg-layout {background-image: url("/bundles/main/img/bg1.png?5");}', @@ -100,7 +98,7 @@ public function localeTrap(): void { \setlocale(LC_ALL, 'pt_PT', 'no'); $pathToFile = __DIR__ . '/../fixtures/-fault-tolerance.css'; - $parser = new Parser(file_get_contents($pathToFile), Settings::create()->withLenientParsing(true)); + $parser = new Parser(\file_get_contents($pathToFile), Settings::create()->withLenientParsing(true)); $result = $parser->parse(); self::assertSame( '.test1 {}' . "\n" . '.test2 {hello: 2.2;hello: 2000000000000.2;}' . "\n" . '#test {}' . "\n" @@ -115,7 +113,7 @@ public function localeTrap(): void public function caseInsensitivity(): void { $pathToFile = __DIR__ . '/../fixtures/case-insensitivity.css'; - $parser = new Parser(file_get_contents($pathToFile)); + $parser = new Parser(\file_get_contents($pathToFile)); $result = $parser->parse(); self::assertSame( @@ -134,7 +132,7 @@ public function caseInsensitivity(): void public function cssWithInvalidColorStillGetsParsedAsDocument(): void { $pathToFile = __DIR__ . '/../fixtures/invalid-color.css'; - $parser = new Parser(file_get_contents($pathToFile), Settings::create()->withLenientParsing(true)); + $parser = new Parser(\file_get_contents($pathToFile), Settings::create()->withLenientParsing(true)); $result = $parser->parse(); self::assertInstanceOf(Document::class, $result); @@ -148,7 +146,7 @@ public function invalidColorStrict(): void $this->expectException(UnexpectedTokenException::class); $pathToFile = __DIR__ . '/../fixtures/invalid-color.css'; - $parser = new Parser(file_get_contents($pathToFile), Settings::create()->beStrict()); + $parser = new Parser(\file_get_contents($pathToFile), Settings::create()->beStrict()); $parser->parse(); } } From 82850176cf07b5db6e54407d50caa7efbc71db70 Mon Sep 17 00:00:00 2001 From: Sjors Ottjes Date: Tue, 18 Aug 2026 04:50:47 +0200 Subject: [PATCH 4/5] Update bin/quickdump.php Co-authored-by: Oliver Klee --- bin/quickdump.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/quickdump.php b/bin/quickdump.php index cc47a817d..5cee1c3b7 100755 --- a/bin/quickdump.php +++ b/bin/quickdump.php @@ -12,7 +12,7 @@ require_once(__DIR__ . '/../vendor/autoload.php'); $source = \file_get_contents('php://stdin'); -if ($source === false) { +if (!\is_string($source)) { throw new \RuntimeException('Failed to read from stdin.'); } $parser = new Parser($source); From 82365bc8177fd83d745a5b67b38be9de4ccfefec Mon Sep 17 00:00:00 2001 From: Sjors Ottjes Date: Tue, 18 Aug 2026 04:51:11 +0200 Subject: [PATCH 5/5] Update bin/quickdump.php Co-authored-by: Oliver Klee --- bin/quickdump.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/quickdump.php b/bin/quickdump.php index 5cee1c3b7..7af97e518 100755 --- a/bin/quickdump.php +++ b/bin/quickdump.php @@ -13,7 +13,7 @@ $source = \file_get_contents('php://stdin'); if (!\is_string($source)) { - throw new \RuntimeException('Failed to read from stdin.'); + throw new \RuntimeException('Failed to read from stdin.', 1786954465); } $parser = new Parser($source);