Skip to content

Commit 6678895

Browse files
umherirrenderKrinkle
authored andcommitted
build: Use PHP8 functions str_contains, str_starts_with and str_ends_with
For readability of the conditions Change-Id: Ie14da92125a4288d22c093e6f2311402f8541615
1 parent 1f3f99c commit 6678895

File tree

7 files changed

+11
-11
lines changed

7 files changed

+11
-11
lines changed

lib/Less/Autoloader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static function unregister() {
4343
*/
4444
public static function loadClass( $className ) {
4545
// handle only package classes
46-
if ( strpos( $className, 'Less_' ) !== 0 ) {
46+
if ( !str_starts_with( $className, 'Less_' ) ) {
4747
return;
4848
}
4949

lib/Less/Cache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public static function Cache( &$less_files, $parser_options = [] ) {
147147
foreach ( $less_files as $file_path => $uri_or_less ) {
148148

149149
// treat as less markup if there are newline characters
150-
if ( strpos( $uri_or_less, "\n" ) !== false ) {
150+
if ( str_contains( $uri_or_less, "\n" ) ) {
151151
$parser->Parse( $uri_or_less );
152152
continue;
153153
}
@@ -236,7 +236,7 @@ public static function CleanCache( $dir = null ) {
236236
foreach ( $files as $file ) {
237237

238238
// don't delete if the file wasn't created with less.php
239-
if ( strpos( $file, self::$prefix ) !== 0 ) {
239+
if ( !str_starts_with( $file, self::$prefix ) ) {
240240
continue;
241241
}
242242

lib/Less/Parser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,7 +2495,7 @@ private function parseDeclaration() {
24952495
// Custom property values get permissive parsing
24962496
if ( is_array( $name ) && array_key_exists( 0, $name ) // to satisfy phan
24972497
&& $name[0] instanceof Less_Tree_Keyword
2498-
&& $name[0]->value && strpos( $name[0]->value, '--' ) === 0 ) {
2498+
&& $name[0]->value && str_starts_with( $name[0]->value, '--' ) ) {
24992499
$value = $this->parsePermissiveValue( [ ';', '}' ] );
25002500
} else {
25012501
// Try to store values as anonymous
@@ -3354,7 +3354,7 @@ public static function serializeVars( $vars ) {
33543354
if ( strval( $value ) === "" ) {
33553355
$value = '~""';
33563356
}
3357-
$s .= ( ( $name[0] === '@' ) ? '' : '@' ) . $name . ': ' . $value . ( ( substr( $value, -1 ) === ';' ) ? '' : ';' );
3357+
$s .= ( str_starts_with( $name, '@' ) ? '' : '@' ) . $name . ': ' . $value . ( str_ends_with( $value, ';' ) ? '' : ';' );
33583358
}
33593359

33603360
return $s;
@@ -3389,7 +3389,7 @@ public static function WinPath( $path ) {
33893389
}
33903390

33913391
public static function AbsPath( $path, $winPath = false ) {
3392-
if ( strpos( $path, '//' ) !== false && preg_match( '/^(https?:)?\/\//i', $path ) ) {
3392+
if ( str_contains( $path, '//' ) && preg_match( '/^(https?:)?\/\//i', $path ) ) {
33933393
return $winPath ? '' : false;
33943394
} else {
33953395
$path = realpath( $path );

lib/Less/SourceMap/Generator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ protected function normalizeFilename( $filename ) {
178178
$basePath = $this->getOption( 'sourceMapBasepath' );
179179

180180
// "Trim" the 'sourceMapBasepath' from the output filename.
181-
if ( is_string( $basePath ) && strpos( $filename, $basePath ) === 0 ) {
181+
if ( is_string( $basePath ) && str_starts_with( $filename, $basePath ) ) {
182182
$filename = substr( $filename, strlen( $basePath ) );
183183
}
184184

185185
// Remove extra leading path separators.
186-
if ( strpos( $filename, '\\' ) === 0 || strpos( $filename, '/' ) === 0 ) {
186+
if ( str_starts_with( $filename, '\\' ) || str_starts_with( $filename, '/' ) ) {
187187
$filename = substr( $filename, 1 );
188188
}
189189

lib/Less/Tree/Call.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function compile( $env ) {
147147

148148
// Check if 'error evaluating function' is the start of the error message
149149
// less.js does this by checking if line and column already set
150-
if ( strpos( $e->getMessage(), 'error evaluating function' ) === 0 ) {
150+
if ( str_starts_with( $e->getMessage(), 'error evaluating function' ) ) {
151151
throw $e;
152152
}
153153

lib/Less/Tree/Url.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function compile( $env ) {
6161
// Add cache buster if enabled
6262
if ( Less_Parser::$options['urlArgs'] ) {
6363
if ( !preg_match( '/^\s*data:/', $val->value ) ) {
64-
$delimiter = strpos( $val->value, '?' ) === false ? '?' : '&';
64+
$delimiter = !str_contains( $val->value, '?' ) ? '?' : '&';
6565
$urlArgs = $delimiter . Less_Parser::$options['urlArgs'];
6666
$hash_pos = strpos( $val->value, '#' );
6767
if ( $hash_pos !== false ) {

test/compare.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function cli( $args ) {
5151
foreach ( $args as $arg ) {
5252
if ( $arg === '--override' ) {
5353
$useOverride = true;
54-
} elseif ( strpos( $arg, '--' ) === 0 ) {
54+
} elseif ( str_starts_with( $arg, '--' ) ) {
5555
$this->error( "Invalid option $arg" );
5656
} elseif ( $fixtureDir === null ) {
5757
// First non-option argument

0 commit comments

Comments
 (0)