Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/src/Cache/Storage/ApcuStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function clean($group, $mode = null)
$internalKey = $key['key'];
}

if (strpos($internalKey, $secret . '-cache-' . $group . '-') === 0 xor $mode !== 'group') {
if (str_starts_with($internalKey, $secret . '-cache-' . $group . '-') xor $mode !== 'group') {
apcu_delete($internalKey);
}
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Cache/Storage/MemcachedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function clean($group, $mode = null)
$prefix = $this->_hash . '-cache-' . $group . '-';

foreach ($index as $key => $value) {
if (strpos($value->name, $prefix) === 0 xor $mode !== 'group') {
if (str_starts_with($value->name, $prefix) xor $mode !== 'group') {
static::$_db->delete($value->name);
unset($index[$key]);
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/src/Cache/Storage/RedisStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,11 @@ public function clean($group, $mode = null)
$secret = $this->_hash;

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

if (strpos($key, $secret . '-cache-' . $group . '-') !== 0 && $mode !== 'group') {
if (!str_starts_with($key, $secret . '-cache-' . $group . '-') && $mode !== 'group') {
static::$_redis->del($key);
}
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Event/AbstractEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function create(string $eventName, array $arguments = [])
* the onTableBeforeLoad event name.
*/
if (!$eventClassName || !class_exists($eventClassName, true)) {
$bareName = strpos($eventName, 'on') === 0 ? substr($eventName, 2) : $eventName;
$bareName = str_starts_with($eventName, 'on') ? substr($eventName, 2) : $eventName;
$parts = Normalise::fromCamelCase($bareName, true);
$eventClassName = __NAMESPACE__ . '\\' . ucfirst(array_shift($parts)) . '\\';
$eventClassName .= implode('', $parts);
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Filesystem/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public static function create($path = '', $mode = 0755)
foreach ($obdArray as $test) {
$test = Path::clean($test);

if (strpos($path, $test) === 0 || strpos($path, realpath($test)) === 0) {
if (str_starts_with($path, $test) || str_starts_with($path, realpath($test))) {
$inBaseDir = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function getOptions()
$options = [];
$options[] = HTMLHelper::_('select.option', ' ', Text::_('JNONE'));
foreach ($items as $item) {
if (substr($item->value, 0, 4) !== 'com_') {
if (!str_starts_with($item->value, 'com_')) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function getOptions()
$options[] = HTMLHelper::_('select.option', ' ', Text::_('JNONE'));

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

Expand Down
4 changes: 2 additions & 2 deletions libraries/src/Form/Filter/TelFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public function filter(\SimpleXMLElement $element, $value, $group = null, ?Regis
if (preg_match('/^(?:\+?1[-. ]?)?\(?([2-9][0-8][0-9])\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/', $value) == 1) {
$number = (string) preg_replace('/[^\d]/', '', $value);

if (substr($number, 0, 1) === '1') {
if (str_starts_with($number, '1')) {
$number = substr($number, 1);
}

if (substr($number, 0, 2) === '+1') {
if (str_starts_with($number, '+1')) {
$number = substr($number, 2);
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/src/Form/Filter/UrlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function filter(\SimpleXMLElement $element, $value, $group = null, ?Regis
$protocol = 'http';

// If it looks like an internal link, then add the root.
if (substr($value, 0, 9) === 'index.php') {
if (str_starts_with($value, 'index.php')) {
$value = Uri::root() . $value;
} else {
// Otherwise we treat it as an external link.
Expand All @@ -81,7 +81,7 @@ public function filter(\SimpleXMLElement $element, $value, $group = null, ?Regis
// If it starts with the host string, just prepend the protocol.
if (substr($value, 0) === $host) {
$value = 'http://' . $value;
} elseif (substr($value, 0, 1) !== '/') {
} elseif (!str_starts_with($value, '/')) {
// Otherwise if it doesn't start with "/" prepend the prefix of the current site.
$value = Uri::root(true) . '/' . $value;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1705,7 +1705,7 @@ public static function getInstance($name, $data = null, $options = [], $replace
$forms[$name] = Factory::getContainer()->get(FormFactoryInterface::class)->createForm($name, $options);

// Load the data.
if (substr($data, 0, 1) === '<') {
if (str_starts_with($data, '<')) {
if ($forms[$name]->load($data, $replace, $xpath) == false) {
throw new \RuntimeException(\sprintf('%s() could not load form', __METHOD__));
}
Expand Down
6 changes: 3 additions & 3 deletions libraries/src/Form/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ public function __get($name)

default:
// Check for data attribute
if (strpos($name, 'data-') === 0 && \array_key_exists($name, $this->dataAttributes)) {
if (str_starts_with($name, 'data-') && \array_key_exists($name, $this->dataAttributes)) {
return $this->dataAttributes[$name];
}
}
Expand Down Expand Up @@ -593,7 +593,7 @@ public function __set($name, $value)

default:
// Detect data attribute(s)
if (strpos($name, 'data-') === 0) {
if (str_starts_with($name, 'data-')) {
$this->dataAttributes[$name] = $value;
} else {
if (property_exists(__CLASS__, $name)) {
Expand Down Expand Up @@ -671,7 +671,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null)

// Lets detect miscellaneous data attribute. For eg, data-*
foreach ($this->element->attributes() as $key => $value) {
if (strpos($key, 'data-') === 0) {
if (str_starts_with($key, 'data-')) {
// Data attribute key value pair
$this->dataAttributes[$key] = $value;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/HTML/HTMLHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ protected static function includeRelativeFiles($folder, $file, $relative, $detec
}

// If http is present in filename
if (strpos($file, 'http') === 0 || strpos($file, '//') === 0) {
if (str_starts_with($file, 'http') || str_starts_with($file, '//')) {
$includes = [$file];
} else {
// Extract extension and strip the file
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Helper/AuthenticationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static function getLoginButtons(string $formId): array

// Unset anything that doesn't conform to a button definition
foreach (array_keys($button) as $key) {
if (substr($key, 0, 5) == 'data-') {
if (str_starts_with($key, 'data-')) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Helper/ModuleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static function &getModule($name, $title = null)
}

// If we didn't find it, and the name is mod_something, create a dummy object
if ($result === null && strpos($name, 'mod_') === 0) {
if ($result === null && str_starts_with($name, 'mod_')) {
$result = static::createDummyModule();
$result->module = $name;
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/src/Helper/PublicFolderGeneratorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function createPublicFolder(string $destinationPath): void
$root = JPATH_ROOT . '/';
$defineRoot = '\'' . JPATH_ROOT . '\'';

if (substr($destinationPath, 0, 1) !== '/') {
if (!str_starts_with($destinationPath, '/')) {
$fullDestinationPath = JPATH_ROOT . '/' . $destinationPath;
$root = '';
$dirsToRoot = substr_count($destinationPath, '/');
Expand Down Expand Up @@ -190,7 +190,7 @@ public function createPublicFolder(string $destinationPath): void
*/
private function createSymlink(string $source, string $dest, string $base): void
{
if (substr($source, 0, 1) !== '/') {
if (!str_starts_with($source, '/')) {
$source = str_repeat('../', substr_count($dest, '/')) . $source;
$dest = $base . $dest;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Http/Transport/CurlTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function request($method, UriInterface $uri, $data = null, array $headers
// If data exists let's encode it and make sure our Content-type header is set.
if (isset($data)) {
// If the data is a scalar value simply add it to the cURL post fields.
if (\is_scalar($data) || (isset($headers['Content-Type']) && strpos($headers['Content-Type'], 'multipart/form-data') === 0)) {
if (\is_scalar($data) || (isset($headers['Content-Type']) && str_starts_with($headers['Content-Type'], 'multipart/form-data'))) {
$options[CURLOPT_POSTFIELDS] = $data;
} else {
// Otherwise we need to encode the value first.
Expand Down
4 changes: 2 additions & 2 deletions libraries/src/Input/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected function parseArguments()
$arg = $argv[$i];

// --foo --bar=baz
if (substr($arg, 0, 2) === '--') {
if (str_starts_with($arg, '--')) {
$eqPos = strpos($arg, '=');

// --foo
Expand All @@ -169,7 +169,7 @@ protected function parseArguments()
$value = substr($arg, $eqPos + 1);
$out[$key] = $value;
}
} elseif (substr($arg, 0, 1) === '-') {
} elseif (str_starts_with($arg, '-')) {
// -k=value -abc
// -k=value
if (substr($arg, 2, 1) === '=') {
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Installer/Adapter/ComponentAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ public function getElement($element = null)
{
$element = parent::getElement($element);

if (strpos($element, 'com_') !== 0) {
if (!str_starts_with($element, 'com_')) {
$element = 'com_' . $element;
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/src/MVC/Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ public function getModel($name = '', $prefix = '', $config = [])
if (!$prefix) {
if ($this->factory instanceof LegacyFactory) {
$prefix = $this->model_prefix;
} elseif (!empty($config['base_path']) && strpos(Path::clean($config['base_path']), JPATH_ADMINISTRATOR) === 0) {
} elseif (!empty($config['base_path']) && str_starts_with(Path::clean($config['base_path']), JPATH_ADMINISTRATOR)) {
// When the frontend uses an administrator model
$prefix = 'Administrator';
} else {
Expand Down Expand Up @@ -861,7 +861,7 @@ public function getView($name = '', $type = '', $prefix = '', $config = [])
if (!$prefix) {
if ($this->factory instanceof LegacyFactory) {
$prefix = $this->getName() . 'View';
} elseif (!empty($config['base_path']) && strpos(Path::clean($config['base_path']), JPATH_ADMINISTRATOR) === 0) {
} elseif (!empty($config['base_path']) && str_starts_with(Path::clean($config['base_path']), JPATH_ADMINISTRATOR)) {
// When the front uses an administrator view
$prefix = 'Administrator';
} else {
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/MVC/Model/FormBehaviorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function loadForm($name, $source = null, $options = [], $clear = false
}

// Load the data.
if (substr($source, 0, 1) === '<') {
if (str_starts_with($source, '<')) {
if ($form->load($source, false, $xpath) == false) {
throw new \RuntimeException('Form::loadForm could not load form');
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/MVC/Model/ListModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ public function getUserStateFromRequest($key, $request, $default = null, $type =
$new_state = $input->get($request, null, $type);

// BC for Search Tools which uses different naming
if ($new_state === null && strpos($request, 'filter_') === 0) {
if ($new_state === null && str_starts_with($request, 'filter_')) {
$name = substr($request, 7);
$filters = $app->getInput()->get('filter', [], 'array');

Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Mail/MailHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static function isEmailAddress($email)
}

// Check for a dash at the beginning of the domain
if (strpos($domain, '-') === 0) {
if (str_starts_with($domain, '-')) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Object/LegacyPropertyManagementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function getProperties($public = true)

if ($public) {
foreach ($vars as $key => $value) {
if ('_' == substr($key, 0, 1)) {
if (str_starts_with($key, '_')) {
unset($vars[$key]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Pathway/SitePathway.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(?SiteApplication $app = null)
break;

case 'url':
if ((strpos($link->link, 'index.php?') === 0) && (strpos($link->link, 'Itemid=') === false)) {
if ((str_starts_with($link->link, 'index.php?')) && (strpos($link->link, 'Itemid=') === false)) {
// If this is an internal Joomla link, ensure the Itemid is set.
$url = $link->link . '&Itemid=' . $link->id;
} else {
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Plugin/CMSPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function registerListeners()

/** @var \ReflectionMethod $method */
foreach ($methods as $method) {
if (substr($method->name, 0, 2) !== 'on') {
if (!str_starts_with($method->name, 'on')) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Router/ApiRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private function removeIndexPhpFromPath(string $path): string
$path = ltrim($path, '/');

// We can only remove index.php if it's present in the beginning of the route
if (strpos($path, 'index.php') !== 0) {
if (!str_starts_with($path, 'index.php')) {
return $path;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Router/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static function _($url, $xhtml = true, $tls = self::TLS_IGNORE, $absolute
public static function link($client, $url, $xhtml = true, $tls = self::TLS_IGNORE, $absolute = false)
{
// If we cannot process this $url exit early.
if (!\is_array($url) && (strpos($url, '&') !== 0) && (strpos($url, 'index.php') !== 0)) {
if (!\is_array($url) && (!str_starts_with($url, '&')) && (!str_starts_with($url, 'index.php'))) {
return $url;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ protected function processBuildRules(&$uri, $stage = self::PROCESS_DURING)
*/
protected function createUri($url)
{
if (!\is_array($url) && substr($url, 0, 1) !== '&') {
if (!\is_array($url) && !str_starts_with($url, '&')) {
return new Uri($url);
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Table/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ public function reset()
// Get the default values for the class from the table.
foreach ($this->getFields() as $k => $v) {
// If the property is not the primary key or private, reset it.
if (!\in_array($k, $this->_tbl_keys) && (strpos($k, '_') !== 0)) {
if (!\in_array($k, $this->_tbl_keys) && (!str_starts_with($k, '_'))) {
$this->$k = $v->Default;
}
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Toolbar/Button/PopupButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private function _getCommand($url)
{
$url = $url ?? '';

if (strpos($url, 'http') !== 0) {
if (!str_starts_with($url, 'http')) {
$url = Uri::base() . $url;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Uri/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public static function isInternal($url)

// @see UriTest
if (
empty($host) && strpos($uri->path, 'index.php') === 0
empty($host) && str_starts_with($uri->path, 'index.php')
|| !empty($host) && preg_match('#^' . preg_quote(static::base(), '#') . '#', $base)
|| !empty($host) && $host === static::getInstance(static::base())->host && strpos($uri->path, 'index.php') !== false
|| !empty($host) && $base === $host && preg_match('#^' . preg_quote($base, '#') . '#', static::base())
Expand Down
8 changes: 4 additions & 4 deletions libraries/src/User/UserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,22 +465,22 @@ public static function verifyPassword($password, $hash, $userId = 0)
$container = Factory::getContainer();

// Cheaply try to determine the algorithm in use otherwise fall back to the chained handler
if (strpos($hash, '$P$') === 0) {
if (str_starts_with($hash, '$P$')) {
/** @var PHPassHandler $handler */
$handler = $container->get(PHPassHandler::class);
} elseif (strpos($hash, '$argon2id') === 0) {
} elseif (str_starts_with($hash, '$argon2id')) {
// Check for Argon2id hashes
/** @var Argon2idHandler $handler */
$handler = $container->get(Argon2idHandler::class);

$passwordAlgorithm = self::HASH_ARGON2ID;
} elseif (strpos($hash, '$argon2i') === 0) {
} elseif (str_starts_with($hash, '$argon2i')) {
// Check for Argon2i hashes
/** @var Argon2iHandler $handler */
$handler = $container->get(Argon2iHandler::class);

$passwordAlgorithm = self::HASH_ARGON2I;
} elseif (strpos($hash, '$2') === 0) {
} elseif (str_starts_with($hash, '$2')) {
// Check for bcrypt hashes
/** @var BCryptHandler $handler */
$handler = $container->get(BCryptHandler::class);
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/WebAsset/WebAssetItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ protected function resolvePath(string $path, string $type): string
*/
protected function isPathExternal(string $path): bool
{
return strpos($path, 'http://') === 0 || strpos($path, 'https://') === 0 || strpos($path, '//') === 0;
return str_starts_with($path, 'http://') || str_starts_with($path, 'https://') || str_starts_with($path, '//');
}

/**
Expand Down
Loading