diff --git a/lib/action/sfAction.class.php b/lib/action/sfAction.class.php index cabab27f0..28d020e81 100644 --- a/lib/action/sfAction.class.php +++ b/lib/action/sfAction.class.php @@ -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); } @@ -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); } @@ -388,15 +388,7 @@ public function getSecurityValue($name, $default = null) { $actionName = strtolower($this->getActionName()); - if (isset($this->security[$actionName][$name])) { - return $this->security[$actionName][$name]; - } - - if (isset($this->security['all'][$name])) { - return $this->security['all'][$name]; - } - - return $default; + return $this->security[$actionName][$name] ?? $this->security['all'][$name] ?? $default; } /** @@ -430,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) { @@ -516,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()); } } diff --git a/lib/action/sfActionStack.class.php b/lib/action/sfActionStack.class.php index 09242f6ef..9952a6694 100644 --- a/lib/action/sfActionStack.class.php +++ b/lib/action/sfActionStack.class.php @@ -49,13 +49,7 @@ public function addEntry($moduleName, $actionName, $actionInstance) */ public function getEntry($index) { - $retval = null; - - if ($index > -1 && $index < count($this->stack)) { - $retval = $this->stack[$index]; - } - - return $retval; + return $this->stack[$index] ?? null; } /** @@ -75,13 +69,7 @@ public function popEntry() */ public function getFirstEntry() { - $retval = null; - - if (isset($this->stack[0])) { - $retval = $this->stack[0]; - } - - return $retval; + return $this->stack[0] ?? null; } /** @@ -91,14 +79,7 @@ public function getFirstEntry() */ public function getLastEntry() { - $count = count($this->stack); - $retval = null; - - if (isset($this->stack[0])) { - $retval = $this->stack[$count - 1]; - } - - return $retval; + return $this->stack[count($this->stack) - 1] ?? null; } /** diff --git a/lib/autoload/sfAutoload.class.php b/lib/autoload/sfAutoload.class.php index de53e724c..1985b1b7d 100644 --- a/lib/autoload/sfAutoload.class.php +++ b/lib/autoload/sfAutoload.class.php @@ -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; } /** diff --git a/lib/autoload/sfSimpleAutoload.class.php b/lib/autoload/sfSimpleAutoload.class.php index 85674e7a0..fad08b7b9 100755 --- a/lib/autoload/sfSimpleAutoload.class.php +++ b/lib/autoload/sfSimpleAutoload.class.php @@ -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; } /** diff --git a/lib/cache/sfCache.class.php b/lib/cache/sfCache.class.php index 60b9a2858..aca6746d4 100644 --- a/lib/cache/sfCache.class.php +++ b/lib/cache/sfCache.class.php @@ -166,7 +166,7 @@ public function getMany($keys) */ public function getLifetime($lifetime) { - return null === $lifetime ? $this->getOption('lifetime') : $lifetime; + return $lifetime ?? $this->getOption('lifetime'); } /** @@ -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; } /** diff --git a/lib/cache/sfMemcacheCache.class.php b/lib/cache/sfMemcacheCache.class.php index 0caae1753..057b4d8c5 100644 --- a/lib/cache/sfMemcacheCache.class.php +++ b/lib/cache/sfMemcacheCache.class.php @@ -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)); } } @@ -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); diff --git a/lib/cache/sfSQLiteCache.class.php b/lib/cache/sfSQLiteCache.class.php index 30484ad2d..788be5e53 100644 --- a/lib/cache/sfSQLiteCache.class.php +++ b/lib/cache/sfSQLiteCache.class.php @@ -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; } /** @@ -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())); @@ -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())); diff --git a/lib/command/sfCommandApplication.class.php b/lib/command/sfCommandApplication.class.php index 15bad631d..b57ea28a6 100644 --- a/lib/command/sfCommandApplication.class.php +++ b/lib/command/sfCommandApplication.class.php @@ -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(); @@ -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; } /** @@ -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))); } diff --git a/lib/command/sfCommandLogger.class.php b/lib/command/sfCommandLogger.class.php index 77673b5c1..ae3178853 100644 --- a/lib/command/sfCommandLogger.class.php +++ b/lib/command/sfCommandLogger.class.php @@ -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()) { diff --git a/lib/config/sfAutoloadConfigHandler.class.php b/lib/config/sfAutoloadConfigHandler.class.php index 2b7cb7a5c..20b5257e4 100755 --- a/lib/config/sfAutoloadConfigHandler.class.php +++ b/lib/config/sfAutoloadConfigHandler.class.php @@ -134,7 +134,7 @@ 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 @@ -142,7 +142,7 @@ protected function parse(array $configFiles) $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); } @@ -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'] ?? '')); } } } diff --git a/lib/config/sfConfig.class.php b/lib/config/sfConfig.class.php index 2ad673ea7..9040d89ee 100644 --- a/lib/config/sfConfig.class.php +++ b/lib/config/sfConfig.class.php @@ -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; } /** diff --git a/lib/config/sfFactoryConfigHandler.class.php b/lib/config/sfFactoryConfigHandler.class.php index 95e067f7b..548095b00 100644 --- a/lib/config/sfFactoryConfigHandler.class.php +++ b/lib/config/sfFactoryConfigHandler.class.php @@ -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']); } diff --git a/lib/config/sfFilterConfigHandler.class.php b/lib/config/sfFilterConfigHandler.class.php index d9d221e27..8461b4668 100644 --- a/lib/config/sfFilterConfigHandler.class.php +++ b/lib/config/sfFilterConfigHandler.class.php @@ -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) { diff --git a/lib/config/sfGeneratorConfigHandler.class.php b/lib/config/sfGeneratorConfigHandler.class.php index 32279c9c1..3b5f28397 100644 --- a/lib/config/sfGeneratorConfigHandler.class.php +++ b/lib/config/sfGeneratorConfigHandler.class.php @@ -35,18 +35,18 @@ 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)); } } @@ -54,7 +54,7 @@ public function execute($configFiles) $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); diff --git a/lib/config/sfPluginConfiguration.class.php b/lib/config/sfPluginConfiguration.class.php index aa80e077d..5d1ba422c 100644 --- a/lib/config/sfPluginConfiguration.class.php +++ b/lib/config/sfPluginConfiguration.class.php @@ -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(); diff --git a/lib/config/sfProjectConfiguration.class.php b/lib/config/sfProjectConfiguration.class.php index 68f006e20..17aea4eff 100644 --- a/lib/config/sfProjectConfiguration.class.php +++ b/lib/config/sfProjectConfiguration.class.php @@ -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'); diff --git a/lib/config/sfRoutingConfigHandler.class.php b/lib/config/sfRoutingConfigHandler.class.php index f917bd4ab..91541962e 100644 --- a/lib/config/sfRoutingConfigHandler.class.php +++ b/lib/config/sfRoutingConfigHandler.class.php @@ -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'] ?? [], ]]; } } diff --git a/lib/config/sfYamlConfigHandler.class.php b/lib/config/sfYamlConfigHandler.class.php index d1ea1e798..018435c46 100644 --- a/lib/config/sfYamlConfigHandler.class.php +++ b/lib/config/sfYamlConfigHandler.class.php @@ -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) diff --git a/lib/debug/sfWebDebug.class.php b/lib/debug/sfWebDebug.class.php index 3e1d2258b..0a83f0614 100644 --- a/lib/debug/sfWebDebug.class.php +++ b/lib/debug/sfWebDebug.class.php @@ -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; } /** @@ -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 = []; diff --git a/lib/debug/sfWebDebugPanel.class.php b/lib/debug/sfWebDebugPanel.class.php index 487feac49..c1399e843 100644 --- a/lib/debug/sfWebDebugPanel.class.php +++ b/lib/debug/sfWebDebugPanel.class.php @@ -112,8 +112,8 @@ public function getToggleableDebugStack($debugStack) $html = $this->getToggler($element, 'Toggle debug stack'); $html .= '