Skip to content

Commit 733fb54

Browse files
authored
Use str_starts_with function for libraries code (joomla#44915)
1 parent 28035af commit 733fb54

34 files changed

+48
-48
lines changed

libraries/src/Cache/Storage/ApcuStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function clean($group, $mode = null)
170170
$internalKey = $key['key'];
171171
}
172172

173-
if (strpos($internalKey, $secret . '-cache-' . $group . '-') === 0 xor $mode !== 'group') {
173+
if (str_starts_with($internalKey, $secret . '-cache-' . $group . '-') xor $mode !== 'group') {
174174
apcu_delete($internalKey);
175175
}
176176
}

libraries/src/Cache/Storage/MemcachedStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public function clean($group, $mode = null)
307307
$prefix = $this->_hash . '-cache-' . $group . '-';
308308

309309
foreach ($index as $key => $value) {
310-
if (strpos($value->name, $prefix) === 0 xor $mode !== 'group') {
310+
if (str_starts_with($value->name, $prefix) xor $mode !== 'group') {
311311
static::$_db->delete($value->name);
312312
unset($index[$key]);
313313
}

libraries/src/Cache/Storage/RedisStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,11 @@ public function clean($group, $mode = null)
286286
$secret = $this->_hash;
287287

288288
foreach ($allKeys as $key) {
289-
if (strpos($key, $secret . '-cache-' . $group . '-') === 0 && $mode === 'group') {
289+
if (str_starts_with($key, $secret . '-cache-' . $group . '-') && $mode === 'group') {
290290
static::$_redis->del($key);
291291
}
292292

293-
if (strpos($key, $secret . '-cache-' . $group . '-') !== 0 && $mode !== 'group') {
293+
if (!str_starts_with($key, $secret . '-cache-' . $group . '-') && $mode !== 'group') {
294294
static::$_redis->del($key);
295295
}
296296
}

libraries/src/Event/AbstractEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static function create(string $eventName, array $arguments = [])
8484
* the onTableBeforeLoad event name.
8585
*/
8686
if (!$eventClassName || !class_exists($eventClassName, true)) {
87-
$bareName = strpos($eventName, 'on') === 0 ? substr($eventName, 2) : $eventName;
87+
$bareName = str_starts_with($eventName, 'on') ? substr($eventName, 2) : $eventName;
8888
$parts = Normalise::fromCamelCase($bareName, true);
8989
$eventClassName = __NAMESPACE__ . '\\' . ucfirst(array_shift($parts)) . '\\';
9090
$eventClassName .= implode('', $parts);

libraries/src/Filesystem/Folder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public static function create($path = '', $mode = 0755)
237237
foreach ($obdArray as $test) {
238238
$test = Path::clean($test);
239239

240-
if (strpos($path, $test) === 0 || strpos($path, realpath($test)) === 0) {
240+
if (str_starts_with($path, $test) || str_starts_with($path, realpath($test))) {
241241
$inBaseDir = true;
242242
break;
243243
}

libraries/src/Form/Field/SchemaorgComponentSectionsField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function getOptions()
4646
$options = [];
4747
$options[] = HTMLHelper::_('select.option', ' ', Text::_('JNONE'));
4848
foreach ($items as $item) {
49-
if (substr($item->value, 0, 4) !== 'com_') {
49+
if (!str_starts_with($item->value, 'com_')) {
5050
continue;
5151
}
5252

libraries/src/Form/Field/WorkflowComponentSectionsField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function getOptions()
4848
$options[] = HTMLHelper::_('select.option', ' ', Text::_('JNONE'));
4949

5050
foreach ($items as $item) {
51-
if (substr($item->value, 0, 4) !== 'com_') {
51+
if (!str_starts_with($item->value, 'com_')) {
5252
continue;
5353
}
5454

libraries/src/Form/Filter/TelFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ public function filter(\SimpleXMLElement $element, $value, $group = null, ?Regis
4747
if (preg_match('/^(?:\+?1[-. ]?)?\(?([2-9][0-8][0-9])\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/', $value) == 1) {
4848
$number = (string) preg_replace('/[^\d]/', '', $value);
4949

50-
if (substr($number, 0, 1) === '1') {
50+
if (str_starts_with($number, '1')) {
5151
$number = substr($number, 1);
5252
}
5353

54-
if (substr($number, 0, 2) === '+1') {
54+
if (str_starts_with($number, '+1')) {
5555
$number = substr($number, 2);
5656
}
5757

libraries/src/Form/Filter/UrlFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function filter(\SimpleXMLElement $element, $value, $group = null, ?Regis
6767
$protocol = 'http';
6868

6969
// If it looks like an internal link, then add the root.
70-
if (substr($value, 0, 9) === 'index.php') {
70+
if (str_starts_with($value, 'index.php')) {
7171
$value = Uri::root() . $value;
7272
} else {
7373
// Otherwise we treat it as an external link.
@@ -81,7 +81,7 @@ public function filter(\SimpleXMLElement $element, $value, $group = null, ?Regis
8181
// If it starts with the host string, just prepend the protocol.
8282
if (substr($value, 0) === $host) {
8383
$value = 'http://' . $value;
84-
} elseif (substr($value, 0, 1) !== '/') {
84+
} elseif (!str_starts_with($value, '/')) {
8585
// Otherwise if it doesn't start with "/" prepend the prefix of the current site.
8686
$value = Uri::root(true) . '/' . $value;
8787
}

libraries/src/Form/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ public static function getInstance($name, $data = null, $options = [], $replace
17051705
$forms[$name] = Factory::getContainer()->get(FormFactoryInterface::class)->createForm($name, $options);
17061706

17071707
// Load the data.
1708-
if (substr($data, 0, 1) === '<') {
1708+
if (str_starts_with($data, '<')) {
17091709
if ($forms[$name]->load($data, $replace, $xpath) == false) {
17101710
throw new \RuntimeException(\sprintf('%s() could not load form', __METHOD__));
17111711
}

0 commit comments

Comments
 (0)