From 1de04ece7173986c02ee3e630bfd3f21820d1585 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 18 Aug 2023 17:32:25 +0100 Subject: [PATCH 1/2] Fix deprecation warnings I'm getting a ton of error messages in my logs like: ``` Deprecated: Return type of TBela\CSS\Element::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in [...]/src/ArrayTrait.php on line 72 ``` and ``` Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in [...]/src/Value.php on line 590 ``` --- src/ArrayTrait.php | 10 +++++----- src/Element.php | 4 ++-- src/Element/AtRule.php | 4 ++-- src/Element/RuleList.php | 4 ++-- src/Parser/AccessTrait.php | 4 ++-- src/Property/PropertyList.php | 2 +- src/Value.php | 8 ++++---- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/ArrayTrait.php b/src/ArrayTrait.php index d8768471..e778942b 100755 --- a/src/ArrayTrait.php +++ b/src/ArrayTrait.php @@ -44,7 +44,7 @@ public function __unset($name) { * @param string $value * @ignore */ - public function offsetSet($offset, $value) + public function offsetSet(mixed $offset, mixed $value): void { if (is_callable([$this, 'set' . $offset])) { @@ -58,7 +58,7 @@ public function offsetSet($offset, $value) * @return bool * @ignore */ - public function offsetExists($offset) + public function offsetExists(mixed $offset): bool { return is_callable([$this, 'get' . $offset]) || is_callable([$this, 'set' . $offset]) || @@ -69,7 +69,7 @@ public function offsetExists($offset) * @param string $offset * @ignore */ - public function offsetUnset($offset) + public function offsetUnset(mixed $offset): void { if (is_callable([$this, 'set' . $offset])) { @@ -83,7 +83,7 @@ public function offsetUnset($offset) * @return mixed|null * @ignore */ - public function offsetGet($offset) + public function offsetGet(mixed $offset): mixed { if (is_callable([$this, 'get' . $offset])) { @@ -116,4 +116,4 @@ public function offsetGet($offset) return null; } -} \ No newline at end of file +} diff --git a/src/Element.php b/src/Element.php index 4983effd..6cd043b9 100755 --- a/src/Element.php +++ b/src/Element.php @@ -613,7 +613,7 @@ public function getAst() * @return stdClass * @ignore */ - public function jsonSerialize () { + public function jsonSerialize (): mixed { return $this->getAst(); } @@ -652,4 +652,4 @@ public function toObject() { return $this->ast; } -} \ No newline at end of file +} diff --git a/src/Element/AtRule.php b/src/Element/AtRule.php index 36a7786a..3b6034ab 100755 --- a/src/Element/AtRule.php +++ b/src/Element/AtRule.php @@ -100,7 +100,7 @@ public function addDeclaration ($name, $value) { * @return \stdClass * @ignore */ - public function jsonSerialize () { + public function jsonSerialize (): mixed { $ast = parent::jsonSerialize(); @@ -116,4 +116,4 @@ public function jsonSerialize () { return $ast; } -} \ No newline at end of file +} diff --git a/src/Element/RuleList.php b/src/Element/RuleList.php index 540e5bd6..93fd6f03 100755 --- a/src/Element/RuleList.php +++ b/src/Element/RuleList.php @@ -281,9 +281,9 @@ public function remove(ElementInterface $element) * return an iterator of child nodes * @return ArrayIterator|Traversable */ - public function getIterator() + public function getIterator(): \Traversable { return new ArrayIterator($this->ast->children ?? []); } -} \ No newline at end of file +} diff --git a/src/Parser/AccessTrait.php b/src/Parser/AccessTrait.php index b7b3c8b2..190a54fd 100755 --- a/src/Parser/AccessTrait.php +++ b/src/Parser/AccessTrait.php @@ -52,8 +52,8 @@ public function __clone() { /** * @return array */ - public function jsonSerialize() + public function jsonSerialize(): mixed { return get_object_vars($this); } -} \ No newline at end of file +} diff --git a/src/Property/PropertyList.php b/src/Property/PropertyList.php index d9fde4bf..041fdd2e 100755 --- a/src/Property/PropertyList.php +++ b/src/Property/PropertyList.php @@ -360,7 +360,7 @@ public function isEmpty() { /** * @inheritDoc */ - public function getIterator() + public function getIterator(): \Traversable { return $this->getProperties(); } diff --git a/src/Value.php b/src/Value.php index c5050752..fad6084d 100755 --- a/src/Value.php +++ b/src/Value.php @@ -581,13 +581,13 @@ public static function parse($string, $property = null, bool $capture_whitespace return $string; } - if (trim($property) === '') { + if (trim((string)$property) === '') { $property = null; } $string = trim($string); - $property = strtolower($property); + $property = strtolower((string)$property); if ($property !== '') { @@ -1466,8 +1466,8 @@ public function __toString() return $this->render(); } - public function jsonSerialize() + public function jsonSerialize(): mixed { return $this->render(); } -} \ No newline at end of file +} From 48edbbf0371d3e10f1076775cc65f6788b3b18b4 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 18 Aug 2023 19:26:28 +0100 Subject: [PATCH 2/2] fix another incompatible type hint --- src/Element/NestingRule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Element/NestingRule.php b/src/Element/NestingRule.php index c9995c77..18c95d7c 100755 --- a/src/Element/NestingRule.php +++ b/src/Element/NestingRule.php @@ -10,9 +10,9 @@ class NestingRule extends Rule /** * @inheritDoc */ - public function support(ElementInterface $child) + public function support(ElementInterface $child): bool { return true; } -} \ No newline at end of file +}