Skip to content

Commit

Permalink
Cleaned up code base
Browse files Browse the repository at this point in the history
Fixed Issue with encoding 227
  • Loading branch information
paquettg committed Jul 19, 2020
1 parent a2c5eb1 commit c2fa05a
Show file tree
Hide file tree
Showing 23 changed files with 3,059 additions and 792 deletions.
4 changes: 0 additions & 4 deletions src/PHPHtmlParser/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ public function char(?int $char = null): string
/**
* Moves the current position forward.
*
*
*
* @throws ContentLengthException
*/
public function fastForward(int $count): Content
Expand All @@ -100,8 +98,6 @@ public function canFastForward(int $count): bool

/**
* Moves the current position backward.
*
*
*/
public function rewind(int $count): Content
{
Expand Down
32 changes: 16 additions & 16 deletions src/PHPHtmlParser/Contracts/Dom/CleanerInterface.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

namespace PHPHtmlParser\Contracts\Dom;

use PHPHtmlParser\Exceptions\LogicalException;
use PHPHtmlParser\Options;

interface CleanerInterface
{
/**
* Cleans the html of any none-html information.
*
* @throws LogicalException
*/
public function clean(string $str, Options $options): string;
}
<?php

namespace PHPHtmlParser\Contracts\Dom;

use PHPHtmlParser\Exceptions\LogicalException;
use PHPHtmlParser\Options;

interface CleanerInterface
{
/**
* Cleans the html of any none-html information.
*
* @throws LogicalException
*/
public function clean(string $str, Options $options, string $defaultCharset): string;
}
66 changes: 33 additions & 33 deletions src/PHPHtmlParser/Contracts/Dom/ParserInterface.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
<?php

namespace PHPHtmlParser\Contracts\Dom;

use PHPHtmlParser\Content;
use PHPHtmlParser\Dom\Node\AbstractNode;
use PHPHtmlParser\Exceptions\ChildNotFoundException;
use PHPHtmlParser\Exceptions\CircularException;
use PHPHtmlParser\Exceptions\ContentLengthException;
use PHPHtmlParser\Exceptions\LogicalException;
use PHPHtmlParser\Exceptions\StrictException;
use PHPHtmlParser\Options;

interface ParserInterface
{
/**
* Attempts to parse the html in content.
*
* @throws ChildNotFoundException
* @throws CircularException
* @throws ContentLengthException
* @throws LogicalException
* @throws StrictException
*/
public function parse(Options $options, Content $content, int $size): AbstractNode;

/**
* Attempts to detect the charset that the html was sent in.
*
* @throws ChildNotFoundException
*/
public function detectCharset(Options $options, string $defaultCharset, AbstractNode $root): bool;
}
<?php

namespace PHPHtmlParser\Contracts\Dom;

use PHPHtmlParser\Content;
use PHPHtmlParser\Dom\Node\AbstractNode;
use PHPHtmlParser\Exceptions\ChildNotFoundException;
use PHPHtmlParser\Exceptions\CircularException;
use PHPHtmlParser\Exceptions\ContentLengthException;
use PHPHtmlParser\Exceptions\LogicalException;
use PHPHtmlParser\Exceptions\StrictException;
use PHPHtmlParser\Options;

interface ParserInterface
{
/**
* Attempts to parse the html in content.
*
* @throws ChildNotFoundException
* @throws CircularException
* @throws ContentLengthException
* @throws LogicalException
* @throws StrictException
*/
public function parse(Options $options, Content $content, int $size): AbstractNode;

/**
* Attempts to detect the charset that the html was sent in.
*
* @throws ChildNotFoundException
*/
public function detectCharset(Options $options, string $defaultCharset, AbstractNode $root): bool;
}
46 changes: 23 additions & 23 deletions src/PHPHtmlParser/Contracts/DomInterface.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?php

declare(strict_types=1);

namespace PHPHtmlParser\Contracts;

use PHPHtmlParser\Dom;
use PHPHtmlParser\Options;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;

interface DomInterface
{
public function loadFromFile(string $file, ?Options $options = null): Dom;

public function loadFromUrl(string $url, ?Options $options, ?ClientInterface $client = null, ?RequestInterface $request = null): Dom;

public function loadStr(string $str, ?Options $options = null): Dom;

public function setOptions(Options $options): Dom;

public function find(string $selector, int $nth = null);
}
<?php

declare(strict_types=1);

namespace PHPHtmlParser\Contracts;

use PHPHtmlParser\Dom;
use PHPHtmlParser\Options;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;

interface DomInterface
{
public function loadFromFile(string $file, ?Options $options = null): Dom;

public function loadFromUrl(string $url, ?Options $options, ?ClientInterface $client = null, ?RequestInterface $request = null): Dom;

public function loadStr(string $str, ?Options $options = null): Dom;

public function setOptions(Options $options): Dom;

public function find(string $selector, int $nth = null);
}
6 changes: 0 additions & 6 deletions src/PHPHtmlParser/DTO/TagDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,11 @@ public function __construct(array $values = [])
$this->tag = $values['tag'] ?? null;
}

