Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cs] introduce modern string functions #366

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
'@PhpCsFixer' => true,
'@Symfony' => true,
'array_syntax' => ['syntax' => 'short'],
'modernize_strpos' => true,
])
->setRiskyAllowed(true)
->setCacheFile('.cache/php-cs-fixer.cache')
->setFinder($finder)
;
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"license": "MIT",
"require": {
"php" : "^7.4 || ^8.1",
"friendsofsymfony1/swiftmailer": "^5.4.13 || ^6.2.5"
"friendsofsymfony1/swiftmailer": "^5.4.13 || ^6.2.5",
"symfony/polyfill-php80": "^1.29"
},
"require-dev": {
"psr/log": "*"
Expand Down
2 changes: 1 addition & 1 deletion lib/autoload/sfCoreAutoload.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ public static function make()
$classes = '';
foreach ($files as $file) {
$file = str_replace(DIRECTORY_SEPARATOR, '/', $file);
$class = basename($file, false === strpos($file, '.class.php') ? '.php' : '.class.php');
$class = basename($file, !str_contains($file, '.class.php') ? '.php' : '.class.php');

$contents = file_get_contents($file);
if (false !== stripos($contents, 'class '.$class)
Expand Down
2 changes: 1 addition & 1 deletion lib/cache/sfFileCache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function remove($key)
*/
public function removePattern($pattern)
{
if (false !== strpos($pattern, '**')) {
if (str_contains($pattern, '**')) {
$pattern = str_replace(sfCache::SEPARATOR, DIRECTORY_SEPARATOR, $pattern).self::EXTENSION;

$regexp = self::patternToRegexp($pattern);
Expand Down
2 changes: 1 addition & 1 deletion lib/command/sfCommandApplication.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ protected function fixCgi()
ini_set('html_errors', false);
ini_set('magic_quotes_runtime', false);

if (false === strpos(PHP_SAPI, 'cgi')) {
if (!str_contains(PHP_SAPI, 'cgi')) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/command/sfCommandManager.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function process($arguments = null)
break;
}

if ('--' == substr($argument, 0, 2)) {
if (str_starts_with($argument, '--')) {
$this->parseLongOption(substr($argument, 2));
} elseif ('-' == $argument[0]) {
$this->parseShortOption(substr($argument, 1));
Expand Down Expand Up @@ -316,7 +316,7 @@ protected function parseShortOption($argument)
*/
protected function parseLongOption($argument)
{
if (false !== strpos($argument, '=')) {
if (str_contains($argument, '=')) {
list($name, $value) = explode('=', $argument, 2);

if (!$this->optionSet->hasOption($name)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/command/sfCommandOption.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class sfCommandOption
*/
public function __construct($name, $shortcut = null, $mode = null, $help = '', $default = null)
{
if ('--' == substr($name, 0, 2)) {
if (str_starts_with($name, '--')) {
$name = substr($name, 2);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/config/sfRoutingConfigHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function parse($configFiles)
foreach ($config as $name => $params) {
if (
(isset($params['type']) && 'collection' == $params['type'])
|| (isset($params['class']) && false !== strpos($params['class'], 'Collection'))
|| (isset($params['class']) && str_contains($params['class'], 'Collection'))
) {
$options = isset($params['options']) ? $params['options'] : [];
$options['name'] = $name;
Expand Down
4 changes: 2 additions & 2 deletions lib/controller/sfWebController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function genUrl($parameters = [], $absolute = false)
}

// relative URL?
if (0 === strpos($parameters, '/')) {
if (str_starts_with($parameters, '/')) {
return $parameters;
}

Expand Down Expand Up @@ -109,7 +109,7 @@ public function convertUrlStringToParameters($url)
// routeName?
if ($url && '@' == $url[0]) {
$route = substr($url, 1);
} elseif (false !== strpos($url, '/')) {
} elseif (str_contains($url, '/')) {
list($params['module'], $params['action']) = explode('/', $url);
} elseif (!$queryString) {
$route = $givenUrl;
Expand Down
2 changes: 1 addition & 1 deletion lib/debug/sfDebug.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public static function shortenFilePath($file)
}

foreach (['sf_root_dir', 'sf_symfony_lib_dir'] as $key) {
if (0 === strpos($file, $value = sfConfig::get($key))) {
if (str_starts_with($file, $value = sfConfig::get($key))) {
$file = str_replace($value, strtoupper($key), $file);

break;
Expand Down
2 changes: 1 addition & 1 deletion lib/debug/sfWebDebugPanel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function getToggleableDebugStack($debugStack)
$file = isset($trace['file']) ? $trace['file'] : null;
$line = isset($trace['line']) ? $trace['line'] : null;

$isProjectFile = $file && 0 === strpos($file, sfConfig::get('sf_root_dir')) && !preg_match('/(cache|plugins|vendor)/', $file);
$isProjectFile = $file && str_starts_with($file, sfConfig::get('sf_root_dir')) && !preg_match('/(cache|plugins|vendor)/', $file);

$html .= sprintf('<span%s>#%s &raquo; ', $isProjectFile ? ' class="sfWebDebugHighlight"' : '', $keys[$j] + 1);

Expand Down
2 changes: 1 addition & 1 deletion lib/debug/sfWebDebugPanelCache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function getTitleUrl()
{
$queryString = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY);

if (false === strpos($queryString, '_sf_ignore_cache')) {
if (!str_contains($queryString, '_sf_ignore_cache')) {
return sprintf('?%s_sf_ignore_cache=1', $queryString ? $queryString.'&' : '');
}

Expand Down
2 changes: 1 addition & 1 deletion lib/debug/sfWebDebugPanelLogs.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected function formatLogLine($logLine)
$logLine = $this->formatSql($logLine);

// remove username/password from DSN
if (false !== strpos($logLine, 'DSN')) {
if (str_contains($logLine, 'DSN')) {
$logLine = preg_replace("/=&gt;\\s+'?[^'\\s,]+'?/", "=&gt; '****'", $logLine);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/debug/sfWebDebugPanelView.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ protected function filterCoreParameters($parameters)
$filtered = [];

foreach ($parameters as $name => $value) {
if (0 !== strpos($name, 'sf_')) {
if (!str_starts_with($name, 'sf_')) {
$filtered[$name] = $value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/escaper/sfOutputEscaperObjectDecorator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __call($method, $args)
{
if (count($args) > 0) {
$escapingMethod = $args[count($args) - 1];
if (is_string($escapingMethod) && 'esc_' === substr($escapingMethod, 0, 4)) {
if (is_string($escapingMethod) && str_starts_with($escapingMethod, 'esc_')) {
array_pop($args);
} else {
$escapingMethod = $this->escapingMethod;
Expand Down
2 changes: 1 addition & 1 deletion lib/form/sfForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public function getValue($field)
*/
public function getName()
{
if ('[%s]' != substr($nameFormat = $this->widgetSchema->getNameFormat(), -4)) {
if (!str_ends_with($nameFormat = $this->widgetSchema->getNameFormat(), '[%s]')) {
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/generator/sfModelGeneratorConfiguration.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public static function getFieldConfigValue($config, $key, $default = null)

public function getCredentials($action)
{
if (0 === strpos($action, '_')) {
if (str_starts_with($action, '_')) {
$action = substr($action, 1);
}

Expand Down Expand Up @@ -401,7 +401,7 @@ protected function compile()
foreach ($this->getListBatchActions() as $action => $parameters) {
$parameters = $this->fixActionParameters($action, $parameters);

$action = 'batch'.ucfirst(0 === strpos($action, '_') ? substr($action, 1) : $action);
$action = 'batch'.ucfirst(str_starts_with($action, '_') ? substr($action, 1) : $action);

$this->configuration['list']['batch_actions'][$action] = $parameters;
}
Expand Down Expand Up @@ -440,7 +440,7 @@ protected function compile()
'delete' => [],
];
foreach ($this->getActionsDefault() as $action => $params) {
if (0 === strpos($action, '_')) {
if (str_starts_with($action, '_')) {
$action = substr($action, 1);
}

Expand Down
10 changes: 5 additions & 5 deletions lib/helper/AssetHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,13 @@ function image_tag($source, $options = [])

function _compute_public_path($source, $dir, $ext, $absolute = false)
{
if (strpos($source, '://') || 0 === strpos($source, '//')) {
if (strpos($source, '://') || str_starts_with($source, '//')) {
return $source;
}

$request = sfContext::getInstance()->getRequest();
$sf_relative_url_root = $request->getRelativeUrlRoot();
if (0 !== strpos($source, '/')) {
if (!str_starts_with($source, '/')) {
$source = $sf_relative_url_root.'/'.$dir.'/'.$source;
}

Expand All @@ -369,11 +369,11 @@ function _compute_public_path($source, $dir, $ext, $absolute = false)
$source = substr($source, 0, $pos);
}

if (false === strpos(basename($source), '.')) {
if (!str_contains(basename($source), '.')) {
$source .= '.'.$ext;
}

if ($sf_relative_url_root && 0 !== strpos($source, $sf_relative_url_root)) {
if ($sf_relative_url_root && !str_starts_with($source, $sf_relative_url_root)) {
$source = $sf_relative_url_root.$source;
}

Expand Down Expand Up @@ -588,7 +588,7 @@ function use_dynamic_stylesheet($css, $position = '', $options = [])

function _dynamic_path($uri, $format, $absolute = false)
{
return url_for($uri.(false === strpos($uri, '?') ? '?' : '&').'sf_format='.$format, $absolute);
return url_for($uri.(!str_contains($uri, '?') ? '?' : '&').'sf_format='.$format, $absolute);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/helper/TagHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function _get_option(&$options, $name, $default = null)
function get_id_from_name($name, $value = null)
{
// check to see if we have an array variable for a field name
if (false !== strpos($name, '[')) {
if (str_contains($name, '[')) {
$name = str_replace(['[]', '][', '[', ']'], [(null != $value) ? '_'.$value : '', '_', '_', ''], $name);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/helper/UrlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function url_for()
{
// for BC with 1.1
$arguments = func_get_args();
if (is_array($arguments[0]) || '@' == substr($arguments[0], 0, 1) || false !== strpos($arguments[0], '/')) {
if (is_array($arguments[0]) || str_starts_with($arguments[0], '@') || str_contains($arguments[0], '/')) {
return call_user_func_array('url_for1', $arguments);
}

Expand Down Expand Up @@ -156,7 +156,7 @@ function link_to()
{
// for BC with 1.1
$arguments = func_get_args();
if (empty($arguments[1]) || is_array($arguments[1]) || '@' == substr($arguments[1], 0, 1) || false !== strpos($arguments[1], '/')) {
if (empty($arguments[1]) || is_array($arguments[1]) || str_starts_with($arguments[1], '@') || str_contains($arguments[1], '/')) {
return call_user_func_array('link_to1', $arguments);
}

Expand Down Expand Up @@ -215,7 +215,7 @@ function form_tag_for(sfForm $form, $routePrefix, $attributes = [])
function link_to_if()
{
$arguments = func_get_args();
if (empty($arguments[2]) || '@' == substr($arguments[2], 0, 1) || false !== strpos($arguments[2], '/')) {
if (empty($arguments[2]) || str_starts_with($arguments[2], '@') || str_contains($arguments[2], '/')) {
list($condition, $name, $params, $options) = array_pad($arguments, 4, null);
} else {
list($condition, $name, $routeName, $params, $options) = array_pad($arguments, 5, null);
Expand Down Expand Up @@ -294,7 +294,7 @@ function public_path($path, $absolute = false)
$source = $root;
}

if ('/' != substr($path, 0, 1)) {
if (!str_starts_with($path, '/')) {
$path = '/'.$path;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/sfI18N.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public function getTimeForCulture($time, $culture = null)

// We parse time format to see where things are (h, m)
$timePositions = [
'h' => false !== strpos($timeFormat, 'H') ? strpos($timeFormat, 'H') : strpos($timeFormat, 'h'),
'h' => str_contains($timeFormat, 'H') ? strpos($timeFormat, 'H') : strpos($timeFormat, 'h'),
'm' => strpos($timeFormat, 'm'),
'a' => strpos($timeFormat, 'a'),
];
Expand Down
8 changes: 4 additions & 4 deletions lib/i18n/sfMessageSource_Database.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ protected function parseDSN($dsn)
$dsn = $match[3];
// $dsn => protocol+hostspec/database (old format)
} else {
if (false !== strpos($dsn, '+')) {
if (str_contains($dsn, '+')) {
list($proto, $dsn) = explode('+', $dsn, 2);
}
if (false !== strpos($dsn, '/')) {
if (str_contains($dsn, '/')) {
list($proto_opts, $dsn) = explode('/', $dsn, 2);
} else {
$proto_opts = $dsn;
Expand All @@ -145,7 +145,7 @@ protected function parseDSN($dsn)
$parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
$proto_opts = rawurldecode($proto_opts);
if ('tcp' == $parsed['protocol']) {
if (false !== strpos($proto_opts, ':')) {
if (str_contains($proto_opts, ':')) {
list($parsed['hostspec'], $parsed['port']) = explode(':', $proto_opts);
} else {
$parsed['hostspec'] = $proto_opts;
Expand All @@ -164,7 +164,7 @@ protected function parseDSN($dsn)
} else {
$parsed['database'] = substr($dsn, 0, $pos);
$dsn = substr($dsn, $pos + 1);
if (false !== strpos($dsn, '&')) {
if (str_contains($dsn, '&')) {
$opts = explode('&', $dsn);
} else { // database?param1=value1
$opts = [$dsn];
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/sfNumberFormat.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ protected function fixFloat($float)
{
$string = (string) $float;

if (false === strpos($float, 'E')) {
if (!str_contains($float, 'E')) {
return $string;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/log/sfWebDebugLogger.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ public function filterResponseContent(sfEvent $event, $content)
|| !$this->context->has('response')
|| !$this->context->has('controller')
|| $request->isXmlHttpRequest()
|| false === strpos($response->getContentType(), 'html')
|| '3' == substr($response->getStatusCode(), 0, 1)
|| !str_contains($response->getContentType(), 'html')
|| str_starts_with($response->getStatusCode(), '3')
|| sfView::RENDER_CLIENT != $this->context->getController()->getRenderMode()
|| $response->isHeaderOnly()
) {
Expand Down
8 changes: 4 additions & 4 deletions lib/plugin/sfPluginManager.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function installPlugin($plugin, $options = [])
*/
public function uninstallPlugin($plugin, $channel = null)
{
if (false !== strpos($plugin, '/')) {
if (str_contains($plugin, '/')) {
list($channel, $plugin) = explode('/', $plugin);
}

Expand Down Expand Up @@ -293,14 +293,14 @@ protected function doInstallPlugin($plugin, $options = [])
$version = isset($options['version']) ? $options['version'] : null;

$isPackage = true;
if (0 === strpos($plugin, 'http://') || file_exists($plugin)) {
if (0 === strpos($plugin, 'http://plugins.symfony-project.')) {
if (str_starts_with($plugin, 'http://') || file_exists($plugin)) {
if (str_starts_with($plugin, 'http://plugins.symfony-project.')) {
throw new sfPluginException("You try to install a symfony 1.0 plugin.\nPlease read the help message of this task to know how to install a plugin for the current version of symfony.");
}

$download = $plugin;
$isPackage = false;
} elseif (false !== strpos($plugin, '/')) {
} elseif (str_contains($plugin, '/')) {
list($channel, $plugin) = explode('/', $plugin);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/plugin/sfSymfonyPluginManager.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ protected function registerSymfonyPackage()
$symfony->setConfig($this->environment->getConfig());
$symfony->setPackageType('php');
$symfony->setAPIVersion(preg_replace('/\d+(\-\w+)?$/', '0', SYMFONY_VERSION));
$symfony->setAPIStability(false === strpos(SYMFONY_VERSION, 'DEV') ? 'stable' : 'beta');
$symfony->setAPIStability(!str_contains(SYMFONY_VERSION, 'DEV') ? 'stable' : 'beta');
$symfony->setReleaseVersion(preg_replace('/\-\w+$/', '', SYMFONY_VERSION));
$symfony->setReleaseStability(false === strpos(SYMFONY_VERSION, 'DEV') ? 'stable' : 'beta');
$symfony->setReleaseStability(!str_contains(SYMFONY_VERSION, 'DEV') ? 'stable' : 'beta');
$symfony->setDate(date('Y-m-d'));
$symfony->setDescription('symfony');
$symfony->setSummary('symfony');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected function getSqlLogs()
break;
}

if (false !== strpos($log['message'], $event->getQuery())) {
if (str_contains($log['message'], $event->getQuery())) {
// assume queries are being requested in order
unset($logs[$i]);
$backtrace = '&nbsp;'.$this->getToggleableDebugStack($log['debug_backtrace']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected function prepareSchemaFile($yamlSchemaPath)
$models[$model]['package'] = $plugin->getName().'.lib.model.doctrine';
}

if (!isset($models[$model]['package_custom_path']) && 0 === strpos($models[$model]['package'], $plugin->getName())) {
if (!isset($models[$model]['package_custom_path']) && str_starts_with($models[$model]['package'], $plugin->getName())) {
$models[$model]['package_custom_path'] = $plugin->getRootDir().'/lib/model/doctrine';
}
}
Expand Down
Loading
Loading