Skip to content

Commit 376785f

Browse files
committed
CS fix
1 parent 9db0c1c commit 376785f

File tree

5 files changed

+42
-24
lines changed

5 files changed

+42
-24
lines changed

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"require":{
1515
"php":">=5.4",
1616
"ext-dom": "*",
17+
"ext-libxml": "*",
18+
"ext-simplexml": "*",
1719
"symfony/css-selector": "*"
1820
},
1921
"require-dev": {

lib/Document.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ public function __construct($element = null)
5858
$this->document = new DOMDocument('1.0', 'UTF-8');
5959

6060
if ($element instanceof Element) {
61-
$element = $element->getNode();
61+
$node = $element->getNode();
6262

63-
$domNode = $this->document->importNode($element, true);
63+
$domNode = $this->document->importNode($node, true);
6464
$this->document->appendChild($domNode);
6565

6666
return;
@@ -108,6 +108,9 @@ public function loadHtml($html)
108108
* @param string $filePath
109109
*
110110
* @return Document
111+
*
112+
* @throws InvalidArgumentException
113+
* @throws RuntimeException
111114
*/
112115
public function loadHtmlFile($filePath)
113116
{
@@ -162,15 +165,15 @@ public function find($selector, $idx = null)
162165
$elements[] = new Element($node);
163166
}
164167

165-
if (is_null($idx)) {
168+
if (null === $idx) {
166169
return $elements;
167-
} else {
168-
if ($idx < 0) {
169-
$idx = count($elements) + $idx;
170-
}
171170
}
172171

173-
return (isset($elements[$idx])) ? $elements[$idx] : null;
172+
if ($idx < 0) {
173+
$idx = count($elements) + $idx;
174+
}
175+
176+
return isset($elements[$idx]) ? $elements[$idx] : null;
174177
}
175178

176179
/**
@@ -181,7 +184,7 @@ public function find($selector, $idx = null)
181184
public function html()
182185
{
183186
if ($this::$callback !== null) {
184-
call_user_func_array($this::$callback, [$this]);
187+
call_user_func($this::$callback, $this);
185188
}
186189

187190
return trim($this->document->saveHTML($this->document->documentElement));
@@ -284,6 +287,8 @@ public function __invoke($selector, $idx = null)
284287
* @param $arguments
285288
*
286289
* @return bool|mixed
290+
*
291+
* @throws BadMethodCallException
287292
*/
288293
public function __call($name, $arguments)
289294
{
@@ -298,16 +303,18 @@ public function __call($name, $arguments)
298303
* @param $arguments
299304
*
300305
* @return bool|Document
306+
*
307+
* @throws BadMethodCallException
301308
*/
302309
public static function __callStatic($name, $arguments)
303310
{
304-
if ($name == 'str_get_html') {
311+
if ($name === 'str_get_html') {
305312
$document = new Document();
306313

307314
return $document->loadHtml($arguments[0]);
308315
}
309316

310-
if ($name == 'file_get_html') {
317+
if ($name === 'file_get_html') {
311318
$document = new Document();
312319

313320
return $document->loadHtmlFile($arguments[0]);

lib/Element.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
/**
1212
* Class Element
13+
*
1314
* @package FastSimpleHTMLDom
1415
* @property string outertext Get dom node's outer html
1516
* @property string innertext Get dom node's inner html
@@ -80,8 +81,8 @@ protected function replaceNode($string)
8081

8182
$newDocument = new Document($string);
8283

83-
if ($newDocument->outertext != $string) {
84-
throw new RuntimeException("Not valid HTML fragment");
84+
if ($newDocument->outertext !== $string) {
85+
throw new RuntimeException('Not valid HTML fragment');
8586
}
8687

8788
$newNode = $this->node->ownerDocument->importNode($newDocument->getDocument()->documentElement, true);
@@ -106,8 +107,8 @@ protected function replaceChild($string)
106107
if (!empty($string)) {
107108
$newDocument = new Document($string);
108109

109-
if ($newDocument->outertext != $string) {
110-
throw new RuntimeException("Not valid HTML fragment");
110+
if ($newDocument->outertext !== $string) {
111+
throw new RuntimeException('Not valid HTML fragment');
111112
}
112113
}
113114

@@ -160,7 +161,7 @@ public function getDom()
160161
* Find list of nodes with a CSS selector
161162
*
162163
* @param string $selector
163-
* @param int $idx
164+
* @param int $idx
164165
*
165166
* @return NodeList|Element|null
166167
*/
@@ -477,7 +478,7 @@ public function __toString()
477478

478479
/**
479480
* @param string $selector
480-
* @param int $idx
481+
* @param int $idx
481482
*
482483
* @return Element|NodeList|null
483484
*/
@@ -504,6 +505,7 @@ public function __call($name, $arguments)
504505

505506
/**
506507
* Retrieve an external iterator
508+
*
507509
* @link http://php.net/manual/en/iteratoraggregate.getiterator.php
508510
* @return NodeList An instance of an object implementing <b>Iterator</b> or
509511
* <b>Traversable</b>

lib/NodeList.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ class NodeList extends \ArrayObject
2121
*/
2222
public function find($selector, $idx = null)
2323
{
24-
$elements = new NodeList();
24+
$elements = new self();
2525
foreach ($this as $node) {
2626
foreach ($node->find($selector) as $res) {
2727
$elements->append($res);
2828
}
2929
}
30-
if (is_null($idx)) {
30+
if (null === $idx) {
3131
return $elements;
32-
} else {
33-
if ($idx < 0) {
34-
$idx = count($elements) + $idx;
35-
}
3632
}
3733

38-
return (isset($elements[$idx])) ? $elements[$idx] : null;
34+
if ($idx < 0) {
35+
$idx = count($elements) + $idx;
36+
}
37+
38+
return isset($elements[$idx]) ? $elements[$idx] : null;
3939
}
4040

4141
/**

lib/SelectorConverter.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44

55

66
use Symfony\Component\CssSelector\CssSelectorConverter;
7+
78
class SelectorConverter
89
{
910
protected static $compiled = [];
1011

12+
/**
13+
* @param $selector
14+
*
15+
* @return mixed|string
16+
* @throws \RuntimeException
17+
*/
1118
public static function toXPath($selector)
1219
{
1320
if (isset(self::$compiled[$selector])){

0 commit comments

Comments
 (0)