Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Build/phpstan/phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -54,12 +60,30 @@ 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
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
Expand Down
7 changes: 4 additions & 3 deletions bin/quickdump.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 (!\is_string($source)) {
throw new \RuntimeException('Failed to read from stdin.', 1786954465);
}
$parser = new Parser($source);

$document = $parser->parse();
Expand Down
9 changes: 3 additions & 6 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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))) {
Expand All @@ -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());
}

Expand Down Expand Up @@ -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();
}

Expand Down
22 changes: 10 additions & 12 deletions tests/RuleSet/LenientParsingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
use Sabberworm\CSS\Settings;

use function Safe\file_get_contents;

/**
* @coversNothing
*/
Expand All @@ -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();
}

Expand All @@ -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"
Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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());
}
Expand All @@ -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");}',
Expand All @@ -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"
Expand All @@ -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(
Expand All @@ -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);
Expand All @@ -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();
}
}