Skip to content

Commit a74eb08

Browse files
committed
[TASK] Add more PHP-CS-Fixer rules and autoformat the code
1 parent 991cab2 commit a74eb08

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+193
-34
lines changed

bin/quickdump.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env php
22
<?php
33

4+
declare(strict_types=1);
5+
46
/**
57
* This script is used for generating the examples in the README.
68
*/

config/php-cs-fixer.php

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,76 @@
2222
// overwrite the PER2 defaults to restore compatibility with PHP 7.x
2323
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
2424

25-
// for `in_array` & friends
26-
'strict_param' => true,
25+
// casing
26+
'magic_constant_casing' => true,
27+
'native_function_casing' => true,
28+
29+
// cast notation
30+
'modernize_types_casting' => true,
31+
'no_short_bool_cast' => true,
32+
33+
// class notation
34+
'no_php4_constructor' => true,
35+
36+
// comment
37+
'no_empty_comment' => true,
38+
39+
// control structure
40+
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
41+
42+
// function notation
43+
'native_function_invocation' => ['include' => ['@all']],
44+
45+
// import
46+
'no_unused_imports' => true,
47+
48+
// language construct
49+
'combine_consecutive_issets' => true,
50+
'combine_consecutive_unsets' => true,
51+
'dir_constant' => true,
52+
'is_null' => true,
53+
54+
// namespace notation
55+
'no_leading_namespace_whitespace' => true,
2756

57+
// operator
58+
'standardize_not_equals' => true,
59+
'ternary_to_null_coalescing' => true,
60+
61+
// PHP tag
62+
'linebreak_after_opening_tag' => true,
63+
64+
// PHPUnit
2865
'php_unit_construct' => true,
2966
'php_unit_dedicate_assert' => ['target' => 'newest'],
3067
'php_unit_expectation' => ['target' => 'newest'],
3168
'php_unit_fqcn_annotation' => true,
32-
'php_unit_method_casing' => true,
33-
'php_unit_mock' => ['target' => 'newest'],
3469
'php_unit_mock_short_will_return' => true,
35-
'php_unit_namespaced' => ['target' => 'newest'],
3670
'php_unit_set_up_tear_down_visibility' => true,
3771
'php_unit_test_annotation' => ['style' => 'annotation'],
3872
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
73+
74+
// PHPDoc
75+
'no_blank_lines_after_phpdoc' => true,
76+
'no_empty_phpdoc' => true,
77+
'phpdoc_indent' => true,
78+
'phpdoc_no_package' => true,
79+
'phpdoc_trim' => true,
80+
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
81+
82+
// return notation
83+
'no_useless_return' => true,
84+
85+
// semicolon
86+
'no_empty_statement' => true,
87+
'no_singleline_whitespace_before_semicolons' => true,
88+
'semicolon_after_instruction' => true,
89+
90+
// strict
91+
'declare_strict_types' => true,
92+
'strict_param' => true,
93+
94+
// string notation
95+
'string_implicit_backslashes' => ['single_quoted' => 'escape'],
3996
]
4097
);

src/CSSList/AtRuleBlockList.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\CSSList;
46

57
use Sabberworm\CSS\OutputFormat;

src/CSSList/CSSBlockList.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\CSSList;
46

57
use Sabberworm\CSS\Property\Selector;

src/CSSList/CSSList.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\CSSList;
46

57
use Sabberworm\CSS\Comment\Comment;

src/CSSList/Document.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\CSSList;
46

57
use Sabberworm\CSS\OutputFormat;

src/CSSList/KeyFrame.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\CSSList;
46

57
use Sabberworm\CSS\OutputFormat;

src/Comment/Comment.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\Comment;
46

57
use Sabberworm\CSS\OutputFormat;

src/Comment/Commentable.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\Comment;
46

57
interface Commentable

src/OutputFormat.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS;
46

