Skip to content

Commit ae97c99

Browse files
committed
[TASK] Switch to the PER2 coding standard
Fixes #442
1 parent 8bb6080 commit ae97c99

14 files changed

+41
-43
lines changed

config/php-cs-fixer.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,27 @@
88
->setRiskyAllowed(true)
99
->setRules(
1010
[
11-
'@PSR12' => true,
12-
// Disable constant visibility from the PSR12 rule set as this would break compatibility with PHP < 7.1.
13-
'visibility_required' => ['elements' => ['property', 'method']],
11+
'@PER-CS2.0' => true,
12+
'@PER-CS2.0:risky' => true,
1413

1514
'@PHPUnit50Migration:risky' => true,
1615
'@PHPUnit52Migration:risky' => true,
1716
'@PHPUnit54Migration:risky' => true,
1817
'@PHPUnit55Migration:risky' => true,
1918
'@PHPUnit56Migration:risky' => true,
2019
'@PHPUnit57Migration:risky' => true,
20+
'@PHPUnit60Migration:risky' => true,
21+
'@PHPUnit75Migration:risky' => true,
22+
'@PHPUnit84Migration:risky' => true,
2123

2224
'php_unit_construct' => true,
23-
'php_unit_dedicate_assert' => ['target' => '5.6'],
24-
'php_unit_expectation' => ['target' => '5.6'],
25+
'php_unit_dedicate_assert' => ['target' => 'newest'],
26+
'php_unit_expectation' => ['target' => 'newest'],
2527
'php_unit_fqcn_annotation' => true,
2628
'php_unit_method_casing' => true,
27-
'php_unit_mock' => ['target' => '5.5'],
29+
'php_unit_mock' => ['target' => 'newest'],
2830
'php_unit_mock_short_will_return' => true,
29-
'php_unit_namespaced' => ['target' => '5.7'],
31+
'php_unit_namespaced' => ['target' => 'newest'],
3032
'php_unit_set_up_tear_down_visibility' => true,
3133
'php_unit_test_annotation' => ['style' => 'annotation'],
3234
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],

src/CSSList/CSSBlockList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected function allSelectors(array &$aResult, $sSpecificitySearch = null)
113113
$sComparator = $aSpecificitySearch[0];
114114
$iTargetSpecificity = $aSpecificitySearch[1];
115115
}
116-
$iTargetSpecificity = (int)$iTargetSpecificity;
116+
$iTargetSpecificity = (int) $iTargetSpecificity;
117117
$iSelectorSpecificity = $oSelector->getSpecificity();
118118
$bMatches = false;
119119
switch ($sComparator) {

src/OutputFormat.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ class OutputFormat
165165
*/
166166
private $iIndentationLevel = 0;
167167

168-
public function __construct()
169-
{
170-
}
168+
public function __construct() {}
171169

172170
/**
173171
* @param string $sName

src/Parsing/ParserState.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ParserState
1010
/**
1111
* @var null
1212
*/
13-
const EOF = null;
13+
public const EOF = null;
1414

1515
/**
1616
* @var Settings

src/Parsing/UnexpectedEOFException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
*
88
* Extends `UnexpectedTokenException` in order to preserve backwards compatibility.
99
*/
10-
class UnexpectedEOFException extends UnexpectedTokenException
11-
{
12-
}
10+
class UnexpectedEOFException extends UnexpectedTokenException {}

src/Property/AtRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ interface AtRule extends Renderable, Commentable
1313
*
1414
* @var string
1515
*/
16-
const BLOCK_RULES = 'media/document/supports/region-style/font-feature-values';
16+
public const BLOCK_RULES = 'media/document/supports/region-style/font-feature-values';
1717

1818
/**
1919
* … and more font-specific ones (to be used inside font-feature-values)
2020
*
2121
* @var string
2222
*/
23-
const SET_RULES = 'font-face/counter-style/page/swash/styleset/annotation';
23+
public const SET_RULES = 'font-face/counter-style/page/swash/styleset/annotation';
2424

2525
/**
2626
* @return string|null

src/Property/KeyframeSelector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class KeyframeSelector extends Selector
99
*
1010
* @var string
1111
*/
12-
const SELECTOR_VALIDATION_RX = '/
12+
public const SELECTOR_VALIDATION_RX = '/
1313
^(
1414
(?:
1515
[a-zA-Z0-9\x{00A0}-\x{FFFF}_^$|*="\'~\[\]()\-\s\.:#+>]* # any sequence of valid unescaped characters

src/Property/Selector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Selector
1313
*
1414
* @var string
1515
*/
16-
const NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX = '/
16+
public const NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX = '/
1717
(\.[\w]+) # classes
1818
|
1919
\[(\w+) # attributes
@@ -37,7 +37,7 @@ class Selector
3737
*
3838
* @var string
3939
*/
40-
const ELEMENTS_AND_PSEUDO_ELEMENTS_RX = '/
40+
public const ELEMENTS_AND_PSEUDO_ELEMENTS_RX = '/
4141
((^|[\s\+\>\~]+)[\w]+ # elements
4242
|
4343
\:{1,2}( # pseudo-elements
@@ -50,7 +50,7 @@ class Selector
5050
*
5151
* @var string
5252
*/
53-
const SELECTOR_VALIDATION_RX = '/
53+
public const SELECTOR_VALIDATION_RX = '/
5454
^(
5555
(?:
5656
[a-zA-Z0-9\x{00A0}-\x{FFFF}_^$|*="\'~\[\]()\-\s\.:#+>]* # any sequence of valid unescaped characters

src/RuleSet/DeclarationBlock.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,9 @@ public function createDimensionsShorthand()
682682
$aValues[$sPosition] = $aRuleValues;
683683
}
684684
$oNewRule = new Rule($sProperty, $oRule->getLineNo(), $oRule->getColNo());
685-
if ((string)$aValues['left'][0] == (string)$aValues['right'][0]) {
686-
if ((string)$aValues['top'][0] == (string)$aValues['bottom'][0]) {
687-
if ((string)$aValues['top'][0] == (string)$aValues['left'][0]) {
685+
if ((string) $aValues['left'][0] == (string) $aValues['right'][0]) {
686+
if ((string) $aValues['top'][0] == (string) $aValues['bottom'][0]) {
687+
if ((string) $aValues['top'][0] == (string) $aValues['left'][0]) {
688688
// All 4 sides are equal
689689
$oNewRule->addValue($aValues['top']);
690690
} else {

src/Value/CalcFunction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ class CalcFunction extends CSSFunction
1111
/**
1212
* @var int
1313
*/
14-
const T_OPERAND = 1;
14+
public const T_OPERAND = 1;
1515

1616
/**
1717
* @var int
1818
*/
19-
const T_OPERATOR = 2;
19+
public const T_OPERATOR = 2;
2020

2121
/**
2222
* @param ParserState $oParserState

src/Value/Size.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ class Size extends PrimitiveValue
1717
*
1818
* @var array<int, string>
1919
*/
20-
const ABSOLUTE_SIZE_UNITS = ['px', 'cm', 'mm', 'mozmm', 'in', 'pt', 'pc', 'vh', 'vw', 'vmin', 'vmax', 'rem'];
20+
public const ABSOLUTE_SIZE_UNITS = ['px', 'cm', 'mm', 'mozmm', 'in', 'pt', 'pc', 'vh', 'vw', 'vmin', 'vmax', 'rem'];
2121

2222
/**
2323
* @var array<int, string>
2424
*/
25-
const RELATIVE_SIZE_UNITS = ['%', 'em', 'ex', 'ch', 'fr'];
25+
public const RELATIVE_SIZE_UNITS = ['%', 'em', 'ex', 'ch', 'fr'];
2626

2727
/**
2828
* @var array<int, string>
2929
*/
30-
const NON_SIZE_UNITS = ['deg', 'grad', 'rad', 's', 'ms', 'turn', 'Hz', 'kHz'];
30+
public const NON_SIZE_UNITS = ['deg', 'grad', 'rad', 's', 'ms', 'turn', 'Hz', 'kHz'];
3131

3232
/**
3333
* @var array<int, array<string, string>>|null
@@ -58,7 +58,7 @@ class Size extends PrimitiveValue
5858
public function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $iLineNo = 0)
5959
{
6060
parent::__construct($iLineNo);
61-
$this->fSize = (float)$fSize;
61+
$this->fSize = (float) $fSize;
6262
$this->sUnit = $sUnit;
6363
$this->bIsColorComponent = $bIsColorComponent;
6464
}
@@ -103,7 +103,7 @@ public static function parse(ParserState $oParserState, $bIsColorComponent = fal
103103
}
104104
}
105105
}
106-
return new Size((float)$sSize, $sUnit, $bIsColorComponent, $oParserState->currentLine());
106+
return new Size((float) $sSize, $sUnit, $bIsColorComponent, $oParserState->currentLine());
107107
}
108108

109109
/**
@@ -150,7 +150,7 @@ public function getUnit()
150150
*/
151151
public function setSize($fSize)
152152
{
153-
$this->fSize = (float)$fSize;
153+
$this->fSize = (float) $fSize;
154154
}
155155

156156
/**
@@ -211,7 +211,7 @@ public function render(OutputFormat $oOutputFormat)
211211
{
212212
$l = localeconv();
213213
$sPoint = preg_quote($l['decimal_point'], '/');
214-
$sSize = preg_match("/[\d\.]+e[+-]?\d+/i", (string)$this->fSize)
214+
$sSize = preg_match("/[\d\.]+e[+-]?\d+/i", (string) $this->fSize)
215215
? preg_replace("/$sPoint?0+$/", "", sprintf("%f", $this->fSize)) : $this->fSize;
216216
return preg_replace(["/$sPoint/", "/^(-?)0\./"], ['.', '$1.'], $sSize)
217217
. ($this->sUnit === null ? '' : $this->sUnit);

tests/Comment/CommentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function toStringRendersCommentEnclosedInCommentDelimiters()
9191

9292
$subject->setComment($comment);
9393

94-
self::assertSame('/*' . $comment . '*/', (string)$subject);
94+
self::assertSame('/*' . $comment . '*/', (string) $subject);
9595
}
9696

9797
/**

tests/OutputFormatTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class OutputFormatTest extends TestCase
1616
/**
1717
* @var string
1818
*/
19-
const TEST_CSS = <<<EOT
19+
public const TEST_CSS = <<<EOT
2020
2121
.main, .test {
2222
font: italic normal bold 16px/1.2 "Helvetica", Verdana, sans-serif;

tests/RuleSet/DeclarationBlockTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function expandBorderShorthand($sCss, $sExpected)
2727
foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) {
2828
$oDeclaration->expandBorderShorthand();
2929
}
30-
self::assertSame(trim((string)$oDoc), $sExpected);
30+
self::assertSame(trim((string) $oDoc), $sExpected);
3131
}
3232

3333
/**
@@ -60,7 +60,7 @@ public function expandFontShorthand($sCss, $sExpected)
6060
foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) {
6161
$oDeclaration->expandFontShorthand();
6262
}
63-
self::assertSame(trim((string)$oDoc), $sExpected);
63+
self::assertSame(trim((string) $oDoc), $sExpected);
6464
}
6565

6666
/**
@@ -116,7 +116,7 @@ public function expandBackgroundShorthand($sCss, $sExpected)
116116
foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) {
117117
$oDeclaration->expandBackgroundShorthand();
118118
}
119-
self::assertSame(trim((string)$oDoc), $sExpected);
119+
self::assertSame(trim((string) $oDoc), $sExpected);
120120
}
121121

122122
/**
@@ -169,7 +169,7 @@ public function expandDimensionsShorthand($sCss, $sExpected)
169169
foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) {
170170
$oDeclaration->expandDimensionsShorthand();
171171
}
172-
self::assertSame(trim((string)$oDoc), $sExpected);
172+
self::assertSame(trim((string) $oDoc), $sExpected);
173173
}
174174

175175
/**
@@ -207,7 +207,7 @@ public function createBorderShorthand($sCss, $sExpected)
207207
foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) {
208208
$oDeclaration->createBorderShorthand();
209209
}
210-
self::assertSame(trim((string)$oDoc), $sExpected);
210+
self::assertSame(trim((string) $oDoc), $sExpected);
211211
}
212212

213213
/**
@@ -238,7 +238,7 @@ public function createFontShorthand($sCss, $sExpected)
238238
foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) {
239239
$oDeclaration->createFontShorthand();
240240
}
241-
self::assertSame(trim((string)$oDoc), $sExpected);
241+
self::assertSame(trim((string) $oDoc), $sExpected);
242242
}
243243

244244
/**
@@ -281,7 +281,7 @@ public function createDimensionsShorthand($sCss, $sExpected)
281281
foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) {
282282
$oDeclaration->createDimensionsShorthand();
283283
}
284-
self::assertSame(trim((string)$oDoc), $sExpected);
284+
self::assertSame(trim((string) $oDoc), $sExpected);
285285
}
286286

287287
/**
@@ -319,7 +319,7 @@ public function createBackgroundShorthand($sCss, $sExpected)
319319
foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) {
320320
$oDeclaration->createBackgroundShorthand();
321321
}
322-
self::assertSame(trim((string)$oDoc), $sExpected);
322+
self::assertSame(trim((string) $oDoc), $sExpected);
323323
}
324324

325325
/**

0 commit comments

Comments
 (0)