Skip to content

Commit c2fa05a

Browse files
committed
Cleaned up code base
Fixed Issue with encoding 227
1 parent a2c5eb1 commit c2fa05a

23 files changed

+3059
-792
lines changed

src/PHPHtmlParser/Content.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ public function char(?int $char = null): string
7575
/**
7676
* Moves the current position forward.
7777
*
78-
*
79-
*
8078
* @throws ContentLengthException
8179
*/
8280
public function fastForward(int $count): Content
@@ -100,8 +98,6 @@ public function canFastForward(int $count): bool
10098

10199
/**
102100
* Moves the current position backward.
103-
*
104-
*
105101
*/
106102
public function rewind(int $count): Content
107103
{
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
<?php
2-
3-
namespace PHPHtmlParser\Contracts\Dom;
4-
5-
use PHPHtmlParser\Exceptions\LogicalException;
6-
use PHPHtmlParser\Options;
7-
8-
interface CleanerInterface
9-
{
10-
/**
11-
* Cleans the html of any none-html information.
12-
*
13-
* @throws LogicalException
14-
*/
15-
public function clean(string $str, Options $options): string;
16-
}
1+
<?php
2+
3+
namespace PHPHtmlParser\Contracts\Dom;
4+
5+
use PHPHtmlParser\Exceptions\LogicalException;
6+
use PHPHtmlParser\Options;
7+
8+
interface CleanerInterface
9+
{
10+
/**
11+
* Cleans the html of any none-html information.
12+
*
13+
* @throws LogicalException
14+
*/
15+
public function clean(string $str, Options $options, string $defaultCharset): string;
16+
}
Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
<?php
2-
3-
namespace PHPHtmlParser\Contracts\Dom;
4-
5-
use PHPHtmlParser\Content;
6-
use PHPHtmlParser\Dom\Node\AbstractNode;
7-
use PHPHtmlParser\Exceptions\ChildNotFoundException;
8-
use PHPHtmlParser\Exceptions\CircularException;
9-
use PHPHtmlParser\Exceptions\ContentLengthException;
10-
use PHPHtmlParser\Exceptions\LogicalException;
11-
use PHPHtmlParser\Exceptions\StrictException;
12-
use PHPHtmlParser\Options;
13-
14-
interface ParserInterface
15-
{
16-
/**
17-
* Attempts to parse the html in content.
18-
*
19-
* @throws ChildNotFoundException
20-
* @throws CircularException
21-
* @throws ContentLengthException
22-
* @throws LogicalException
23-
* @throws StrictException
24-
*/
25-
public function parse(Options $options, Content $content, int $size): AbstractNode;
26-
27-
/**
28-
* Attempts to detect the charset that the html was sent in.
29-
*
30-
* @throws ChildNotFoundException
31-
*/
32-
public function detectCharset(Options $options, string $defaultCharset, AbstractNode $root): bool;
33-
}
1+
<?php
2+
3+
namespace PHPHtmlParser\Contracts\Dom;
4+
5+
use PHPHtmlParser\Content;
6+
use PHPHtmlParser\Dom\Node\AbstractNode;
7+
use PHPHtmlParser\Exceptions\ChildNotFoundException;
8+
use PHPHtmlParser\Exceptions\CircularException;
9+
use PHPHtmlParser\Exceptions\ContentLengthException;
10+
use PHPHtmlParser\Exceptions\LogicalException;
11+
use PHPHtmlParser\Exceptions\StrictException;
12+
use PHPHtmlParser\Options;
13+
14+
interface ParserInterface
15+
{
16+
/**
17+
* Attempts to parse the html in content.
18+
*
19+
* @throws ChildNotFoundException
20+
* @throws CircularException
21+
* @throws ContentLengthException
22+
* @throws LogicalException
23+
* @throws StrictException
24+
*/
25+
public function parse(Options $options, Content $content, int $size): AbstractNode;
26+
27+
/**
28+
* Attempts to detect the charset that the html was sent in.
29+
*
30+
* @throws ChildNotFoundException
31+
*/
32+
public function detectCharset(Options $options, string $defaultCharset, AbstractNode $root): bool;
33+
}
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
<?php
2-
3-
declare(strict_types=1);
4-
5-
namespace PHPHtmlParser\Contracts;
6-
7-
use PHPHtmlParser\Dom;
8-
use PHPHtmlParser\Options;
9-
use Psr\Http\Client\ClientInterface;
10-
use Psr\Http\Message\RequestInterface;
11-
12-
interface DomInterface
13-
{
14-
public function loadFromFile(string $file, ?Options $options = null): Dom;
15-
16-
public function loadFromUrl(string $url, ?Options $options, ?ClientInterface $client = null, ?RequestInterface $request = null): Dom;
17-
18-
public function loadStr(string $str, ?Options $options = null): Dom;
19-
20-
public function setOptions(Options $options): Dom;
21-
22-
public function find(string $selector, int $nth = null);
23-
}
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PHPHtmlParser\Contracts;
6+
7+
use PHPHtmlParser\Dom;
8+
use PHPHtmlParser\Options;
9+
use Psr\Http\Client\ClientInterface;
10+
use Psr\Http\Message\RequestInterface;
11+
12+
interface DomInterface
13+
{
14+
public function loadFromFile(string $file, ?Options $options = null): Dom;
15+
16+
public function loadFromUrl(string $url, ?Options $options, ?ClientInterface $client = null, ?RequestInterface $request = null): Dom;
17+
18+
public function loadStr(string $str, ?Options $options = null): Dom;
19+
20+
public function setOptions(Options $options): Dom;
21+
22+
public function find(string $selector, int $nth = null);
23+
}

src/PHPHtmlParser/DTO/TagDTO.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,11 @@ public function __construct(array $values = [])
3636
$this->tag = $values['tag'] ?? null;
3737
}
3838

