Skip to content

Commit befc2bb

Browse files
committed
[rector] improvement: use null coalescing operator
1 parent 4e19251 commit befc2bb

File tree

124 files changed

+322
-322
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+322
-322
lines changed

Diff for: lib/action/sfAction.class.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public function getPartial($templateName, $vars = null)
290290
{
291291
$this->getContext()->getConfiguration()->loadHelpers('Partial');
292292

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

295295
return get_partial($templateName, $vars);
296296
}
@@ -333,7 +333,7 @@ public function getComponent($moduleName, $componentName, $vars = null)
333333
{
334334
$this->getContext()->getConfiguration()->loadHelpers('Partial');
335335

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

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

428428
if (null !== $module) {
@@ -508,6 +508,6 @@ public function getRoute()
508508
*/
509509
protected function get404Message($message = null)
510510
{
511-
return null === $message ? sprintf('This request has been forwarded to a 404 error page by the action "%s/%s".', $this->getModuleName(), $this->getActionName()) : $message;
511+
return $message ?? sprintf('This request has been forwarded to a 404 error page by the action "%s/%s".', $this->getModuleName(), $this->getActionName());
512512
}
513513
}

Diff for: lib/autoload/sfAutoload.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function getClassPath($class)
9090
{
9191
$class = strtolower($class);
9292

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

9696
/**

Diff for: lib/autoload/sfSimpleAutoload.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public function getClassPath($class)
279279
{
280280
$class = strtolower($class);
281281

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

285285
/**

Diff for: lib/cache/sfCache.class.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function getMany($keys)
166166
*/
167167
public function getLifetime($lifetime)
168168
{
169-
return null === $lifetime ? $this->getOption('lifetime') : $lifetime;
169+
return $lifetime ?? $this->getOption('lifetime');
170170
}
171171

172172
/**
@@ -191,7 +191,7 @@ public function getBackend()
191191
*/
192192
public function getOption($name, $default = null)
193193
{
194-
return isset($this->options[$name]) ? $this->options[$name] : $default;
194+
return $this->options[$name] ?? $default;
195195
}
196196

197197
/**

Diff for: lib/cache/sfMemcacheCache.class.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public function initialize($options = [])
5050

5151
if ($this->getOption('servers')) {
5252
foreach ($this->getOption('servers') as $server) {
53-
$port = isset($server['port']) ? $server['port'] : 11211;
54-
if (!$this->memcache->addServer($server['host'], $port, isset($server['persistent']) ? $server['persistent'] : true)) {
53+
$port = $server['port'] ?? 11211;
54+
if (!$this->memcache->addServer($server['host'], $port, $server['persistent'] ?? true)) {
5555
throw new sfInitializationException(sprintf('Unable to connect to the memcache server (%s:%s).', $server['host'], $port));
5656
}
5757
}
@@ -106,7 +106,7 @@ public function has($key)
106106
*/
107107
public function set($key, $data, $lifetime = null)
108108
{
109-
$lifetime = null === $lifetime ? $this->getOption('lifetime') : $lifetime;
109+
$lifetime ??= $this->getOption('lifetime');
110110

111111
// save metadata
112112
$this->setMetadata($key, $lifetime);

Diff for: lib/cache/sfSQLiteCache.class.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function get($key, $default = null)
7070
$data = $this->dbh->singleQuery(sprintf("SELECT data FROM cache WHERE key = '%s' AND timeout > %d", sqlite_escape_string($key), time()));
7171
}
7272

73-
return null === $data ? $default : $data;
73+
return $data ?? $default;
7474
}
7575

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

156-
return null === $rs ? 0 : $rs;
156+
return $rs ?? 0;
157157
}
158158

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

172-
return null === $rs ? 0 : $rs;
172+
return $rs ?? 0;
173173
}
174174

175175
$rs = $this->dbh->query(sprintf("SELECT last_modified FROM cache WHERE key = '%s' AND timeout > %d", sqlite_escape_string($key), time()));

