Skip to content

Commit 5bf0ddf

Browse files
authored
[TASK] Remove thecodingmachine/safe dependency (part 2) (#1615)
1 parent d432803 commit 5bf0ddf

4 files changed

Lines changed: 41 additions & 21 deletions

File tree

Build/phpstan/phpstan-baseline.neon

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
parameters:
22
ignoreErrors:
3+
-
4+
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\.$#'
5+
identifier: theCodingMachineSafe.function
6+
count: 1
7+
path: ../../bin/quickdump.php
8+
39
-
410
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\.$#'
511
identifier: theCodingMachineSafe.function
@@ -54,12 +60,30 @@ parameters:
5460
count: 1
5561
path: ../../src/Value/Value.php
5662

63+
-
64+
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\.$#'
65+
identifier: theCodingMachineSafe.function
66+
count: 2
67+
path: ../../tests/ParserTest.php
68+
69+
-
70+
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\.$#'
71+
identifier: theCodingMachineSafe.function
72+
count: 1
73+
path: ../../tests/ParserTest.php
74+
5775
-
5876
message: '#^Parameter \#1 \$value of method Sabberworm\\CSS\\Property\\Declaration\:\:setValue\(\) expects Sabberworm\\CSS\\Value\\RuleValueList\|string\|null, Sabberworm\\CSS\\Value\\Size given\.$#'
5977
identifier: argument.type
6078
count: 3
6179
path: ../../tests/RuleSet/DeclarationBlockTest.php
6280

81+
-
82+
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\.$#'
83+
identifier: theCodingMachineSafe.function
84+
count: 10
85+
path: ../../tests/RuleSet/LenientParsingTest.php
86+
6387
-
6488
message: '#^Parameter \#1 \$type of class Sabberworm\\CSS\\CSSList\\AtRuleBlockList constructor expects non\-empty\-string, '''' given\.$#'
6589
identifier: argument.type

bin/quickdump.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55

66
use Sabberworm\CSS\Parser;
77

8-
use function Safe\file_get_contents;
9-
108
/**
119
* This script is used for generating the examples in the README.
1210
*/
1311

1412
require_once(__DIR__ . '/../vendor/autoload.php');
1513

16-
$source = file_get_contents('php://stdin');
14+
$source = \file_get_contents('php://stdin');
15+
if (!\is_string($source)) {
16+
throw new \RuntimeException('Failed to read from stdin.', 1786954465);
17+
}
1718
$parser = new Parser($source);
1819

1920
$document = $parser->parse();

tests/ParserTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
use Sabberworm\CSS\Value\URL;
3131
use Sabberworm\CSS\Value\ValueList;
3232

33-
use function Safe\file_get_contents;
34-
use function Safe\opendir;
35-
3633
/**
3734
* @covers \Sabberworm\CSS\Parser
3835
*/
@@ -61,7 +58,7 @@ public function parseForOneDeclarationBlockReturnsDocumentWithOneDeclarationBloc
6158
public function files(): void
6259
{
6360
$directory = __DIR__ . '/fixtures';
64-
$directoryHandle = opendir($directory);
61+
$directoryHandle = \opendir($directory);
6562

6663
/* This is the correct way to loop over the directory. */
6764
while (false !== ($filename = \readdir($directoryHandle))) {
@@ -76,7 +73,7 @@ public function files(): void
7673
// or a future test of an as-of-now missing feature
7774
continue;
7875
}
79-
$parser = new Parser(file_get_contents($directory . '/' . $filename));
76+
$parser = new Parser(\file_get_contents($directory . '/' . $filename));
8077
self::assertNotSame('', $parser->parse()->render());
8178
}
8279

@@ -895,7 +892,7 @@ public function missingPropertyValueLenient(): void
895892
public static function parsedStructureForFile($filename, $settings = null): Document
896893
{
897894
$filename = __DIR__ . "/fixtures/$filename.css";
898-
$parser = new Parser(file_get_contents($filename), $settings);
895+
$parser = new Parser(\file_get_contents($filename), $settings);
899896
return $parser->parse();
900897
}
901898

tests/RuleSet/LenientParsingTest.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
1111
use Sabberworm\CSS\Settings;
1212

13-
use function Safe\file_get_contents;
14-
1513
/**
1614
* @coversNothing
1715
*/
@@ -25,7 +23,7 @@ public function faultToleranceOff(): void
2523
$this->expectException(UnexpectedTokenException::class);
2624

2725
$pathToFile = __DIR__ . '/../fixtures/-fault-tolerance.css';
28-
$parser = new Parser(file_get_contents($pathToFile), Settings::create()->beStrict());
26+
$parser = new Parser(\file_get_contents($pathToFile), Settings::create()->beStrict());
2927
$parser->parse();
3028
}
3129

@@ -35,7 +33,7 @@ public function faultToleranceOff(): void
3533
public function faultToleranceOn(): void
3634
{
3735
$pathToFile = __DIR__ . '/../fixtures/-fault-tolerance.css';
38-
$parser = new Parser(file_get_contents($pathToFile), Settings::create()->withLenientParsing(true));
36+
$parser = new Parser(\file_get_contents($pathToFile), Settings::create()->withLenientParsing(true));
3937
$result = $parser->parse();
4038
self::assertSame(
4139
'.test1 {}' . "\n" . '.test2 {hello: 2.2;hello: 2000000000000.2;}' . "\n" . '#test {}' . "\n"
@@ -52,7 +50,7 @@ public function endToken(): void
5250
$this->expectException(UnexpectedTokenException::class);
5351

5452
$pathToFile = __DIR__ . '/../fixtures/-end-token.css';
55-
$parser = new Parser(file_get_contents($pathToFile), Settings::create()->beStrict());
53+
$parser = new Parser(\file_get_contents($pathToFile), Settings::create()->beStrict());
5654
$parser->parse();
5755
}
5856

@@ -64,7 +62,7 @@ public function endToken2(): void
6462
$this->expectException(UnexpectedTokenException::class);
6563

6664
$pathToFile = __DIR__ . '/../fixtures/-end-token-2.css';
67-
$parser = new Parser(file_get_contents($pathToFile), Settings::create()->beStrict());
65+
$parser = new Parser(\file_get_contents($pathToFile), Settings::create()->beStrict());
6866
$parser->parse();
6967
}
7068

@@ -74,7 +72,7 @@ public function endToken2(): void
7472
public function endTokenPositive(): void
7573
{
7674
$pathToFile = __DIR__ . '/../fixtures/-end-token.css';
77-
$parser = new Parser(file_get_contents($pathToFile), Settings::create()->withLenientParsing(true));
75+
$parser = new Parser(\file_get_contents($pathToFile), Settings::create()->withLenientParsing(true));
7876
$result = $parser->parse();
7977
self::assertSame('', $result->render());
8078
}
@@ -85,7 +83,7 @@ public function endTokenPositive(): void
8583
public function endToken2Positive(): void
8684
{
8785
$pathToFile = __DIR__ . '/../fixtures/-end-token-2.css';
88-
$parser = new Parser(file_get_contents($pathToFile), Settings::create()->withLenientParsing(true));
86+
$parser = new Parser(\file_get_contents($pathToFile), Settings::create()->withLenientParsing(true));
8987
$result = $parser->parse();
9088
self::assertSame(
9189
'#home .bg-layout {background-image: url("/bundles/main/img/bg1.png?5");}',
@@ -100,7 +98,7 @@ public function localeTrap(): void
10098
{
10199
\setlocale(LC_ALL, 'pt_PT', 'no');
102100
$pathToFile = __DIR__ . '/../fixtures/-fault-tolerance.css';
103-
$parser = new Parser(file_get_contents($pathToFile), Settings::create()->withLenientParsing(true));
101+
$parser = new Parser(\file_get_contents($pathToFile), Settings::create()->withLenientParsing(true));
104102
$result = $parser->parse();
105103
self::assertSame(
106104
'.test1 {}' . "\n" . '.test2 {hello: 2.2;hello: 2000000000000.2;}' . "\n" . '#test {}' . "\n"
@@ -115,7 +113,7 @@ public function localeTrap(): void
115113
public function caseInsensitivity(): void
116114
{
117115
$pathToFile = __DIR__ . '/../fixtures/case-insensitivity.css';
118-
$parser = new Parser(file_get_contents($pathToFile));
116+
$parser = new Parser(\file_get_contents($pathToFile));
119117
$result = $parser->parse();
120118

121119
self::assertSame(
@@ -134,7 +132,7 @@ public function caseInsensitivity(): void
134132
public function cssWithInvalidColorStillGetsParsedAsDocument(): void
135133
{
136134
$pathToFile = __DIR__ . '/../fixtures/invalid-color.css';
137-
$parser = new Parser(file_get_contents($pathToFile), Settings::create()->withLenientParsing(true));
135+
$parser = new Parser(\file_get_contents($pathToFile), Settings::create()->withLenientParsing(true));
138136
$result = $parser->parse();
139137

140138
self::assertInstanceOf(Document::class, $result);
@@ -148,7 +146,7 @@ public function invalidColorStrict(): void
148146
$this->expectException(UnexpectedTokenException::class);
149147

150148
$pathToFile = __DIR__ . '/../fixtures/invalid-color.css';
151-
$parser = new Parser(file_get_contents($pathToFile), Settings::create()->beStrict());
149+
$parser = new Parser(\file_get_contents($pathToFile), Settings::create()->beStrict());
152150
$parser->parse();
153151
}
154152
}

0 commit comments

Comments
 (0)