39-
/**
40-
* @return bool
41-
*/
4239
public function isStatus(): bool
4340
{
4441
return $this->status;
4542
}
4643

47-
/**
48-
* @return bool
49-
*/
5044
public function isClosing(): bool
5145
{
5246
return $this->closing;

src/PHPHtmlParser/Dom.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function loadFromFile(string $file, ?Options $options = null): Dom
117117
* @throws StrictException
118118
* @throws ClientExceptionInterface
119119
*/
120-
public function loadFromUrl(string $url, ?Options $options, ?ClientInterface $client = null, ?RequestInterface $request = null): Dom
120+
public function loadFromUrl(string $url, ?Options $options = null, ?ClientInterface $client = null, ?RequestInterface $request = null): Dom
121121
{
122122
if ($client === null) {
123123
$client = new Client();
@@ -152,20 +152,18 @@ public function loadStr(string $str, ?Options $options = null): Dom
152152
$localOptions = $localOptions->setFromOptions($options);
153153
}
154154

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

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

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

162162
return $this;
163163
}
164164

165165
/**
166166
* Sets a global options array to be used by all load calls.
167-
*
168-
*
169167
*/
170168
public function setOptions(Options $options): Dom
171169
{
@@ -177,10 +175,10 @@ public function setOptions(Options $options): Dom
177175
/**
178176
* Find elements by css selector on the root node.
179177
*
180-
* @return mixed|Collection|null
181178
* @throws NotLoadedException
182-
*
183179
* @throws ChildNotFoundException
180+
*
181+
* @return mixed|Collection|null
184182
*/
185183
public function find(string $selector, int $nth = null)
186184
{
@@ -195,10 +193,10 @@ public function find(string $selector, int $nth = null)
195193
*
196194
* @param $id
197195
*
198-
* @return mixed|Collection|null
199196
* @throws NotLoadedException
200-
*
201197
* @throws ChildNotFoundException
198+
*
199+
* @return mixed|Collection|null
202200
*/
203201
public function getElementById($id)
204202
{
@@ -211,10 +209,10 @@ public function getElementById($id)
211209
* Simple wrapper function that returns all elements by
212210
* tag name.
213211
*
214-
* @return mixed|Collection|null
215212
* @throws NotLoadedException
216-
*
217213
* @throws ChildNotFoundException
214+
*
215+
* @return mixed|Collection|null
218216
*/
219217
public function getElementsByTag(string $name)
220218
{
@@ -227,10 +225,10 @@ public function getElementsByTag(string $name)
227225
* Simple wrapper function that returns all elements by
228226
* class name.
229227
*
230-
* @return mixed|Collection|null
231228
* @throws NotLoadedException
232-
*
233229
* @throws ChildNotFoundException
230+
*
231+
* @return mixed|Collection|null
234232
*/
235233
public function getElementsByClass(string $class)
236234
{
@@ -250,4 +248,4 @@ private function isLoaded(): void
250248
throw new NotLoadedException('Content is not loaded!');
251249
}
252250
}
253-
}
251+
}

0 commit comments

Comments
 (0)