10000 [rector] improvement: use null coalescing operator · FriendsOfSymfony1/symfony1@befc2bb · GitHub
[go: up one dir, main page]

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

lib/action/sfAction.class.php

Lines changed: 4 additions & 4 deletions
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
}

lib/autoload/sfAutoload.class.php

Lines changed: 1 addition & 1 deletion
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
/**

lib/autoload/sfSimpleAutoload.class.php

Lines changed: 1 addition & 1 deletion
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
/**

lib/cache/sfCache.class.php

Lines changed: 2 additions & 2 deletions
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
/**

lib/cache/sfMemcacheCache.class.php

Lines changed: 3 additions & 3 deletions
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);

lib/cache/sfSQLiteCache.class.php

Lines changed: 3 additions & 3 deletions
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()));

lib/command/sfCommandApplication.class.php

Lines changed: 6 additions & 6 deletions
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
}

lib/command/sfCommandLogger.class.php

Lines changed: 1 addition & 1 deletion
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()) {

lib/config/sfAutoloadConfigHandler.class.php

Lines changed: 3 additions & 3 deletions
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
}

lib/config/sfConfig.class.php

Lines changed: 1 addition & 1 deletion
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
/**

0 commit comments

Comments
 (0)
0