diff --git a/src/Element/RuleList.php b/src/Element/RuleList.php index dfdfb9a..9593133 100755 --- a/src/Element/RuleList.php +++ b/src/Element/RuleList.php @@ -43,12 +43,14 @@ public function __get($name) { return $this->ast->children ?? []; } + + return null; } /** * @inheritDoc */ - public function addComment($value) + public function addComment(string $value): Comment { $comment = new Comment(); @@ -57,10 +59,11 @@ public function addComment($value) return $this->append($comment); } - /** - * @inheritDoc - */ - public function computeShortHand() { + /** + * @inheritDoc + * @throws \Exception + */ + public function computeShortHand(): RuleListInterface { foreach (new NodeWalker($this) as $event => $node) { // -> @@ -108,7 +111,7 @@ public function computeShortHand() { /** * @inheritDoc */ - public function hasChildren() + public function hasChildren(): bool { return isset($this->ast->children) && count($this->ast->children) > 0; @@ -117,7 +120,7 @@ public function hasChildren() /** * @inheritDoc */ - public function removeChildren() + public function removeChildren(): ElementInterface { if (!empty($this->ast->isLeaf)) { @@ -143,13 +146,13 @@ public function removeChildren() /** * @inheritDoc */ - public function getChildren() + public function getChildren(): array { return $this->ast->children ?? []; } - public function setChildren(array $elements) { + public function setChildren(array $elements): RuleListInterface { if (!empty($this->ast->children)) { @@ -194,14 +197,14 @@ public function support(ElementInterface $child): bool /** * @inheritDoc */ - public function append(ElementInterface ...$elements) + public function append(ElementInterface ...$elements): ElementInterface|array { foreach ($elements as $element) { if (!$this->support($element)) { - throw new InvalidArgumentException(sprintf('%s: invalid child of type %s', $this->type, $element->type), 400); + throw new InvalidArgumentException(sprintf('%s: invalid child of type %s', $this->ast->type, $element->ast->type), 400); } if ($element instanceof Stylesheet) { @@ -229,7 +232,7 @@ public function append(ElementInterface ...$elements) /** * @inheritDoc */ - public function appendCss($css) { + public function appendCss(string $css): RuleListInterface { $this->append((new Parser($css))->parse()); @@ -239,7 +242,7 @@ public function appendCss($css) { /** * @inheritDoc */ - public function insert(ElementInterface $element, $position) + public function insert(ElementInterface $element, int $position): ElementInterface { if (!$this->support($element) || $position < 0) { @@ -268,8 +271,8 @@ public function insert(ElementInterface $element, $position) /** * @inheritDoc */ - public function remove(ElementInterface $element) - { + public function remove(ElementInterface $element): ElementInterface + { if ($element->getParent() === $this) { @@ -289,8 +292,8 @@ public function remove(ElementInterface $element) * return an iterator of child nodes * @return ArrayIterator|Traversable */ - public function getIterator() - { + public function getIterator(): Traversable|ArrayIterator + { return new ArrayIterator($this->ast->children ?? []); } diff --git a/src/Interfaces/RuleListInterface.php b/src/Interfaces/RuleListInterface.php index 4248f26..a0a34fc 100755 --- a/src/Interfaces/RuleListInterface.php +++ b/src/Interfaces/RuleListInterface.php @@ -4,6 +4,7 @@ use Exception; use IteratorAggregate; +use TBela\CSS\Element\Comment; /** * Interface implemented by rules containers @@ -18,12 +19,12 @@ interface RuleListInterface extends ElementInterface, IteratorAggregate { * return true if the node has children * @return bool */ - public function hasChildren(); + public function hasChildren(): bool; /** * return child nodes * @return array */ - public function getChildren(); + public function getChildren(): array; /** * append child node @@ -31,15 +32,15 @@ public function getChildren(); * @return ElementInterface * @throws Exception */ - public function setChildren(array $elements); + public function setChildren(array $elements): ElementInterface; /** * Add a comment node * @param string $value - * @return Element\Comment + * @return Comment * @throws Exception */ - public function addComment($value); + public function addComment(string $value): Comment; /** * check if this node accepts element as a child @@ -51,10 +52,10 @@ public function support(ElementInterface $child): bool; /** * append child nodes * @param ElementInterface|ElementInterface[] $elements - * @return ElementInterface + * @return ElementInterface|ElementInterface[] * @throws Exception */ - public function append(ElementInterface ...$elements); + public function append(ElementInterface ...$elements): ElementInterface|array; /** * append css text to this node @@ -62,7 +63,7 @@ public function append(ElementInterface ...$elements); * @return ElementInterface * @throws Exception */ - public function appendCss($css); + public function appendCss(string $css): ElementInterface; /** * insert a child node at the specified position @@ -71,23 +72,23 @@ public function appendCss($css); * @return ElementInterface * @throws Exception */ - public function insert(ElementInterface $element, $position); + public function insert(ElementInterface $element, int $position): ElementInterface; /** * remove a child node from its parent * @param ElementInterface $element * @return ElementInterface */ - public function remove(ElementInterface $element); + public function remove(ElementInterface $element): ElementInterface; /** * Remove all children * @return ElementInterface */ - public function removeChildren(); + public function removeChildren(): ElementInterface; /** * @return RuleListInterface */ - public function computeShortHand(); + public function computeShortHand(): RuleListInterface; } \ No newline at end of file