Skip to content

Commit 874787b

Browse files
committed
String comparisons are now strict where possible.
1 parent 6505b9c commit 874787b

File tree

6 files changed

+24
-36
lines changed

6 files changed

+24
-36
lines changed

composer.lock

Lines changed: 12 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/htmldoc.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ protected function parseSelector(string $selector) {
291291
$join = null;
292292
do {
293293
switch ($token['type']) {
294-
295294
case 'id':
296295
$parts[] = [
297296
'id' => mb_substr($token['value'], 1),
@@ -319,14 +318,14 @@ protected function parseSelector(string $selector) {
319318
case 'squareopen':
320319
$item = ['join' => $join];
321320
while (($token = $tokens->next()) !== false) {
322-
if ($token['type'] == 'squareclose') {
321+
if ($token['type'] === 'squareclose') {
323322
break;
324323
} elseif (in_array($token['type'], ['string', 'quotes'])) {
325324
if ($token['type'] == 'quotes') {
326325
$token['value'] = stripslashes(mb_substr($token['value'], 1, -1));
327326
}
328327
$item[isset($item['attribute']) ? 'value' : 'attribute'] = $token['value'];
329-
} elseif ($token['type'] == 'comparison') {
328+
} elseif ($token['type'] === 'comparison') {
330329
$item['comparison'] = $token['value'];
331330
}
332331
}
@@ -401,7 +400,7 @@ public function get(int $index = null) {
401400
// build children that are tags
402401
$children = [];
403402
foreach ($this->children AS $item) {
404-
if (get_class($item) == 'hexydec\\html\\tag') {
403+
if (get_class($item) === 'hexydec\\html\\tag') {
405404
$children[] = $item;
406405
}
407406
}
@@ -435,7 +434,7 @@ public function find(string $selector) : htmldoc {
435434
// parse selector and find tags
436435
if (is_array($selector) || ($selector = $this->parseSelector($selector)) !== false) {
437436
foreach ($this->children AS $item) {
438-
if (get_class($item) == 'hexydec\\html\\tag') {
437+
if (get_class($item) === 'hexydec\\html\\tag') {
439438
foreach ($selector AS $value) {
440439
if (($items = $item->find($value)) !== false) {
441440
$found = array_merge($found, $items);
@@ -505,7 +504,7 @@ public function children() : htmldoc {
505504
*/
506505
public function attr(string $key) : ?string {
507506
foreach ($this->children AS $item) {
508-
if (get_class($item) == 'hexydec\\html\\tag') {
507+
if (get_class($item) === 'hexydec\\html\\tag') {
509508
return $item->attr($key);
510509
}
511510
}
@@ -522,7 +521,7 @@ public function text() : string {
522521
foreach ($this->children AS $item) {
523522

524523
// only get text from these objects
525-
if (in_array(get_class($item), ['hexydec\\html\\tag', 'hexydec\\html\\text'])) {
524+
if (in_array(get_class($item), ['hexydec\\html\\tag', 'hexydec\\html\\text'], true)) {
526525
$value = $item->text();
527526
$text = array_merge($text, is_array($value) ? $value : [$value]);
528527
}
@@ -635,7 +634,7 @@ public function save(string $file = null, array $options = []) {
635634
if (!empty($options['charset'])) {
636635

637636
// if not UTF-8, convert all applicable HTML entities
638-
if ($options['charset'] != 'UTF-8') {
637+
if ($options['charset'] !== 'UTF-8') {
639638
$html = $this->htmlentities($html, $options['charset']);
640639
}
641640

src/tokens/comment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function parse(tokenise $tokens) : void {
3939
* @return void
4040
*/
4141
public function minify(array $minify) : void {
42-
if (!empty($minify['comments']['remove']) && (empty($minify['comments']['ie']) || (mb_strpos($this->content, '[if ') !== 0 && $this->content != '<![endif]'))) {
42+
if (!empty($minify['comments']['remove']) && (empty($minify['comments']['ie']) || (mb_strpos($this->content, '[if ') !== 0 && $this->content !== '<![endif]'))) {
4343
$this->content = null;
4444
}
4545
}

src/tokens/doctype.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public function __construct(htmldoc $root) {
2828
*/
2929
public function parse(tokenise $tokens) : void {
3030
$content = '';
31-
while (($token = $tokens->next()) !== null && $token['type'] != 'tagopenend') {
32-
if ($token['type'] == 'attribute') {
31+
while (($token = $tokens->next()) !== null && $token['type'] !== 'tagopenend') {
32+
if ($token['type'] === 'attribute') {
3333
$content .= ($content ? ' ' : '').ltrim($token['value']);
3434
}
3535
}

src/tokens/style.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,6 @@ public function parse(tokenise $tokens) : void {
3737
$this->content = $token[0];
3838
return;
3939
}
40-
// if (($token = $tokens->current()) !== null) {
41-
// $value = '';
42-
// while ($token !== null && ($token['type'] != 'tagclose' || $token['value'] != '</style>')) {
43-
// if ($token['type'] == 'cdata') {
44-
// $value .= mb_substr($token['value'], 9, -3);
45-
// } else {
46-
// $value .= $token['value'];
47-
// }
48-
// $token = $tokens->next();
49-
// }
50-
// $tokens->prev();
51-
// if ($value) {
52-
// $this->content = $value;
53-
// }
54-
// }
5540
}
5641

5742
/**

src/tokens/tag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function parse(tokenise $tokens) : void {
120120
}
121121

122122
case 'tagselfclose':
123-
if (in_array($tag, $this->config['elements']['singleton'])) {
123+
if (in_array($tag, $this->config['elements']['singleton'], true)) {
124124
$this->singleton = $token['value'];
125125
}
126126
break 2;
@@ -132,7 +132,7 @@ public function parse(tokenise $tokens) : void {
132132
if (in_array($close, $this->getParentTagNames())) {
133133

134134
// when it is not our tag, pass it to the parent to handle
135-
if ($close != $tag) {
135+
if ($close !== $tag) {
136136
$tokens->prev();
137137

138138
// otherwise we are closing ourself

0 commit comments

Comments
 (0)