Skip to content

Commit cf530de

Browse files
authored
Use str_starts_with function for modules and plugins (joomla#44936)
1 parent 80f5b09 commit cf530de

File tree

11 files changed

+19
-19
lines changed

11 files changed

+19
-19
lines changed

administrator/modules/mod_menu/src/Menu/CssMenu.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ protected function preprocess($parent)
293293
continue;
294294
}
295295

296-
if (!empty($item->link) && substr($item->link, 0, 8) === 'special:') {
296+
if (!empty($item->link) && str_starts_with($item->link, 'special:')) {
297297
$special = substr($item->link, 8);
298298

299299
if ($special === 'language-forum') {
@@ -498,7 +498,7 @@ public function getIconClass($node)
498498
}
499499

500500
// We were passed a class name
501-
if (substr($identifier, 0, 6) == 'class:') {
501+
if (str_starts_with($identifier, 'class:')) {
502502
$class = substr($identifier, 6);
503503
} else {
504504
// We were passed background icon url. Build the CSS class for the icon

administrator/modules/mod_submenu/src/Menu/Menu.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static function preprocess($parent)
6161
]))->getArgument('subject', $children);
6262

6363
foreach ($children as $item) {
64-
if (substr($item->link, 0, 8) === 'special:') {
64+
if (str_starts_with($item->link, 'special:')) {
6565
$special = substr($item->link, 8);
6666

6767
if ($special === 'language-forum') {
@@ -203,10 +203,10 @@ public static function preprocess($parent)
203203
$iconImage = $item->icon;
204204

205205
if ($iconImage) {
206-
if (substr($iconImage, 0, 6) === 'class:' && substr($iconImage, 6) === 'icon-home') {
206+
if (str_starts_with($iconImage, 'class:') && substr($iconImage, 6) === 'icon-home') {
207207
$iconImage = '<span class="home-image icon-home" aria-hidden="true"></span>';
208208
$iconImage .= '<span class="visually-hidden">' . Text::_('JDEFAULT') . '</span>';
209-
} elseif (substr($iconImage, 0, 6) === 'image:') {
209+
} elseif (str_starts_with($iconImage, 'image:')) {
210210
$iconImage = '&nbsp;<span class="badge bg-secondary">' . substr($iconImage, 6) . '</span>';
211211
}
212212

modules/mod_menu/src/Helper/MenuHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static function getList(&$params)
125125
break;
126126

127127
case 'url':
128-
if ((strpos($item->link, 'index.php?') === 0) && (strpos($item->link, 'Itemid=') === false)) {
128+
if ((str_starts_with($item->link, 'index.php?')) && (strpos($item->link, 'Itemid=') === false)) {
129129
// If this is an internal Joomla link, ensure the Itemid is set.
130130
$item->flink = $item->link . '&Itemid=' . $item->id;
131131
}

modules/mod_wrapper/src/Helper/WrapperHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function getParamsWrapper(Registry $params, SiteApplication $app)
4949

5050
if ($params->get('add')) {
5151
// Adds 'http://' if none is set
52-
if (strpos($url, '/') === 0) {
52+
if (str_starts_with($url, '/')) {
5353
// Relative URL in component. use server http_host.
5454
$url = 'http://' . $app->getInput()->server->get('HTTP_HOST') . $url;
5555
} elseif (strpos($url, 'http') === false && strpos($url, 'https') === false) {

plugins/api-authentication/token/src/Extension/Token.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function onUserAuthenticate(AuthenticationEvent $event): void
131131
$authHeader = $this->getApplication()->getInput()->server->get('REDIRECT_HTTP_AUTHORIZATION', '', 'string');
132132
}
133133

134-
if (substr($authHeader, 0, 7) == 'Bearer ') {
134+
if (str_starts_with($authHeader, 'Bearer ')) {
135135
$parts = explode(' ', $authHeader, 2);
136136
$tokenString = trim($parts[1]);
137137
$tokenString = $this->filter->clean($tokenString, 'BASE64');

plugins/editors/tinymce/src/PluginTraits/DisplayTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function display(string $name, string $content = '', array $attributes =
164164

165165
// if we have a name and path, add it to the list
166166
if ($external['name'] != '' && $path != '') {
167-
$externalPlugins[$external['name']] = substr($path, 0, 1) == '/' ? Uri::root() . substr($path, 1) : $path;
167+
$externalPlugins[$external['name']] = str_starts_with($path, '/') ? Uri::root() . substr($path, 1) : $path;
168168
}
169169
}
170170
}

plugins/system/debug/src/Extension/Debug.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ public function onAfterRespond(AfterRespondEvent|ApplicationEvent $event): void
365365

366366
// No debug for Safari and Chrome redirection.
367367
if (
368-
strpos($contents, '<html><head><meta http-equiv="refresh" content="0;') === 0
368+
str_starts_with($contents, '<html><head><meta http-equiv="refresh" content="0;')
369369
&& strpos(strtolower($_SERVER['HTTP_USER_AGENT'] ?? ''), 'webkit') !== false
370370
) {
371371
$this->debugBar->stackData();
@@ -619,7 +619,7 @@ private function collectLogs()
619619
$category = $entry->category;
620620
$relative = $file ? str_replace(JPATH_ROOT, '', $file) : '';
621621

622-
if ($relative && 0 === strpos($relative, '/libraries/src')) {
622+
if ($relative && str_starts_with($relative, '/libraries/src')) {
623623
if (!$logDeprecatedCore) {
624624
break;
625625
}

plugins/system/fields/src/Extension/Fields.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function onContentPrepareForm(Model\PrepareFormEvent $event)
288288
$context = $form->getName();
289289

290290
// When a category is edited, the context is com_categories.categorycom_content
291-
if (strpos($context, 'com_categories.category') === 0) {
291+
if (str_starts_with($context, 'com_categories.category')) {
292292
$context = str_replace('com_categories.category', '', $context) . '.categories';
293293
$data = $data ?: $this->getApplication()->getInput()->get('jform', [], 'array');
294294

plugins/system/httpheaders/src/Extension/Httpheaders.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,12 @@ private function setCspHeader(): void
310310
}
311311

312312
// Append the script hashes placeholder
313-
if ($scriptHashesEnabled && strpos($cspValue->directive, 'script-src') === 0) {
313+
if ($scriptHashesEnabled && str_starts_with($cspValue->directive, 'script-src')) {
314314
$cspValue->value = '{script-hashes} ' . $cspValue->value;
315315
}
316316

317317
// Append the style hashes placeholder
318-
if ($styleHashesEnabled && strpos($cspValue->directive, 'style-src') === 0) {
318+
if ($styleHashesEnabled && str_starts_with($cspValue->directive, 'style-src')) {
319319
$cspValue->value = '{style-hashes} ' . $cspValue->value;
320320
}
321321

plugins/system/privacyconsent/src/Extension/PrivacyConsent.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,10 @@ public function onAfterRoute(AfterRouteEvent $event): void
301301
'method', 'methods', 'captive', 'callback',
302302
];
303303
$isAllowedUserTask = \in_array($task, $allowedUserTasks)
304-
|| substr($task, 0, 8) === 'captive.'
305-
|| substr($task, 0, 8) === 'methods.'
306-
|| substr($task, 0, 7) === 'method.'
307-
|| substr($task, 0, 9) === 'callback.';
304+
|| str_starts_with($task, 'captive.')
305+
|| str_starts_with($task, 'methods.')
306+
|| str_starts_with($task, 'method.')
307+
|| str_starts_with($task, 'callback.');
308308

309309
if (
310310
($option == 'com_users' && $isAllowedUserTask)

0 commit comments

Comments
 (0)