Skip to content

Commit

Permalink
[rector] improvement: use null coalescing operator
Browse files Browse the repository at this point in the history
  • Loading branch information
connorhu committed Mar 23, 2024
1 parent 4e19251 commit befc2bb
Show file tree
Hide file tree
Showing 124 changed files with 322 additions and 322 deletions.
8 changes: 4 additions & 4 deletions lib/action/sfAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public function getPartial($templateName, $vars = null)
{
$this->getContext()->getConfiguration()->loadHelpers('Partial');

$vars = null !== $vars ? $vars : $this->varHolder->getAll();
$vars ??= $this->varHolder->getAll();

return get_partial($templateName, $vars);
}
Expand Down Expand Up @@ -333,7 +333,7 @@ public function getComponent($moduleName, $componentName, $vars = null)
{
$this->getContext()->getConfiguration()->loadHelpers('Partial');

$vars = null !== $vars ? $vars : $this->varHolder->getAll();
$vars ??= $this->varHolder->getAll();

return get_component($moduleName, $componentName, $vars);
}
Expand Down Expand Up @@ -422,7 +422,7 @@ public function getCredential()
public function setTemplate($name, $module = null)
{
if (sfConfig::get('sf_logging_enabled')) {
$this->dispatcher->notify(new sfEvent($this, 'application.log', [sprintf('Change template to "%s/%s"', null === $module ? 'CURRENT' : $module, $name)]));
$this->dispatcher->notify(new sfEvent($this, 'application.log', [sprintf('Change template to "%s/%s"', $module ?? 'CURRENT', $name)]));
}

if (null !== $module) {
Expand Down Expand Up @@ -508,6 +508,6 @@ public function getRoute()
*/
protected function get404Message($message = null)
{
return null === $message ? sprintf('This request has been forwarded to a 404 error page by the action "%s/%s".', $this->getModuleName(), $this->getActionName()) : $message;
return $message ?? sprintf('This request has been forwarded to a 404 error page by the action "%s/%s".', $this->getModuleName(), $this->getActionName());
}
}
2 changes: 1 addition & 1 deletion lib/autoload/sfAutoload.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function getClassPath($class)
{
$class = strtolower($class);

return isset($this->classes[$class]) ? $this->classes[$class] : null;
return $this->classes[$class] ?? null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/autoload/sfSimpleAutoload.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public function getClassPath($class)
{
$class = strtolower($class);

return isset($this->classes[$class]) ? $this->classes[$class] : null;
return $this->classes[$class] ?? null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/cache/sfCache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function getMany($keys)
*/
public function getLifetime($lifetime)
{
return null === $lifetime ? $this->getOption('lifetime') : $lifetime;
return $lifetime ?? $this->getOption('lifetime');
}

/**
Expand All @@ -191,7 +191,7 @@ public function getBackend()
*/
public function getOption($name, $default = null)
{
return isset($this->options[$name]) ? $this->options[$name] : $default;
return $this->options[$name] ?? $default;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/cache/sfMemcacheCache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public function initialize($options = [])

if ($this->getOption('servers')) {
foreach ($this->getOption('servers') as $server) {
$port = isset($server['port']) ? $server['port'] : 11211;
if (!$this->memcache->addServer($server['host'], $port, isset($server['persistent']) ? $server['persistent'] : true)) {
$port = $server['port'] ?? 11211;
if (!$this->memcache->addServer($server['host'], $port, $server['persistent'] ?? true)) {
throw new sfInitializationException(sprintf('Unable to connect to the memcache server (%s:%s).', $server['host'], $port));
}
}
Expand Down Expand Up @@ -106,7 +106,7 @@ public function has($key)
*/
public function set($key, $data, $lifetime = null)
{
$lifetime = null === $lifetime ? $this->getOption('lifetime') : $lifetime;
$lifetime ??= $this->getOption('lifetime');

// save metadata
$this->setMetadata($key, $lifetime);
Expand Down
6 changes: 3 additions & 3 deletions lib/cache/sfSQLiteCache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function get($key, $default = null)
$data = $this->dbh->singleQuery(sprintf("SELECT data FROM cache WHERE key = '%s' AND timeout > %d", sqlite_escape_string($key), time()));
}

return null === $data ? $default : $data;
return $data ?? $default;
}

/**
Expand Down Expand Up @@ -153,7 +153,7 @@ public function getTimeout($key)
if ($this->isSqLite3()) {
$rs = $this->dbh->querySingle(sprintf("SELECT timeout FROM cache WHERE key = '%s' AND timeout > %d", $this->dbh->escapeString($key), time()));

return null === $rs ? 0 : $rs;
return $rs ?? 0;
}

$rs = $this->dbh->query(sprintf("SELECT timeout FROM cache WHERE key = '%s' AND timeout > %d", sqlite_escape_string($key), time()));
Expand All @@ -169,7 +169,7 @@ public function getLastModified($key)
if ($this->isSqLite3()) {
$rs = $this->dbh->querySingle(sprintf("SELECT last_modified FROM cache WHERE key = '%s' AND timeout > %d", $this->dbh->escapeString($key), time()));

return null === $rs ? 0 : $rs;
return $rs ?? 0;
}

$rs = $this->dbh->query(sprintf("SELECT last_modified FROM cache WHERE key = '%s' AND timeout > %d", sqlite_escape_string($key), time()));
Expand Down
12 changes: 6 additions & 6 deletions lib/command/sfCommandApplication.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ abstract class sfCommandApplication
public function __construct(sfEventDispatcher $dispatcher, ?sfFormatter $formatter = null, $options = [])
{
$this->dispatcher = $dispatcher;
$this->formatter = null === $formatter ? $this->guessBestFormatter(STDOUT) : $formatter;
$this->formatter = $formatter ?? $this->guessBestFormatter(STDOUT);
$this->options = $options;

$this->fixCgi();
Expand Down Expand Up @@ -100,7 +100,7 @@ abstract public function configure();
*/
public function getOption($name)
{
return isset($this->options[$name]) ? $this->options[$name] : null;
return $this->options[$name] ?? null;
}

/**
Expand Down Expand Up @@ -396,11 +396,11 @@ public function renderException($e)
]);

for ($i = 0, $count = count($trace); $i < $count; ++$i) {
$class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
$type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
$class = $trace[$i]['class'] ?? '';
$type = $trace[$i]['type'] ?? '';
$function = $trace[$i]['function'];
$file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
$line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
$file = $trace[$i]['file'] ?? 'n/a';
$line = $trace[$i]['line'] ?? 'n/a';

fwrite(STDERR, sprintf(" %s%s%s at %s:%s\n", $class, $type, $function, $this->formatter->format($file, 'INFO', STDERR), $this->formatter->format($line, 'INFO', STDERR)));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/command/sfCommandLogger.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function initialize(sfEventDispatcher $dispatcher, $options = [])
*/
public function listenToLogEvent(sfEvent $event)
{
$priority = isset($event['priority']) ? $event['priority'] : self::INFO;
$priority = $event['priority'] ?? self::INFO;

$prefix = '';
if ('application.log' == $event->getName()) {
Expand Down
6 changes: 3 additions & 3 deletions lib/config/sfAutoloadConfigHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ protected function parse(array $configFiles)
}
} else {
// directory mapping
$ext = isset($entry['ext']) ? $entry['ext'] : '.php';
$ext = $entry['ext'] ?? '.php';
$path = $entry['path'];

// we automatically add our php classes
require_once sfConfig::get('sf_symfony_lib_dir').'/util/sfFinder.class.php';
$finder = sfFinder::type('file')->name('*'.$ext)->follow_link();

// recursive mapping?
$recursive = isset($entry['recursive']) ? $entry['recursive'] : false;
$recursive = $entry['recursive'] ?? false;
if (!$recursive) {
$finder->maxdepth(0);
}
Expand All @@ -154,7 +154,7 @@ protected function parse(array $configFiles)

if ($matches = glob($path)) {
foreach ($finder->in($matches) as $file) {
$mapping = array_merge($mapping, $this->parseFile($path, $file, isset($entry['prefix']) ? $entry['prefix'] : ''));
$mapping = array_merge($mapping, $this->parseFile($path, $file, $entry['prefix'] ?? ''));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/config/sfConfig.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class sfConfig
*/
public static function get($name, $default = null)
{
return isset(self::$config[$name]) ? self::$config[$name] : $default;
return self::$config[$name] ?? $default;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/config/sfFactoryConfigHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function execute($configFiles)
$defaultParameters = [];
$defaultParameters[] = sprintf("'auto_shutdown' => false, 'session_id' => \$this->getRequest()->getParameter('%s'),", $parameters['session_name']);
if (is_subclass_of($class, 'sfDatabaseSessionStorage')) {
$defaultParameters[] = sprintf("'database' => \$this->getDatabaseManager()->getDatabase('%s'),", isset($parameters['database']) ? $parameters['database'] : 'default');
$defaultParameters[] = sprintf("'database' => \$this->getDatabaseManager()->getDatabase('%s'),", $parameters['database'] ?? 'default');
unset($parameters['database']);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/config/sfFilterConfigHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function execute($configFiles)
unset($keys['param']['condition']);
}

$type = isset($keys['param']['type']) ? $keys['param']['type'] : null;
$type = $keys['param']['type'] ?? null;
unset($keys['param']['type']);

if ($condition) {
Expand Down
8 changes: 4 additions & 4 deletions lib/config/sfGeneratorConfigHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,26 @@ public function execute($configFiles)
}

if (!isset($config['generator'])) {
throw new sfParseException(sprintf('Configuration file "%s" must specify a generator section.', isset($configFiles[1]) ? $configFiles[1] : $configFiles[0]));
throw new sfParseException(sprintf('Configuration file "%s" must specify a generator section.', $configFiles[1] ?? $configFiles[0]));
}

$config = $config['generator'];

if (!isset($config['class'])) {
throw new sfParseException(sprintf('Configuration file "%s" must specify a generator class section under the generator section.', isset($configFiles[1]) ? $configFiles[1] : $configFiles[0]));
throw new sfParseException(sprintf('Configuration file "%s" must specify a generator class section under the generator section.', $configFiles[1] ?? $configFiles[0]));
}

foreach (['fields', 'list', 'edit'] as $section) {
if (isset($config[$section])) {
throw new sfParseException(sprintf('Configuration file "%s" can specify a "%s" section but only under the param section.', isset($configFiles[1]) ? $configFiles[1] : $configFiles[0], $section));
throw new sfParseException(sprintf('Configuration file "%s" can specify a "%s" section but only under the param section.', $configFiles[1] ?? $configFiles[0], $section));
}
}

// generate class and add a reference to it
$generatorManager = new sfGeneratorManager(sfContext::getInstance()->getConfiguration());

// generator parameters
$generatorParam = (isset($config['param']) ? $config['param'] : []);
$generatorParam = ($config['param'] ?? []);

// hack to find the module name (look for the last /modules/ in path)
preg_match('#.*/modules/([^/]+)/#', str_replace('\\', '/', $configFiles[0]), $match);
Expand Down
2 changes: 1 addition & 1 deletion lib/config/sfPluginConfiguration.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(sfProjectConfiguration $configuration, $rootDir = nu
$this->configuration = $configuration;
$this->dispatcher = $configuration->getEventDispatcher();
$this->rootDir = null === $rootDir ? $this->guessRootDir() : realpath($rootDir);
$this->name = null === $name ? $this->guessName() : $name;
$this->name = $name ?? $this->guessName();

$this->setup();
$this->configure();
Expand Down
2 changes: 1 addition & 1 deletion lib/config/sfProjectConfiguration.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct($rootDir = null, ?sfEventDispatcher $dispatcher = nu

$this->rootDir = null === $rootDir ? static::guessRootDir() : realpath($rootDir);
$this->symfonyLibDir = realpath(__DIR__.'/..');
$this->dispatcher = null === $dispatcher ? new sfEventDispatcher() : $dispatcher;
$this->dispatcher = $dispatcher ?? new sfEventDispatcher();

ini_set('magic_quotes_runtime', 'off');

Expand Down
14 changes: 7 additions & 7 deletions lib/config/sfRoutingConfigHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ protected function parse($configFiles)
(isset($params['type']) && 'collection' == $params['type'])
|| (isset($params['class']) && false !== strpos($params['class'], 'Collection'))
) {
$options = isset($params['options']) ? $params['options'] : [];
$options = $params['options'] ?? [];
$options['name'] = $name;
$options['requirements'] = isset($params['requirements']) ? $params['requirements'] : [];
$options['requirements'] = $params['requirements'] ?? [];

$routes[$name] = [isset($params['class']) ? $params['class'] : 'sfRouteCollection', [$options]];
$routes[$name] = [$params['class'] ?? 'sfRouteCollection', [$options]];
} else {
$routes[$name] = [isset($params['class']) ? $params['class'] : 'sfRoute', [
$routes[$name] = [$params['class'] ?? 'sfRoute', [
$params['url'] ?: '/',
isset($params['params']) ? $params['params'] : (isset($params['param']) ? $params['param'] : []),
isset($params['requirements']) ? $params['requirements'] : [],
isset($params['options']) ? $params['options'] : [],
$params['params'] ?? $params['param'] ?? [],
$params['requirements'] ?? [],
$params['options'] ?? [],
]];
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/config/sfYamlConfigHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static function parseYaml($configFile)
throw new sfParseException(sprintf('Configuration file "%s" could not be parsed', $configFile));
}

return null === $config ? [] : $config;
return $config ?? [];
}

public static function flattenConfiguration($config)
Expand Down
4 changes: 2 additions & 2 deletions lib/debug/sfWebDebug.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function removePanel($name)
*/
public function getOption($name, $default = null)
{
return isset($this->options[$name]) ? $this->options[$name] : $default;
return $this->options[$name] ?? $default;
}

/**
Expand Down Expand Up @@ -178,7 +178,7 @@ public function injectToolbar($content)
*/
public function asHtml()
{
$current = isset($this->options['request_parameters']['sfWebDebugPanel']) ? $this->options['request_parameters']['sfWebDebugPanel'] : null;
$current = $this->options['request_parameters']['sfWebDebugPanel'] ?? null;

$titles = [];
$panels = [];
Expand Down
10 changes: 5 additions & 5 deletions lib/debug/sfWebDebugPanel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public function getToggleableDebugStack($debugStack)
$html = $this->getToggler($element, 'Toggle debug stack');
$html .= '<div class="sfWebDebugDebugInfo" id="'.$element.'" style="display:none">';
foreach ($debugStack as $j => $trace) {
$file = isset($trace['file']) ? $trace['file'] : null;
$line = isset($trace['line']) ? $trace['line'] : null;
$file = $trace['file'] ?? null;
$line = $trace['line'] ?? null;

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

Expand All @@ -122,8 +122,8 @@ public function getToggleableDebugStack($debugStack)
if (isset($trace['function'])) {
$html .= sprintf(
'in <span class="sfWebDebugLogInfo">%s%s%s()</span> ',
isset($trace['class']) ? $trace['class'] : '',
isset($trace['type']) ? $trace['type'] : '',
$trace['class'] ?? '',
$trace['type'] ?? '',
$trace['function']
);
}
Expand Down Expand Up @@ -166,7 +166,7 @@ public function formatFileLink($file, $line = null, $text = null)
'<a href="%s" class="sfWebDebugFileLink" title="%s">%s</a>',
htmlspecialchars(strtr($linkFormat, ['%f' => $file, '%l' => $line]), ENT_QUOTES, sfConfig::get('sf_charset')),
htmlspecialchars($shortFile, ENT_QUOTES, sfConfig::get('sf_charset')),
null === $text ? $shortFile : $text
$text ?? $shortFile
);
}
if (null === $text) {
Expand Down
2 changes: 1 addition & 1 deletion lib/escaper/sfOutputEscaperArrayDecorator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function offsetExists($offset)
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
$value = isset($this->value[$offset]) ? $this->value[$offset] : null;
$value = $this->value[$offset] ?? null;

return sfOutputEscaper::escape($this->escapingMethod, $value);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/exception/data/error.html.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php $path = sfConfig::get('sf_relative_url_root', preg_replace('#/[^/]+\.php5?$#', '', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : (isset($_SERVER['ORIG_SCRIPT_NAME']) ? $_SERVER['ORIG_SCRIPT_NAME'] : ''))); ?>
<?php $path = sfConfig::get('sf_relative_url_root', preg_replace('#/[^/]+\.php5?$#', '', $_SERVER['SCRIPT_NAME'] ?? $_SERVER['ORIG_SCRIPT_NAME'] ?? '')); ?>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down
2 changes: 1 addition & 1 deletion lib/exception/data/unavailable.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php $path = preg_replace('#/[^/]+\.php5?$#', '', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : (isset($_SERVER['ORIG_SCRIPT_NAME']) ? $_SERVER['ORIG_SCRIPT_NAME'] : '')); ?>
<?php $path = preg_replace('#/[^/]+\.php5?$#', '', $_SERVER['SCRIPT_NAME'] ?? $_SERVER['ORIG_SCRIPT_NAME'] ?? ''); ?>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down
2 changes: 1 addition & 1 deletion lib/exception/sfError404Exception.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class sfError404Exception extends sfException
*/
public function printStackTrace()
{
$exception = null === $this->wrappedException ? $this : $this->wrappedException;
$exception = $this->wrappedException ?? $this;

if (sfConfig::get('sf_debug')) {
$response = sfContext::getInstance()->getResponse();
Expand Down
Loading

0 comments on commit befc2bb

Please sign in to comment.