Skip to content

Commit acfda1c

Browse files
committed
Updated tag.php to use str_contains() instead of mb_strpos() where possible.
Fixed some return value issues in `htmldoc`.
1 parent 2b1abd4 commit acfda1c

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@master
10+
- uses: actions/checkout@v3
1111

1212
- name: Cache Composer dependencies
1313
uses: actions/cache@v3

src/htmldoc.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public function __get(string $var) : mixed {
7575
} else {
7676
return $this->children[0]->{$var};
7777
}
78-
return null;
7978
}
8079

8180
/**
@@ -518,7 +517,7 @@ public function text() : string {
518517
* Adds the specified nodes to the htmldoc object
519518
*
520519
* @param array $nodes An array of nodes to add to the collection
521-
* @return void
520+
* @return htmldoc The current instance of this object
522521
*/
523522
protected function collection(array $nodes) : htmldoc {
524523

src/tokens/tag.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ public function minify(array $minify) : void {
479479
}
480480

481481
// use parent folders if it is shorter
482-
if ($minify['urls']['parent'] && $dirs && \mb_strpos($attributes[$key], '/') === 0 && \mb_strpos($attributes[$key], '//') === false) {
482+
if ($minify['urls']['parent'] && $dirs && \mb_strpos($attributes[$key], '/') === 0 && !\str_contains($attributes[$key], '//')) {
483483
$isDir = \mb_strrpos($attributes[$key], '/') === \mb_strlen($attributes[$key])-1;
484484
$compare = \explode('/', \trim($isDir ? $attributes[$key] : \dirname($attributes[$key]), '/'));
485485
$update = false;
@@ -531,7 +531,7 @@ public function minify(array $minify) : void {
531531
), '; ');
532532

533533
// trim classes
534-
} elseif ($key === 'class' && $min['class'] && \mb_strpos($attributes[$key] ?? '', ' ') !== false) {
534+
} elseif ($key === 'class' && $min['class'] && \str_contains($attributes[$key] ?? '', ' ')) {
535535
$attributes[$key] = \trim(\preg_replace('/\s+/', ' ', $attributes[$key]));
536536

537537
// minify option tag, always capture the tag to prevent it being removed as a default
@@ -879,7 +879,7 @@ public function html(array $options = []) : string {
879879
$html .= '='.$value;
880880

881881
// single quotes || swap when minimal and there are double quotes in the string
882-
} elseif ($options['quotestyle'] === 'single' || ($options['quotestyle'] === 'minimal' && \mb_strpos($value, '"') !== false)) {
882+
} elseif ($options['quotestyle'] === 'single' || ($options['quotestyle'] === 'minimal' && \str_contains($value, '"'))) {
883883
$html .= "='".\str_replace(['&', "'", '<'], ['&amp;', '&#39;', '&lt;'], $value)."'";
884884

885885
// double quotes

0 commit comments

Comments
 (0)