From 5887c84833b02dcd97f93461b9a9916ad7dd9f24 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Mon, 12 Feb 2024 18:14:09 +0100 Subject: [PATCH] [TASK] Switch to the PER2 coding standard Fixes #442 --- config/php-cs-fixer.php | 16 +++++++++------- src/CSSList/CSSBlockList.php | 2 +- src/OutputFormat.php | 4 +--- src/Parsing/UnexpectedEOFException.php | 4 +--- src/RuleSet/DeclarationBlock.php | 6 +++--- src/Value/Size.php | 8 ++++---- tests/Comment/CommentTest.php | 2 +- tests/RuleSet/DeclarationBlockTest.php | 16 ++++++++-------- 8 files changed, 28 insertions(+), 30 deletions(-) diff --git a/config/php-cs-fixer.php b/config/php-cs-fixer.php index 88a9a692..76f52077 100644 --- a/config/php-cs-fixer.php +++ b/config/php-cs-fixer.php @@ -8,9 +8,8 @@ ->setRiskyAllowed(true) ->setRules( [ - '@PSR12' => true, - // Disable constant visibility from the PSR12 rule set as this would break compatibility with PHP < 7.1. - 'visibility_required' => ['elements' => ['property', 'method']], + '@PER-CS2.0' => true, + '@PER-CS2.0:risky' => true, '@PHPUnit50Migration:risky' => true, '@PHPUnit52Migration:risky' => true, @@ -18,15 +17,18 @@ '@PHPUnit55Migration:risky' => true, '@PHPUnit56Migration:risky' => true, '@PHPUnit57Migration:risky' => true, + '@PHPUnit60Migration:risky' => true, + '@PHPUnit75Migration:risky' => true, + '@PHPUnit84Migration:risky' => true, 'php_unit_construct' => true, - 'php_unit_dedicate_assert' => ['target' => '5.6'], - 'php_unit_expectation' => ['target' => '5.6'], + 'php_unit_dedicate_assert' => ['target' => 'newest'], + 'php_unit_expectation' => ['target' => 'newest'], 'php_unit_fqcn_annotation' => true, 'php_unit_method_casing' => true, - 'php_unit_mock' => ['target' => '5.5'], + 'php_unit_mock' => ['target' => 'newest'], 'php_unit_mock_short_will_return' => true, - 'php_unit_namespaced' => ['target' => '5.7'], + 'php_unit_namespaced' => ['target' => 'newest'], 'php_unit_set_up_tear_down_visibility' => true, 'php_unit_test_annotation' => ['style' => 'annotation'], 'php_unit_test_case_static_method_calls' => ['call_type' => 'self'], diff --git a/src/CSSList/CSSBlockList.php b/src/CSSList/CSSBlockList.php index fce7913e..6b02edfb 100644 --- a/src/CSSList/CSSBlockList.php +++ b/src/CSSList/CSSBlockList.php @@ -113,7 +113,7 @@ protected function allSelectors(array &$aResult, $sSpecificitySearch = null) $sComparator = $aSpecificitySearch[0]; $iTargetSpecificity = $aSpecificitySearch[1]; } - $iTargetSpecificity = (int)$iTargetSpecificity; + $iTargetSpecificity = (int) $iTargetSpecificity; $iSelectorSpecificity = $oSelector->getSpecificity(); $bMatches = false; switch ($sComparator) { diff --git a/src/OutputFormat.php b/src/OutputFormat.php index 96f26e14..9cc2ae4d 100644 --- a/src/OutputFormat.php +++ b/src/OutputFormat.php @@ -165,9 +165,7 @@ class OutputFormat */ private $iIndentationLevel = 0; - public function __construct() - { - } + public function __construct() {} /** * @param string $sName diff --git a/src/Parsing/UnexpectedEOFException.php b/src/Parsing/UnexpectedEOFException.php index 368ec70c..825cc0c4 100644 --- a/src/Parsing/UnexpectedEOFException.php +++ b/src/Parsing/UnexpectedEOFException.php @@ -7,6 +7,4 @@ * * Extends `UnexpectedTokenException` in order to preserve backwards compatibility. */ -class UnexpectedEOFException extends UnexpectedTokenException -{ -} +class UnexpectedEOFException extends UnexpectedTokenException {} diff --git a/src/RuleSet/DeclarationBlock.php b/src/RuleSet/DeclarationBlock.php index b218bd8c..91f5ecef 100644 --- a/src/RuleSet/DeclarationBlock.php +++ b/src/RuleSet/DeclarationBlock.php @@ -682,9 +682,9 @@ public function createDimensionsShorthand() $aValues[$sPosition] = $aRuleValues; } $oNewRule = new Rule($sProperty, $oRule->getLineNo(), $oRule->getColNo()); - if ((string)$aValues['left'][0] == (string)$aValues['right'][0]) { - if ((string)$aValues['top'][0] == (string)$aValues['bottom'][0]) { - if ((string)$aValues['top'][0] == (string)$aValues['left'][0]) { + if ((string) $aValues['left'][0] == (string) $aValues['right'][0]) { + if ((string) $aValues['top'][0] == (string) $aValues['bottom'][0]) { + if ((string) $aValues['top'][0] == (string) $aValues['left'][0]) { // All 4 sides are equal $oNewRule->addValue($aValues['top']); } else { diff --git a/src/Value/Size.php b/src/Value/Size.php index 0ef18e24..46036f94 100644 --- a/src/Value/Size.php +++ b/src/Value/Size.php @@ -58,7 +58,7 @@ class Size extends PrimitiveValue public function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $iLineNo = 0) { parent::__construct($iLineNo); - $this->fSize = (float)$fSize; + $this->fSize = (float) $fSize; $this->sUnit = $sUnit; $this->bIsColorComponent = $bIsColorComponent; } @@ -103,7 +103,7 @@ public static function parse(ParserState $oParserState, $bIsColorComponent = fal } } } - return new Size((float)$sSize, $sUnit, $bIsColorComponent, $oParserState->currentLine()); + return new Size((float) $sSize, $sUnit, $bIsColorComponent, $oParserState->currentLine()); } /** @@ -150,7 +150,7 @@ public function getUnit() */ public function setSize($fSize) { - $this->fSize = (float)$fSize; + $this->fSize = (float) $fSize; } /** @@ -211,7 +211,7 @@ public function render(OutputFormat $oOutputFormat) { $l = localeconv(); $sPoint = preg_quote($l['decimal_point'], '/'); - $sSize = preg_match("/[\d\.]+e[+-]?\d+/i", (string)$this->fSize) + $sSize = preg_match("/[\d\.]+e[+-]?\d+/i", (string) $this->fSize) ? preg_replace("/$sPoint?0+$/", "", sprintf("%f", $this->fSize)) : $this->fSize; return preg_replace(["/$sPoint/", "/^(-?)0\./"], ['.', '$1.'], $sSize) . ($this->sUnit === null ? '' : $this->sUnit); diff --git a/tests/Comment/CommentTest.php b/tests/Comment/CommentTest.php index d26da963..7261e9ba 100644 --- a/tests/Comment/CommentTest.php +++ b/tests/Comment/CommentTest.php @@ -91,7 +91,7 @@ public function toStringRendersCommentEnclosedInCommentDelimiters() $subject->setComment($comment); - self::assertSame('/*' . $comment . '*/', (string)$subject); + self::assertSame('/*' . $comment . '*/', (string) $subject); } /** diff --git a/tests/RuleSet/DeclarationBlockTest.php b/tests/RuleSet/DeclarationBlockTest.php index 27c6615f..31537a9b 100644 --- a/tests/RuleSet/DeclarationBlockTest.php +++ b/tests/RuleSet/DeclarationBlockTest.php @@ -27,7 +27,7 @@ public function expandBorderShorthand($sCss, $sExpected) foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->expandBorderShorthand(); } - self::assertSame(trim((string)$oDoc), $sExpected); + self::assertSame(trim((string) $oDoc), $sExpected); } /** @@ -60,7 +60,7 @@ public function expandFontShorthand($sCss, $sExpected) foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->expandFontShorthand(); } - self::assertSame(trim((string)$oDoc), $sExpected); + self::assertSame(trim((string) $oDoc), $sExpected); } /** @@ -116,7 +116,7 @@ public function expandBackgroundShorthand($sCss, $sExpected) foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->expandBackgroundShorthand(); } - self::assertSame(trim((string)$oDoc), $sExpected); + self::assertSame(trim((string) $oDoc), $sExpected); } /** @@ -169,7 +169,7 @@ public function expandDimensionsShorthand($sCss, $sExpected) foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->expandDimensionsShorthand(); } - self::assertSame(trim((string)$oDoc), $sExpected); + self::assertSame(trim((string) $oDoc), $sExpected); } /** @@ -207,7 +207,7 @@ public function createBorderShorthand($sCss, $sExpected) foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->createBorderShorthand(); } - self::assertSame(trim((string)$oDoc), $sExpected); + self::assertSame(trim((string) $oDoc), $sExpected); } /** @@ -238,7 +238,7 @@ public function createFontShorthand($sCss, $sExpected) foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->createFontShorthand(); } - self::assertSame(trim((string)$oDoc), $sExpected); + self::assertSame(trim((string) $oDoc), $sExpected); } /** @@ -281,7 +281,7 @@ public function createDimensionsShorthand($sCss, $sExpected) foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->createDimensionsShorthand(); } - self::assertSame(trim((string)$oDoc), $sExpected); + self::assertSame(trim((string) $oDoc), $sExpected); } /** @@ -319,7 +319,7 @@ public function createBackgroundShorthand($sCss, $sExpected) foreach ($oDoc->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->createBackgroundShorthand(); } - self::assertSame(trim((string)$oDoc), $sExpected); + self::assertSame(trim((string) $oDoc), $sExpected); } /**