From e4057a6631cb8f2c45e9cdc3bd7933912d1a9b7d Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sat, 7 Jun 2025 11:52:24 +0200 Subject: [PATCH 1/3] use promoted properties --- src/Element/A.php | 11 ++++------- src/Element/Base.php | 11 ++++------- src/Element/Img.php | 11 ++++------- src/Element/Link.php | 14 +++----------- src/Node/Document.php | 16 ++++++---------- src/Reader/Reader.php | 5 +---- src/Visitor/Element.php | 6 +----- src/Visitor/Elements.php | 6 +----- 8 files changed, 24 insertions(+), 56 deletions(-) diff --git a/src/Element/A.php b/src/Element/A.php index 8af124f..8dc374b 100644 --- a/src/Element/A.php +++ b/src/Element/A.php @@ -18,13 +18,10 @@ */ final class A implements Custom { - private Element $element; - private Url $href; - - private function __construct(Url $href, Element $element) - { - $this->element = $element; - $this->href = $href; + private function __construct( + private Url $href, + private Element $element, + ) { } /** diff --git a/src/Element/Base.php b/src/Element/Base.php index 50f2de3..2e96406 100644 --- a/src/Element/Base.php +++ b/src/Element/Base.php @@ -17,13 +17,10 @@ */ final class Base implements Custom { - private Element $element; - private Url $href; - - private function __construct(Url $href, Element $element) - { - $this->element = $element; - $this->href = $href; + private function __construct( + private Url $href, + private Element $element, + ) { } /** diff --git a/src/Element/Img.php b/src/Element/Img.php index bfbd0e4..0fd08ef 100644 --- a/src/Element/Img.php +++ b/src/Element/Img.php @@ -17,13 +17,10 @@ */ final class Img implements Custom { - private Element $element; - private Url $src; - - private function __construct(Url $src, Element $element) - { - $this->element = $element; - $this->src = $src; + private function __construct( + private Url $src, + private Element $element, + ) { } /** diff --git a/src/Element/Link.php b/src/Element/Link.php index 536697d..2d10097 100644 --- a/src/Element/Link.php +++ b/src/Element/Link.php @@ -17,22 +17,14 @@ */ final class Link implements Custom { - private Element $element; - private Url $href; - /** @var non-empty-string */ - private string $relationship; - /** * @param non-empty-string $relationship */ private function __construct( - Url $href, - string $relationship, - Element $element, + private Url $href, + private string $relationship, + private Element $element, ) { - $this->element = $element; - $this->href = $href; - $this->relationship = $relationship; } /** diff --git a/src/Node/Document.php b/src/Node/Document.php index b6dbfe3..bfa161b 100644 --- a/src/Node/Document.php +++ b/src/Node/Document.php @@ -22,17 +22,13 @@ */ final class Document { - private Type $type; - /** @var Sequence */ - private Sequence $children; - /** - * @param Sequence|null $children + * @param Sequence $children */ - private function __construct(Type $type, ?Sequence $children = null) - { - $this->type = $type; - $this->children = $children ?? Sequence::of(); + private function __construct( + private Type $type, + private Sequence $children, + ) { } /** @@ -42,7 +38,7 @@ private function __construct(Type $type, ?Sequence $children = null) */ public static function of(Type $type, ?Sequence $children = null): self { - return new self($type, $children); + return new self($type, $children ?? Sequence::of()); } public function type(): Type diff --git a/src/Reader/Reader.php b/src/Reader/Reader.php index 2e37dff..0a1235a 100644 --- a/src/Reader/Reader.php +++ b/src/Reader/Reader.php @@ -21,11 +21,8 @@ */ final class Reader { - private Translator $translate; - - private function __construct(Translator $translate) + private function __construct(private Translator $translate) { - $this->translate = $translate; } /** diff --git a/src/Visitor/Element.php b/src/Visitor/Element.php index 7c6be14..f8b8112 100644 --- a/src/Visitor/Element.php +++ b/src/Visitor/Element.php @@ -20,15 +20,11 @@ */ final class Element { - /** @var non-empty-string */ - private string $name; - /** * @param non-empty-string $name */ - private function __construct(string $name) + private function __construct(private string $name) { - $this->name = $name; } /** diff --git a/src/Visitor/Elements.php b/src/Visitor/Elements.php index e7c8bf6..4e95995 100644 --- a/src/Visitor/Elements.php +++ b/src/Visitor/Elements.php @@ -16,15 +16,11 @@ */ final class Elements { - /** @var non-empty-string */ - private string $name; - /** * @param non-empty-string $name */ - private function __construct(string $name) + private function __construct(private string $name) { - $this->name = $name; } /** From 2326fe2d3b91c184ab1075f2d67096200301c24f Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sat, 7 Jun 2025 11:54:11 +0200 Subject: [PATCH 2/3] move reader to root of the package --- CHANGELOG.md | 1 + README.md | 2 +- src/{Reader => }/Reader.php | 7 ++----- tests/{Reader => }/ReaderTest.php | 4 ++-- tests/Visitor/BodyTest.php | 2 +- tests/Visitor/ElementTest.php | 2 +- tests/Visitor/ElementsTest.php | 2 +- tests/Visitor/HeadTest.php | 2 +- 8 files changed, 10 insertions(+), 12 deletions(-) rename src/{Reader => }/Reader.php (92%) rename tests/{Reader => }/ReaderTest.php (97%) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed4f799..89df396 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - `Innmind\Html\Node\Document` no longer implement any interface - `Innmind\Html\Reader\Reader` now return an `Innmind\Immutable\Attempt` - `Innmind\Html\Visitor\Elements` now return a `Innmind\Immutable\Sequence` +- `Innmind\Html\Reader\Reader` has been renamed `Innmind\Html\Reader` ### Removed diff --git a/README.md b/README.md index b04164c..3789615 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ composer require innmind/html ```php use Innmind\Html\{ - Reader\Reader, + Reader, Node\Document, }; use Innmind\Xml\{ diff --git a/src/Reader/Reader.php b/src/Reader.php similarity index 92% rename from src/Reader/Reader.php rename to src/Reader.php index 0a1235a..162970d 100644 --- a/src/Reader/Reader.php +++ b/src/Reader.php @@ -1,12 +1,9 @@ Date: Sat, 7 Jun 2025 11:56:20 +0200 Subject: [PATCH 3/3] move document to root of the package --- CHANGELOG.md | 1 + README.md | 2 +- src/{Node => }/Document.php | 2 +- src/Reader.php | 1 - src/Translator.php | 13 ++++++------- src/Visitor/Element.php | 2 +- src/Visitor/Elements.php | 2 +- tests/{Node => }/DocumentTest.php | 4 ++-- tests/ReaderTest.php | 2 +- .../NodeTranslator/DocumentTranslatorTest.php | 2 +- 10 files changed, 15 insertions(+), 16 deletions(-) rename src/{Node => }/Document.php (98%) rename tests/{Node => }/DocumentTest.php (98%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89df396..23a501a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - `Innmind\Html\Reader\Reader` now return an `Innmind\Immutable\Attempt` - `Innmind\Html\Visitor\Elements` now return a `Innmind\Immutable\Sequence` - `Innmind\Html\Reader\Reader` has been renamed `Innmind\Html\Reader` +- `Innmind\Html\Node\Document` has been renamed `Innmind\Html\Document` ### Removed diff --git a/README.md b/README.md index 3789615..cdfa686 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ composer require innmind/html ```php use Innmind\Html\{ Reader, - Node\Document, + Document, }; use Innmind\Xml\{ Node, diff --git a/src/Node/Document.php b/src/Document.php similarity index 98% rename from src/Node/Document.php rename to src/Document.php index bfa161b..6a1dce4 100644 --- a/src/Node/Document.php +++ b/src/Document.php @@ -1,7 +1,7 @@