Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
- `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`
- `Innmind\Html\Node\Document` has been renamed `Innmind\Html\Document`

### Removed

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ composer require innmind/html

```php
use Innmind\Html\{
Reader\Reader,
Node\Document,
Reader,
Document,
};
use Innmind\Xml\{
Node,
Expand Down
18 changes: 7 additions & 11 deletions src/Node/Document.php → src/Document.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types = 1);

namespace Innmind\Html\Node;
namespace Innmind\Html;

use Innmind\Xml\{
Node,
Expand All @@ -22,17 +22,13 @@
*/
final class Document
{
private Type $type;
/** @var Sequence<Node|Element|Custom> */
private Sequence $children;

/**
* @param Sequence<Node|Element|Custom>|null $children
* @param Sequence<Node|Element|Custom> $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,
) {
}

/**
Expand All @@ -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
Expand Down
11 changes: 4 additions & 7 deletions src/Element/A.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

/**
Expand Down
11 changes: 4 additions & 7 deletions src/Element/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

/**
Expand Down
11 changes: 4 additions & 7 deletions src/Element/Img.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

/**
Expand Down
14 changes: 3 additions & 11 deletions src/Element/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
11 changes: 2 additions & 9 deletions src/Reader/Reader.php → src/Reader.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<?php
declare(strict_types = 1);

namespace Innmind\Html\Reader;
namespace Innmind\Html;

use Innmind\Html\{
Node\Document,
Translator,
};
use Innmind\Xml\{
Node,
Element,
Expand All @@ -21,11 +17,8 @@
*/
final class Reader
{
private Translator $translate;

private function __construct(Translator $translate)
private function __construct(private Translator $translate)
{
$this->translate = $translate;
}

/**
Expand Down
13 changes: 6 additions & 7 deletions src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

namespace Innmind\Html;

use Innmind\Html\{
Element\A,
Element\Base,
Element\Img,
Element\Link,
Element\Script,
Node\Document,
use Innmind\Html\Element\{
A,
Base,
Img,
Link,
Script,
};
use Innmind\Xml\{
Element,
Expand Down
8 changes: 2 additions & 6 deletions src/Visitor/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Innmind\Html\Visitor;

use Innmind\Html\Node\Document;
use Innmind\Html\Document;
use Innmind\Xml\{
Node,
Element as Model,
Expand All @@ -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;
}

/**
Expand Down
8 changes: 2 additions & 6 deletions src/Visitor/Elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Innmind\Html\Visitor;

use Innmind\Html\Node\Document;
use Innmind\Html\Document;
use Innmind\Xml\{
Node,
Element,
Expand All @@ -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;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Node/DocumentTest.php → tests/DocumentTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
declare(strict_types = 1);

namespace Tests\Innmind\Html\Node;
namespace Tests\Innmind\Html;

use Innmind\Html\Node\Document;
use Innmind\Html\Document;
use Innmind\Xml\{
Node,
Document\Type,
Expand Down
6 changes: 3 additions & 3 deletions tests/Reader/ReaderTest.php → tests/ReaderTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
declare(strict_types = 1);

namespace Tests\Innmind\Html\Reader;
namespace Tests\Innmind\Html;

use Innmind\Html\{
Reader\Reader,
Node\Document,
Reader,
Document,
};
use Innmind\Xml\Format;
use Innmind\Filesystem\File\Content;
Expand Down
2 changes: 1 addition & 1 deletion tests/Translator/NodeTranslator/DocumentTranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use Innmind\Html\{
Translator,
Node\Document,
Document,
};
use Innmind\BlackBox\PHPUnit\Framework\TestCase;

Expand Down
2 changes: 1 addition & 1 deletion tests/Visitor/BodyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use Innmind\Html\{
Visitor,
Reader\Reader,
Reader,
};
use Innmind\Xml\{
Element,
Expand Down
2 changes: 1 addition & 1 deletion tests/Visitor/ElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use Innmind\Html\{
Visitor\Element as ElementFinder,
Reader\Reader,
Reader,
};
use Innmind\Xml\{
Element,
Expand Down
2 changes: 1 addition & 1 deletion tests/Visitor/ElementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use Innmind\Html\{
Visitor\Elements,
Reader\Reader,
Reader,
};
use Innmind\Xml\{
Element,
Expand Down
2 changes: 1 addition & 1 deletion tests/Visitor/HeadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use Innmind\Html\{
Visitor,
Reader\Reader,
Reader,
};
use Innmind\Xml\{
Element,
Expand Down