Skip to content

Commit ed3c42b

Browse files
authored
Use str_ends_with function for libraries code (joomla#44916)
1 parent 733fb54 commit ed3c42b

File tree

7 files changed

+10
-10
lines changed

7 files changed

+10
-10
lines changed

libraries/src/HTML/Helpers/StringHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public static function truncateComplex($html, $maxLength = 0, $noSplit = true)
196196

197197
// If the plain text is shorter than the max length the variable will not end in ...
198198
// In that case we use the whole string.
199-
if (substr($ptString, -3) !== '...') {
199+
if (!str_ends_with($ptString, '...')) {
200200
return $html;
201201
}
202202

libraries/src/Mail/MailHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public static function isEmailAddress($email)
136136
$allowed = "a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-";
137137
$regex = "/^[$allowed][\.$allowed]{0,63}$/";
138138

139-
if (!preg_match($regex, $local) || substr($local, -1) === '.' || $local[0] === '.' || preg_match('/\.\./', $local)) {
139+
if (!preg_match($regex, $local) || str_ends_with($local, '.') || $local[0] === '.' || preg_match('/\.\./', $local)) {
140140
return false;
141141
}
142142

libraries/src/Router/SiteRouter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public function parseFormat(&$router, &$uri)
178178
$route = $uri->getPath();
179179

180180
// Identify format
181-
if (!(substr($route, -9) === 'index.php' || substr($route, -1) === '/') && $suffix = pathinfo($route, PATHINFO_EXTENSION)) {
181+
if (!(str_ends_with($route, 'index.php') || str_ends_with($route, '/')) && $suffix = pathinfo($route, PATHINFO_EXTENSION)) {
182182
$uri->setVar('format', $suffix);
183183
$route = str_replace('.' . $suffix, '', $route);
184184
$uri->setPath($route);
@@ -509,7 +509,7 @@ public function buildFormat(&$router, &$uri)
509509
$route = $uri->getPath();
510510

511511
// Identify format
512-
if (!(substr($route, -9) === 'index.php' || substr($route, -1) === '/') && $format = $uri->getVar('format', 'html')) {
512+
if (!(str_ends_with($route, 'index.php') || str_ends_with($route, '/')) && $format = $uri->getVar('format', 'html')) {
513513
$route .= '.' . $format;
514514
$uri->setPath($route);
515515
$uri->delVar('format');

libraries/src/Schema/ChangeItem/MysqlChangeItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ private function checkDefault($changesArray, $type)
354354
// Skip types that do not support default values
355355
$type = strtolower($type);
356356

357-
if (substr($type, -4) === 'text' || substr($type, -4) === 'blob') {
357+
if (str_ends_with($type, 'text') || str_ends_with($type, 'blob')) {
358358
return false;
359359
}
360360

libraries/src/Updater/Adapter/CollectionAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public function findUpdate($options)
227227

228228
if (!xml_parse($this->xmlParser, $response->body)) {
229229
// If the URL is missing the .xml extension, try appending it and retry loading the update
230-
if (!$this->appendExtension && (substr($this->_url, -4) !== '.xml')) {
230+
if (!$this->appendExtension && (!str_ends_with($this->_url, '.xml'))) {
231231
$options['append_extension'] = true;
232232

233233
return $this->findUpdate($options);

libraries/src/Updater/Adapter/ExtensionAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public function findUpdate($options)
286286

287287
if (!xml_parse($this->xmlParser, $response->body)) {
288288
// If the URL is missing the .xml extension, try appending it and retry loading the update
289-
if (!$this->appendExtension && (substr($this->_url, -4) !== '.xml')) {
289+
if (!$this->appendExtension && (!str_ends_with($this->_url, '.xml'))) {
290290
$options['append_extension'] = true;
291291

292292
return $this->findUpdate($options);

libraries/src/Updater/UpdateAdapter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ protected function getUpdateSiteResponse($options = [])
229229
$this->appendExtension = $options['append_extension'];
230230
}
231231

232-
if ($this->appendExtension && (substr($url, -4) !== '.xml')) {
233-
if (substr($url, -1) !== '/') {
232+
if ($this->appendExtension && (!str_ends_with($url, '.xml'))) {
233+
if (!str_ends_with($url, '/')) {
234234
$url .= '/';
235235
}
236236

@@ -281,7 +281,7 @@ protected function getUpdateSiteResponse($options = [])
281281

282282
if ($response === null || $response->code !== 200) {
283283
// If the URL is missing the .xml extension, try appending it and retry loading the update
284-
if (!$this->appendExtension && (substr($url, -4) !== '.xml')) {
284+
if (!$this->appendExtension && (!str_ends_with($url, '.xml'))) {
285285
$options['append_extension'] = true;
286286

287287
return $this->getUpdateSiteResponse($options);

0 commit comments

Comments
 (0)