From 1c36d33cef3bbbe1909eba184d6a9dfd2aa3b6db Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 26 Jan 2025 15:42:53 +0100 Subject: [PATCH 1/2] [TASK] Use native types for all constructor parameters Part of #811 --- src/Property/CSSNamespace.php | 4 +--- src/Rule/Rule.php | 4 +--- src/RuleSet/AtRuleSet.php | 3 +-- src/Value/CSSFunction.php | 6 ++---- src/Value/RuleValueList.php | 3 +-- src/Value/ValueList.php | 5 ++--- 6 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/Property/CSSNamespace.php b/src/Property/CSSNamespace.php index 78989d8a3..3dc00c7df 100644 --- a/src/Property/CSSNamespace.php +++ b/src/Property/CSSNamespace.php @@ -35,11 +35,9 @@ class CSSNamespace implements AtRule protected $comments = []; /** - * @param string $url - * @param string|null $prefix * @param int<0, max> $lineNumber */ - public function __construct($url, $prefix = null, int $lineNumber = 0) + public function __construct(string $url, ?string $prefix = null, int $lineNumber = 0) { $this->url = $url; $this->prefix = $prefix; diff --git a/src/Rule/Rule.php b/src/Rule/Rule.php index a20e864d9..bbb7c7137 100644 --- a/src/Rule/Rule.php +++ b/src/Rule/Rule.php @@ -56,11 +56,9 @@ class Rule implements Renderable, Commentable protected $comments = []; /** - * @param string $rule * @param int<0, max> $lineNumber - * @param int $columnNumber */ - public function __construct($rule, int $lineNumber = 0, $columnNumber = 0) + public function __construct(string $rule, int $lineNumber = 0, int $columnNumber = 0) { $this->rule = $rule; $this->lineNumber = $lineNumber; diff --git a/src/RuleSet/AtRuleSet.php b/src/RuleSet/AtRuleSet.php index a896246b9..46562eb12 100644 --- a/src/RuleSet/AtRuleSet.php +++ b/src/RuleSet/AtRuleSet.php @@ -27,10 +27,9 @@ class AtRuleSet extends RuleSet implements AtRule /** * @param non-empty-string $type - * @param string $arguments * @param int<0, max> $lineNumber */ - public function __construct($type, $arguments = '', int $lineNumber = 0) + public function __construct(string $type, string $arguments = '', int $lineNumber = 0) { parent::__construct($lineNumber); $this->type = $type; diff --git a/src/Value/CSSFunction.php b/src/Value/CSSFunction.php index 3c10900e9..fe20efff7 100644 --- a/src/Value/CSSFunction.php +++ b/src/Value/CSSFunction.php @@ -24,12 +24,10 @@ class CSSFunction extends ValueList protected $name; /** - * @param string $name - * @param RuleValueList|array $arguments - * @param string $separator + * @param RuleValueList|array $aArguments * @param int<0, max> $lineNumber */ - public function __construct($name, $arguments, $separator = ',', int $lineNumber = 0) + public function __construct(string $name, $arguments, string $separator = ',', int $lineNumber = 0) { if ($arguments instanceof RuleValueList) { $separator = $arguments->getListSeparator(); diff --git a/src/Value/RuleValueList.php b/src/Value/RuleValueList.php index 9e5059795..2cbc1fcc9 100644 --- a/src/Value/RuleValueList.php +++ b/src/Value/RuleValueList.php @@ -12,10 +12,9 @@ class RuleValueList extends ValueList { /** - * @param string $separator * @param int<0, max> $lineNumber */ - public function __construct($separator = ',', int $lineNumber = 0) + public function __construct(string $separator = ',', int $lineNumber = 0) { parent::__construct([], $separator, $lineNumber); } diff --git a/src/Value/ValueList.php b/src/Value/ValueList.php index 8a50809de..9f430a952 100644 --- a/src/Value/ValueList.php +++ b/src/Value/ValueList.php @@ -29,11 +29,10 @@ abstract class ValueList extends Value protected $separator; /** - * @param array|Value|string $components - * @param string $separator + * @param array|Value|string $aComponents * @param int<0, max> $lineNumber */ - public function __construct($components = [], $separator = ',', int $lineNumber = 0) + public function __construct($components = [], string $separator = ',', int $lineNumber = 0) { parent::__construct($lineNumber); if (!\is_array($components)) { From b7b0433d9bcc5baaf4ffba7eacbd7f092f737ba3 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 25 Feb 2025 13:08:14 +0100 Subject: [PATCH 2/2] Fix some types --- config/phpstan-baseline.neon | 4 ++-- src/Property/CSSNamespace.php | 11 +++++++---- src/Value/CSSFunction.php | 2 +- src/Value/ValueList.php | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/config/phpstan-baseline.neon b/config/phpstan-baseline.neon index 89348ca39..a9dcb0ba2 100644 --- a/config/phpstan-baseline.neon +++ b/config/phpstan-baseline.neon @@ -43,8 +43,8 @@ parameters: path: ../src/CSSList/Document.php - - message: '#^Cannot call method render\(\) on string\.$#' - identifier: method.nonObject + message: '#^Method Sabberworm\\CSS\\Property\\CSSNamespace\:\:atRuleArgs\(\) should return array\ but returns list\\.$#' + identifier: return.type count: 1 path: ../src/Property/CSSNamespace.php diff --git a/src/Property/CSSNamespace.php b/src/Property/CSSNamespace.php index 3dc00c7df..155387caf 100644 --- a/src/Property/CSSNamespace.php +++ b/src/Property/CSSNamespace.php @@ -6,6 +6,8 @@ use Sabberworm\CSS\Comment\Comment; use Sabberworm\CSS\OutputFormat; +use Sabberworm\CSS\Value\CSSString; +use Sabberworm\CSS\Value\URL; /** * `CSSNamespace` represents an `@namespace` rule. @@ -13,7 +15,7 @@ class CSSNamespace implements AtRule { /** - * @var string + * @var CSSString|URL */ private $url; @@ -35,9 +37,10 @@ class CSSNamespace implements AtRule protected $comments = []; /** + * @param CSSString|URL $url * @param int<0, max> $lineNumber */ - public function __construct(string $url, ?string $prefix = null, int $lineNumber = 0) + public function __construct($url, ?string $prefix = null, int $lineNumber = 0) { $this->url = $url; $this->prefix = $prefix; @@ -67,7 +70,7 @@ public function render(OutputFormat $outputFormat): string } /** - * @return string + * @return CSSString|URL */ public function getUrl() { @@ -83,7 +86,7 @@ public function getPrefix() } /** - * @param string $url + * @param CSSString|URL $url */ public function setUrl($url): void { diff --git a/src/Value/CSSFunction.php b/src/Value/CSSFunction.php index fe20efff7..aa5e66e70 100644 --- a/src/Value/CSSFunction.php +++ b/src/Value/CSSFunction.php @@ -24,7 +24,7 @@ class CSSFunction extends ValueList protected $name; /** - * @param RuleValueList|array $aArguments + * @param RuleValueList|array $arguments * @param int<0, max> $lineNumber */ public function __construct(string $name, $arguments, string $separator = ',', int $lineNumber = 0) diff --git a/src/Value/ValueList.php b/src/Value/ValueList.php index 9f430a952..aed4ec609 100644 --- a/src/Value/ValueList.php +++ b/src/Value/ValueList.php @@ -29,7 +29,7 @@ abstract class ValueList extends Value protected $separator; /** - * @param array|Value|string $aComponents + * @param array|Value|string $components * @param int<0, max> $lineNumber */ public function __construct($components = [], string $separator = ',', int $lineNumber = 0)