Diff for: lib/command/sfCommandApplication.class.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ abstract class sfCommandApplication
6363
public function __construct(sfEventDispatcher $dispatcher, ?sfFormatter $formatter = null, $options = [])
6464
{
6565
$this->dispatcher = $dispatcher;
66-
$this->formatter = null === $formatter ? $this->guessBestFormatter(STDOUT) : $formatter;
66+
$this->formatter = $formatter ?? $this->guessBestFormatter(STDOUT);
6767
$this->options = $options;
6868

6969
$this->fixCgi();
@@ -100,7 +100,7 @@ abstract public function configure();
100100
*/
101101
public function getOption($name)
102102
{
103-
return isset($this->options[$name]) ? $this->options[$name] : null;
103+
return $this->options[$name] ?? null;
104104
}
105105

106106
/**
@@ -396,11 +396,11 @@ public function renderException($e)
396396
]);
397397

398398
for ($i = 0, $count = count($trace); $i < $count; ++$i) {
399-
$class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
400-
$type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
399+
$class = $trace[$i]['class'] ?? '';
400+
$type = $trace[$i]['type'] ?? '';
401401
$function = $trace[$i]['function'];
402-
$file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
403-
$line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
402+
$file = $trace[$i]['file'] ?? 'n/a';
403+
$line = $trace[$i]['line'] ?? 'n/a';
404404

405405
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)));
406406
}

Diff for: lib/command/sfCommandLogger.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function initialize(sfEventDispatcher $dispatcher, $options = [])
3333
*/
3434
public function listenToLogEvent(sfEvent $event)
3535
{
36-
$priority = isset($event['priority']) ? $event['priority'] : self::INFO;
36+
$priority = $event['priority'] ?? self::INFO;
3737

3838
$prefix = '';
3939
if ('application.log' == $event->getName()) {

Diff for: lib/config/sfAutoloadConfigHandler.class.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ protected function parse(array $configFiles)
134134
}
135135
} else {
136136
// directory mapping
137-
$ext = isset($entry['ext']) ? $entry['ext'] : '.php';
137+
$ext = $entry['ext'] ?? '.php';
138138
$path = $entry['path'];
139139

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

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

155155
if ($matches = glob($path)) {
156156
foreach ($finder->in($matches) as $file) {
157-
$mapping = array_merge($mapping, $this->parseFile($path, $file, isset($entry['prefix']) ? $entry['prefix'] : ''));
157+
$mapping = array_merge($mapping, $this->parseFile($path, $file, $entry['prefix'] ?? ''));
158158
}
159159
}
160160
}

Diff for: lib/config/sfConfig.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class sfConfig
2727
*/
2828
public static function get($name, $default = null)
2929
{
30-
return isset(self::$config[$name]) ? self::$config[$name] : $default;
30+
return self::$config[$name] ?? $default;
3131
}
3232

3333
/**

Diff for: lib/config/sfFactoryConfigHandler.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function execute($configFiles)
9797
$defaultParameters = [];
9898
$defaultParameters[] = sprintf("'auto_shutdown' => false, 'session_id' => \$this->getRequest()->getParameter('%s'),", $parameters['session_name']);
9999
if (is_subclass_of($class, 'sfDatabaseSessionStorage')) {
100-
$defaultParameters[] = sprintf("'database' => \$this->getDatabaseManager()->getDatabase('%s'),", isset($parameters['database']) ? $parameters['database'] : 'default');
100+
$defaultParameters[] = sprintf("'database' => \$this->getDatabaseManager()->getDatabase('%s'),", $parameters['database'] ?? 'default');
101101
unset($parameters['database']);
102102
}
103103

Diff for: lib/config/sfFilterConfigHandler.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function execute($configFiles)
6868
unset($keys['param']['condition']);
6969
}
7070

71-
$type = isset($keys['param']['type']) ? $keys['param']['type'] : null;
71+
$type = $keys['param']['type'] ?? null;
7272
unset($keys['param']['type']);
7373

7474
if ($condition) {

Diff for: lib/config/sfGeneratorConfigHandler.class.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,26 @@ public function execute($configFiles)
3535
}
3636

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

4141
$config = $config['generator'];
4242

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

4747
foreach (['fields', 'list', 'edit'] as $section) {
4848
if (isset($config[$section])) {
49-
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));
49+
throw new sfParseException(sprintf('Configuration file "%s" can specify a "%s" section but only under the param section.', $configFiles[1] ?? $configFiles[0], $section));
5050
}
5151
}
5252

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

5656
// generator parameters
57-
$generatorParam = (isset($config['param']) ? $config['param'] : []);
57+
$generatorParam = ($config['param'] ?? []);
5858

5959
// hack to find the module name (look for the last /modules/ in path)
6060
preg_match('#.*/modules/([^/]+)/#', str_replace('\\', '/', $configFiles[0]), $match);

Diff for: lib/config/sfPluginConfiguration.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(sfProjectConfiguration $configuration, $rootDir = nu
3232
$this->configuration = $configuration;
3333
$this->dispatcher = $configuration->getEventDispatcher();
3434
$this->rootDir = null === $rootDir ? $this->guessRootDir() : realpath($rootDir);
35-
$this->name = null === $name ? $this->guessName() : $name;
35+
$this->name = $name ?? $this->guessName();
3636

3737
$this->setup();
3838
$this->configure();

Diff for: lib/config/sfProjectConfiguration.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct($rootDir = null, ?sfEventDispatcher $dispatcher = nu
5656

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

6161
ini_set('magic_quotes_runtime', 'off');
6262

Diff for: lib/config/sfRoutingConfigHandler.class.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,17 @@ protected function parse($configFiles)
9191
(isset($params['type']) && 'collection' == $params['type'])
9292
|| (isset($params['class']) && false !== strpos($params['class'], 'Collection'))
9393
) {
94-
$options = isset($params['options']) ? $params['options'] : [];
94+
$options = $params['options'] ?? [];
9595
$options['name'] = $name;
96-
$options['requirements'] = isset($params['requirements']) ? $params['requirements'] : [];
96+
$options['requirements'] = $params['requirements'] ?? [];
9797

98-
$routes[$name] = [isset($params['class']) ? $params['class'] : 'sfRouteCollection', [$options]];
98+
$routes[$name] = [$params['class'] ?? 'sfRouteCollection', [$options]];
9999
} else {
100-
$routes[$name] = [isset($params['class']) ? $params['class'] : 'sfRoute', [
100+
$routes[$name] = [$params['class'] ?? 'sfRoute', [
101101
$params['url'] ?: '/',
102-
isset($params['params']) ? $params['params'] : (isset($params['param']) ? $params['param'] : []),
103-
isset($params['requirements']) ? $params['requirements'] : [],
104-
isset($params['options']) ? $params['options'] : [],
102+
$params['params'] ?? $params['param'] ?? [],
103+
$params['requirements'] ?? [],
104+
$params['options'] ?? [],
105105
]];
106106
}
107107
}

Diff for: lib/config/sfYamlConfigHandler.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static function parseYaml($configFile)
6969
throw new sfParseException(sprintf('Configuration file "%s" could not be parsed', $configFile));
7070
}
7171

72-
return null === $config ? [] : $config;
72+
return $config ?? [];
7373
}
7474

7575
public static function flattenConfiguration($config)

Diff for: lib/debug/sfWebDebug.class.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function removePanel($name)
134134
*/
135135
public function getOption($name, $default = null)
136136
{
137-
return isset($this->options[$name]) ? $this->options[$name] : $default;
137+
return $this->options[$name] ?? $default;
138138
}
139139

140140
/**
@@ -178,7 +178,7 @@ public function injectToolbar($content)
178178
*/
179179
public function asHtml()
180180
{
181-
$current = isset($this->options['request_parameters']['sfWebDebugPanel']) ? $this->options['request_parameters']['sfWebDebugPanel'] : null;
181+
$current = $this->options['request_parameters']['sfWebDebugPanel'] ?? null;
182182

183183
$titles = [];
184184
$panels = [];

Diff for: lib/debug/sfWebDebugPanel.class.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ public function getToggleableDebugStack($debugStack)
112112
$html = $this->getToggler($element, 'Toggle debug stack');
113113
$html .= '<div class="sfWebDebugDebugInfo" id="'.$element.'" style="display:none">';
114114
foreach ($debugStack as $j => $trace) {
115-
$file = isset($trace['file']) ? $trace['file'] : null;
116-
$line = isset($trace['line']) ? $trace['line'] : null;
115+
$file = $trace['file'] ?? null;
116+
$line = $trace['line'] ?? null;
117117

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

@@ -122,8 +122,8 @@ public function getToggleableDebugStack($debugStack)
122122
if (isset($trace['function'])) {
123123
$html .= sprintf(
124124
'in <span class="sfWebDebugLogInfo">%s%s%s()</span> ',
125-
isset($trace['class']) ? $trace['class'] : '',
126-
isset($trace['type']) ? $trace['type'] : '',
125+
$trace['class'] ?? '',
126+
$trace['type'] ?? '',
127127
$trace['function']
128128
);
129129
}
@@ -166,7 +166,7 @@ public function formatFileLink($file, $line = null, $text = null)
166166
'<a href="%s" class="sfWebDebugFileLink" title="%s">%s</a>',
167167
htmlspecialchars(strtr($linkFormat, ['%f' => $file, '%l' => $line]), ENT_QUOTES, sfConfig::get('sf_charset')),
168168
htmlspecialchars($shortFile, ENT_QUOTES, sfConfig::get('sf_charset')),
169-
null === $text ? $shortFile : $text
169+
$text ?? $shortFile
170170
);
171171
}
172172
if (null === $text) {

Diff for: lib/escaper/sfOutputEscaperArrayDecorator.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function offsetExists($offset)
120120
#[\ReturnTypeWillChange]
121121
public function offsetGet($offset)
122122
{
123-
$value = isset($this->value[$offset]) ? $this->value[$offset] : null;
123+
$value = $this->value[$offset] ?? null;
124124

125125
return sfOutputEscaper::escape($this->escapingMethod, $value);
126126
}

Diff for: lib/exception/data/error.html.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
22

3-
<?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'] : ''))); ?>
3+
<?php $path = sfConfig::get('sf_relative_url_root', preg_replace('#/[^/]+\.php5?$#', '', $_SERVER['SCRIPT_NAME'] ?? $_SERVER['ORIG_SCRIPT_NAME'] ?? '')); ?>
44

55
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
66
<head>

Diff for: lib/exception/data/unavailable.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
22

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

55
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
66
<head>

Diff for: lib/exception/sfError404Exception.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class sfError404Exception extends sfException
2020
*/
2121
public function printStackTrace()
2222
{
23-
$exception = null === $this->wrappedException ? $this : $this->wrappedException;
23+
$exception = $this->wrappedException ?? $this;
2424

2525
if (sfConfig::get('sf_debug')) {
2626
$response = sfContext::getInstance()->getResponse();

0 commit comments

Comments
 (0)