Skip to content

Commit

Permalink
Run CS Fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
theseer committed Apr 28, 2022
1 parent 5d47ef4 commit 11dd0ed
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DOMElement;
use DOMNode;
use DOMText;
use function assert;

class Html {

Expand Down Expand Up @@ -74,12 +75,14 @@ public function toSnippet(string $id): Snippet {

public function extractAsSnippets(Selector $selector, string $targetId): SnippetList {
$selection = $selector->select($this->dom->documentElement);

if ($selection->isEmpty()) {
throw new TempladoException('Selection result is empty - cannot extract');
}

$list = new SnippetList();
foreach($selection as $item) {

foreach ($selection as $item) {
assert($item instanceof DOMNode);

if ($item instanceof DOMText) {
Expand All @@ -104,7 +107,6 @@ public function extractAsSnippets(Selector $selector, string $targetId): Snippet
return $list;
}


public function asString(Filter $filter = null): string {
$content = $this->serializeDomDocument();
$content = (new EmptyElementsFilter())->apply($content);
Expand Down
3 changes: 1 addition & 2 deletions src/Templado.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public static function parseHtmlString(string $string): Html {
return new Html($dom);
}

private static function formatError(\LibXMLError $error): string
{
private static function formatError(\LibXMLError $error): string {
return \sprintf(
'%s (Line %d, Column %d)',
\trim($error->message),
Expand Down
3 changes: 1 addition & 2 deletions src/formdata/FormDataRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ private function findFormElement(DOMElement $context, string $identifier): DOMEl
if ($context->localName === 'form' &&
($context->getAttribute('id') === $identifier ||
$context->getAttribute('name') === $identifier)) {

return $context;
}

$xp = new DOMXPath($context->ownerDocument);
$xp = new DOMXPath($context->ownerDocument);
$result = $xp->query(
\sprintf('.//*[local-name() = "form" and (@id = "%1$s" or @name = "%1$s")]', $identifier),
$context
Expand Down
3 changes: 3 additions & 0 deletions src/snippet/SnippetRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private function process(DOMElement $context): void {
*/
private function processCurrent(): void {
$nextSibling = $this->currentContext->nextSibling;

if ($this->currentContext->hasAttribute('id')) {
$id = $this->currentContext->getAttribute('id');

Expand All @@ -54,6 +55,7 @@ private function processCurrent(): void {
}

$actualNext = $this->currentContext->nextSibling;

if ($this->currentContext->hasChildNodes()) {
$this->process($this->currentContext);
}
Expand All @@ -67,6 +69,7 @@ private function processCurrent(): void {
$this->process($actualNext);
}
$actualNext = $actualNext->nextSibling;

if ($actualNext === null || $actualNext->isSameNode($nextSibling)) {
return;
}
Expand Down
5 changes: 4 additions & 1 deletion src/snippet/TempladoSnippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ private function replaceNode(DOMElement $node): DOMNode {
foreach ($root->childNodes as $child) {
$imported = $node->ownerDocument->importNode($child, true);
$parent->insertBefore($imported, $node);
if ($first === null && $imported instanceof DOMElement) { $first = $imported; }

if ($first === null && $imported instanceof DOMElement) {
$first = $imported;
}
}
$parent->removeChild($node);

Expand Down
7 changes: 3 additions & 4 deletions tests/HTMLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ public function testSimpleSnippetsCanBeExtracted(): void {
$testDom = new DOMDocument();

$this->assertCount(3, $list);
foreach($list as $snippet) {

foreach ($list as $snippet) {
$this->assertInstanceOf(SimpleSnippet::class, $snippet);
$this->assertSame('some-id', $snippet->getTargetId());

Expand Down Expand Up @@ -292,7 +293,7 @@ public function testTextSnippetsCanBeExtracted(): void {

$this->assertCount(1, $list);

foreach($list as $snippet) {
foreach ($list as $snippet) {
$this->assertInstanceOf(TextSnippet::class, $snippet);
$this->assertSame('some-id', $snippet->getTargetId());

Expand All @@ -317,7 +318,5 @@ public function testTryingToExtractNonElementNodeThrowsException(): void {

$this->expectException(TempladoException::class);
(new Html($dom))->extractAsSnippets($selector, 'some-id');

}

}
1 change: 0 additions & 1 deletion tests/formdata/FormDataRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public function testFormElementFoundOnRootElementById(): void {
$src->documentElement,
$exp->documentElement
);

}

public function testFormElementFoundOnRootElementByName(): void {
Expand Down
1 change: 0 additions & 1 deletion tests/issues/SnippetNestingBug/NestedSnippetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use PHPUnit\Framework\TestCase;

class NestedSnippetTest extends TestCase {

use DomDocumentsEqualTrait;

public function testReplacementWithMultipleSiblingBug(): void {
Expand Down

0 comments on commit 11dd0ed

Please sign in to comment.