57
/**

src/OutputFormatter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS;
46

57
use Sabberworm\CSS\Comment\Commentable;

src/Parser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS;
46

57
use Sabberworm\CSS\CSSList\Document;

src/Parsing/Anchor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\Parsing;
46

57
class Anchor

src/Parsing/OutputException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\Parsing;
46

57
/**

src/Parsing/ParserState.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\Parsing;
46

57
use Sabberworm\CSS\Comment\Comment;
@@ -144,7 +146,7 @@ public function parseIdentifier($bIgnoreCase = true)
144146
}
145147
$sCharacter = null;
146148
while (!$this->isEnd() && ($sCharacter = $this->parseCharacter(true)) !== null) {
147-
if (\preg_match('/[a-zA-Z0-9\x{00A0}-\x{FFFF}_-]/Sux', $sCharacter)) {
149+
if (\preg_match('/[a-zA-Z0-9\\x{00A0}-\\x{FFFF}_-]/Sux', $sCharacter)) {
148150
$sResult .= $sCharacter;
149151
} else {
150152
$sResult .= '\\' . $sCharacter;
@@ -169,13 +171,13 @@ public function parseCharacter($bIsForIdentifier)
169171
if ($this->peek() === '\\') {
170172
if (
171173
$bIsForIdentifier && $this->oParserSettings->bLenientParsing
172-
&& ($this->comes('\0') || $this->comes('\9'))
174+
&& ($this->comes('\\0') || $this->comes('\\9'))
173175
) {
174176
// Non-strings can contain \0 or \9 which is an IE hack supported in lenient parsing.
175177
return null;
176178
}
177179
$this->consume('\\');
178-
if ($this->comes('\n') || $this->comes('\r')) {
180+
if ($this->comes('\\n') || $this->comes('\\r')) {
179181
return '';
180182
}
181183
if (\preg_match('/[0-9a-fA-F]/Su', $this->peek()) === 0) {
@@ -185,7 +187,7 @@ public function parseCharacter($bIsForIdentifier)
185187
if ($this->strlen($sUnicode) < 6) {
186188
// Consume whitespace after incomplete unicode escape
187189
if (\preg_match('/\\s/isSu', $this->peek())) {
188-
if ($this->comes('\r\n')) {
190+
if ($this->comes('\\r\\n')) {
189191
$this->consume(2);
190192
} else {
191193
$this->consume(1);

src/Parsing/SourceException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\Parsing;
46

57
class SourceException extends \Exception

src/Parsing/UnexpectedEOFException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\Parsing;
46

57
/**

src/Parsing/UnexpectedTokenException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\Parsing;
46

57
/**

src/Property/AtRule.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\Property;
46

57
use Sabberworm\CSS\Comment\Commentable;

src/Property/CSSNamespace.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\Property;
46

57
use Sabberworm\CSS\Comment\Comment;

src/Property/Charset.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\Property;
46

57
use Sabberworm\CSS\Comment\Comment;

src/Property/Import.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\Property;
46

57
use Sabberworm\CSS\Comment\Comment;

src/Property/KeyframeSelector.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\Property;
46

57
class KeyframeSelector extends Selector
@@ -14,12 +16,12 @@ class KeyframeSelector extends Selector
1416
public const SELECTOR_VALIDATION_RX = '/
1517
^(
1618
(?:
17-
[a-zA-Z0-9\x{00A0}-\x{FFFF}_^$|*="\'~\[\]()\-\s\.:#+>]* # any sequence of valid unescaped characters
19+
[a-zA-Z0-9\\x{00A0}-\\x{FFFF}_^$|*="\'~\\[\\]()\\-\\s\\.:#+>]* # any sequence of valid unescaped characters
1820
(?:\\\\.)? # a single escaped character
19-
(?:([\'"]).*?(?<!\\\\)\2)? # a quoted text like [id="example"]
21+
(?:([\'"]).*?(?<!\\\\)\\2)? # a quoted text like [id="example"]
2022
)*
2123
)|
22-
(\d+%) # keyframe animation progress percentage (e.g. 50%)
24+
(\\d+%) # keyframe animation progress percentage (e.g. 50%)
2325
$
2426
/ux';
2527
}

src/Property/Selector.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\Property;
46

57
/**
@@ -14,11 +16,11 @@ class Selector
1416
* @var string
1517
*/
1618
private const NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX = '/
17-
(\.[\w]+) # classes
19+
(\\.[\\w]+) # classes
1820
|
19-
\[(\w+) # attributes
21+
\\[(\\w+) # attributes
2022
|
21-
(\:( # pseudo classes
23+
(\\:( # pseudo classes
2224
link|visited|active
2325
|hover|focus
2426
|lang
@@ -38,9 +40,9 @@ class Selector
3840
* @var string
3941
*/
4042
private const ELEMENTS_AND_PSEUDO_ELEMENTS_RX = '/
41-
((^|[\s\+\>\~]+)[\w]+ # elements
43+
((^|[\\s\\+\\>\\~]+)[\\w]+ # elements
4244
|
43-
\:{1,2}( # pseudo-elements
45+
\\:{1,2}( # pseudo-elements
4446
after|before|first-letter|first-line|selection
4547
))
4648
/ix';
@@ -55,9 +57,9 @@ class Selector
5557
public const SELECTOR_VALIDATION_RX = '/
5658
^(
5759
(?:
58-
[a-zA-Z0-9\x{00A0}-\x{FFFF}_^$|*="\'~\[\]()\-\s\.:#+>]* # any sequence of valid unescaped characters
60+
[a-zA-Z0-9\\x{00A0}-\\x{FFFF}_^$|*="\'~\\[\\]()\\-\\s\\.:#+>]* # any sequence of valid unescaped characters
5961
(?:\\\\.)? # a single escaped character
60-
(?:([\'"]).*?(?<!\\\\)\2)? # a quoted text like [id="example"]
62+
(?:([\'"]).*?(?<!\\\\)\\2)? # a quoted text like [id="example"]
6163
)*
6264
)$
6365
/ux';

src/Renderable.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS;
46

57
interface Renderable

src/Rule/Rule.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\Rule;
46

57
use Sabberworm\CSS\Comment\Comment;

src/RuleSet/AtRuleSet.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\RuleSet;
46

57
use Sabberworm\CSS\OutputFormat;

src/RuleSet/DeclarationBlock.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\RuleSet;
46

57
use Sabberworm\CSS\CSSList\CSSList;

src/RuleSet/RuleSet.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Sabberworm\CSS\RuleSet;
46

57
use Sabberworm\CSS\Comment\Comment;

0 commit comments

Comments
 (0)