/**
* @return bool
*/
public function isStatus(): bool
{
return $this->status;
}

/**
* @return bool
*/
public function isClosing(): bool
{
return $this->closing;
Expand Down
26 changes: 12 additions & 14 deletions src/PHPHtmlParser/Dom.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function loadFromFile(string $file, ?Options $options = null): Dom
* @throws StrictException
* @throws ClientExceptionInterface
*/
public function loadFromUrl(string $url, ?Options $options, ?ClientInterface $client = null, ?RequestInterface $request = null): Dom
public function loadFromUrl(string $url, ?Options $options = null, ?ClientInterface $client = null, ?RequestInterface $request = null): Dom
{
if ($client === null) {
$client = new Client();
Expand Down Expand Up @@ -152,20 +152,18 @@ public function loadStr(string $str, ?Options $options = null): Dom
$localOptions = $localOptions->setFromOptions($options);
}

$html = $this->domCleaner->clean($str, $localOptions);
$html = $this->domCleaner->clean($str, $localOptions, $this->defaultCharset);

$this->content = new Content($html);

$this->root = $this->domParser->parse($localOptions, $this->content, strlen($str));
$this->root = $this->domParser->parse($localOptions, $this->content, \strlen($str));
$this->domParser->detectCharset($localOptions, $this->defaultCharset, $this->root);

return $this;
}

/**
* Sets a global options array to be used by all load calls.
*
*
*/
public function setOptions(Options $options): Dom
{
Expand All @@ -177,10 +175,10 @@ public function setOptions(Options $options): Dom
/**
* Find elements by css selector on the root node.
*
* @return mixed|Collection|null
* @throws NotLoadedException
*
* @throws ChildNotFoundException
*
* @return mixed|Collection|null
*/
public function find(string $selector, int $nth = null)
{
Expand All @@ -195,10 +193,10 @@ public function find(string $selector, int $nth = null)
*
* @param $id
*
* @return mixed|Collection|null
* @throws NotLoadedException
*
* @throws ChildNotFoundException
*
* @return mixed|Collection|null
*/
public function getElementById($id)
{
Expand All @@ -211,10 +209,10 @@ public function getElementById($id)
* Simple wrapper function that returns all elements by
* tag name.
*
* @return mixed|Collection|null
* @throws NotLoadedException
*
* @throws ChildNotFoundException
*
* @return mixed|Collection|null
*/
public function getElementsByTag(string $name)
{
Expand All @@ -227,10 +225,10 @@ public function getElementsByTag(string $name)
* Simple wrapper function that returns all elements by
* class name.
*
* @return mixed|Collection|null
* @throws NotLoadedException
*
* @throws ChildNotFoundException
*
* @return mixed|Collection|null
*/
public function getElementsByClass(string $class)
{
Expand All @@ -250,4 +248,4 @@ private function isLoaded(): void
throw new NotLoadedException('Content is not loaded!');
}
}
}
}
Loading

0 comments on commit c2fa05a

Please sign in to comment.