diff --git a/composer.json b/composer.json
index 046faefcf83a..bb51819c9849 100644
--- a/composer.json
+++ b/composer.json
@@ -29,7 +29,7 @@
"phpunit/phpcov": "^9.0.2 || ^10.0",
"phpunit/phpunit": "^10.5.16 || ^11.2",
"predis/predis": "^3.0",
- "rector/rector": "2.6.3",
+ "rector/rector": "2.6.4",
"shipmonk/phpstan-baseline-per-identifier": "^2.0"
},
"replace": {
diff --git a/system/BaseModel.php b/system/BaseModel.php
index 5579bd8f810a..64d083fe4d2b 100644
--- a/system/BaseModel.php
+++ b/system/BaseModel.php
@@ -1648,9 +1648,7 @@ public function getValidationRules(array $options = []): array
protected function ensureValidation(): void
{
- if ($this->validation === null) {
- $this->validation = service('validation', null, false);
- }
+ $this->validation ??= service('validation', null, false);
}
/**
diff --git a/system/CLI/SignalTrait.php b/system/CLI/SignalTrait.php
index 0490e15d9d55..792f7334f865 100644
--- a/system/CLI/SignalTrait.php
+++ b/system/CLI/SignalTrait.php
@@ -81,9 +81,7 @@ protected function isPcntlAvailable(): bool
*/
protected function isPosixAvailable(): bool
{
- if (self::$isPosixAvailable === null) {
- self::$isPosixAvailable = is_windows() ? false : extension_loaded('posix');
- }
+ self::$isPosixAvailable ??= is_windows() ? false : extension_loaded('posix');
return self::$isPosixAvailable;
}
diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php
index 6fef8cbb6362..177edbd8d753 100644
--- a/system/CodeIgniter.php
+++ b/system/CodeIgniter.php
@@ -624,9 +624,7 @@ protected function bootstrapEnvironment()
*/
protected function startBenchmark()
{
- if ($this->startTime === null) {
- $this->startTime = microtime(true);
- }
+ $this->startTime ??= microtime(true);
$this->benchmark = Services::timer();
$this->benchmark->start('total_execution', $this->startTime);
diff --git a/system/Commands/ListCommands.php b/system/Commands/ListCommands.php
index c976733b768d..20ee5305ecaa 100644
--- a/system/Commands/ListCommands.php
+++ b/system/Commands/ListCommands.php
@@ -101,9 +101,7 @@ protected function listFull(array $commands)
$groups = [];
foreach ($commands as $title => $command) {
- if (! isset($groups[$command['group']])) {
- $groups[$command['group']] = [];
- }
+ $groups[$command['group']] ??= [];
$groups[$command['group']][$title] = $command;
}
diff --git a/system/Common.php b/system/Common.php
index 226c0554a6cf..72502d0fd5d0 100644
--- a/system/Common.php
+++ b/system/Common.php
@@ -490,9 +490,7 @@ function esc($data, string $context = 'html', ?string $encoding = null)
static $escapers = [];
$cacheKey = strtolower($encoding ?? 'utf-8');
- if (! isset($escapers[$cacheKey])) {
- $escapers[$cacheKey] = new Escaper($encoding);
- }
+ $escapers[$cacheKey] ??= new Escaper($encoding);
$data = $escapers[$cacheKey]->{$method}($data);
}
@@ -588,9 +586,7 @@ function function_usable(string $functionName): bool
static $_suhosin_func_blacklist;
if (function_exists($functionName)) {
- if (! isset($_suhosin_func_blacklist)) {
- $_suhosin_func_blacklist = extension_loaded('suhosin') ? explode(',', trim(ini_get('suhosin.executor.func.blacklist'))) : [];
- }
+ $_suhosin_func_blacklist ??= extension_loaded('suhosin') ? explode(',', trim(ini_get('suhosin.executor.func.blacklist'))) : [];
return ! in_array($functionName, $_suhosin_func_blacklist, true);
}
diff --git a/system/Config/BaseService.php b/system/Config/BaseService.php
index e5f46586a305..06cbabd10efd 100644
--- a/system/Config/BaseService.php
+++ b/system/Config/BaseService.php
@@ -276,9 +276,7 @@ protected static function getSharedInstance(string $key, ...$params)
public static function autoloader(bool $getShared = true)
{
if ($getShared) {
- if (! isset(static::$instances['autoloader'])) {
- static::$instances['autoloader'] = new Autoloader();
- }
+ static::$instances['autoloader'] ??= new Autoloader();
return static::$instances['autoloader'];
}
diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php
index 1d2055d9ca24..fe2c1c371816 100644
--- a/system/Database/BaseBuilder.php
+++ b/system/Database/BaseBuilder.php
@@ -1488,9 +1488,7 @@ public function orderBy(string $orderBy, string $direction = '', ?bool $escape =
$direction = in_array($direction, ['ASC', 'DESC'], true) ? ' ' . $direction : '';
}
- if ($escape === null) {
- $escape = $this->db->protectIdentifiers;
- }
+ $escape ??= $this->db->protectIdentifiers;
if ($escape === false) {
$qbOrderBy[] = [
diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php
index 98ec9df3e2b9..a7af22565cca 100644
--- a/system/Database/BaseConnection.php
+++ b/system/Database/BaseConnection.php
@@ -467,9 +467,7 @@ private function getBuiltinPropertyTypesMap(array $properties): array
$className = static::class;
$requested = array_fill_keys($properties, true);
- if (! isset(self::$propertyBuiltinTypesCache[$className])) {
- self::$propertyBuiltinTypesCache[$className] = [];
- }
+ self::$propertyBuiltinTypesCache[$className] ??= [];
// Fill only the properties requested by this call that are not cached yet.
$missing = array_diff_key($requested, self::$propertyBuiltinTypesCache[$className]);
@@ -1867,10 +1865,7 @@ protected function foreignKeyDataToObjects(array $data)
foreach ($data as $row) {
$name = $row['constraint_name'];
- // for sqlite generate name
- if ($name === null) {
- $name = $row['table_name'] . '_' . implode('_', $row['column_name']) . '_foreign';
- }
+ $name ??= $row['table_name'] . '_' . implode('_', $row['column_name']) . '_foreign';
$obj = new stdClass();
$obj->constraint_name = $name;
diff --git a/system/Database/BaseUtils.php b/system/Database/BaseUtils.php
index cf42bb7f7184..442fdd2a766b 100644
--- a/system/Database/BaseUtils.php
+++ b/system/Database/BaseUtils.php
@@ -233,9 +233,7 @@ public function getCSVFromResult(ResultInterface $query, string $delim = ',', st
public function getXMLFromResult(ResultInterface $query, array $params = []): string
{
foreach (['root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t"] as $key => $val) {
- if (! isset($params[$key])) {
- $params[$key] = $val;
- }
+ $params[$key] ??= $val;
}
$root = $params['root'];
diff --git a/system/Database/Config.php b/system/Database/Config.php
index 790c2fb63b12..250af22acd62 100644
--- a/system/Database/Config.php
+++ b/system/Database/Config.php
@@ -60,9 +60,7 @@ public static function connect($group = null, bool $getShared = true)
} else {
$dbConfig = config(DbConfig::class);
- if ($group === null) {
- $group = (ENVIRONMENT === 'testing') ? 'tests' : $dbConfig->defaultGroup;
- }
+ $group ??= (ENVIRONMENT === 'testing') ? 'tests' : $dbConfig->defaultGroup;
assert(is_string($group));
diff --git a/system/Database/Query.php b/system/Database/Query.php
index 294f143e57e8..41d21c93330d 100644
--- a/system/Database/Query.php
+++ b/system/Database/Query.php
@@ -161,9 +161,7 @@ public function setDuration(float $start, ?float $end = null): self
{
$this->startTime = $start;
- if ($end === null) {
- $end = microtime(true);
- }
+ $end ??= microtime(true);
$this->endTime = $end;
diff --git a/system/Database/SQLSRV/Connection.php b/system/Database/SQLSRV/Connection.php
index 5e82e7b2abf3..e18408c5c34d 100644
--- a/system/Database/SQLSRV/Connection.php
+++ b/system/Database/SQLSRV/Connection.php
@@ -47,7 +47,7 @@ class Connection extends BaseConnection
* FALSE or SQLSRV_CURSOR_FORWARD would increase performance,
* but would disable num_rows() (and possibly insert_id())
*
- * @var false|string
+ * @var false|string|null
*/
public $scrollable;
@@ -88,10 +88,7 @@ public function __construct(array $params)
{
parent::__construct($params);
- // This is only supported as of SQLSRV 3.0
- if ($this->scrollable === null) {
- $this->scrollable = defined('SQLSRV_CURSOR_CLIENT_BUFFERED') ? SQLSRV_CURSOR_CLIENT_BUFFERED : false;
- }
+ $this->scrollable ??= defined('SQLSRV_CURSOR_CLIENT_BUFFERED') ? SQLSRV_CURSOR_CLIENT_BUFFERED : false;
}
/**
diff --git a/system/Database/SQLite3/Builder.php b/system/Database/SQLite3/Builder.php
index d31cfb493967..be6bcbe1a0c5 100644
--- a/system/Database/SQLite3/Builder.php
+++ b/system/Database/SQLite3/Builder.php
@@ -242,7 +242,7 @@ protected function _deleteBatch(string $table, array $keys, array $values): stri
// @codeCoverageIgnore
}
- if (is_string(current(array_keys($constraints)))) {
+ if (is_string(array_key_first($constraints))) {
$concat1 = implode(' || ', array_keys($constraints));
$concat2 = implode(' || ', array_values($constraints));
} else {
diff --git a/system/Debug/BaseExceptionHandler.php b/system/Debug/BaseExceptionHandler.php
index 6adaa8eaaca9..48fd5b3404c8 100644
--- a/system/Debug/BaseExceptionHandler.php
+++ b/system/Debug/BaseExceptionHandler.php
@@ -48,9 +48,7 @@ public function __construct(ExceptionsConfig $config)
$this->obLevel = ob_get_level();
- if ($this->viewPath === null) {
- $this->viewPath = rtrim($this->config->errorViewPath, '\\/ ') . DIRECTORY_SEPARATOR;
- }
+ $this->viewPath ??= rtrim($this->config->errorViewPath, '\\/ ') . DIRECTORY_SEPARATOR;
}
/**
diff --git a/system/Debug/Timer.php b/system/Debug/Timer.php
index be4b56ce7cc8..9b6af4d4bcd0 100644
--- a/system/Debug/Timer.php
+++ b/system/Debug/Timer.php
@@ -96,9 +96,7 @@ public function getElapsedTime(string $name, int $decimals = 4)
$timer = $this->timers[$name];
- if ($timer['end'] === null) {
- $timer['end'] = microtime(true);
- }
+ $timer['end'] ??= microtime(true);
return (float) number_format($timer['end'] - $timer['start'], $decimals, '.', '');
}
@@ -115,9 +113,7 @@ public function getTimers(int $decimals = 4): array
$timers = $this->timers;
foreach ($timers as &$timer) {
- if ($timer['end'] === null) {
- $timer['end'] = microtime(true);
- }
+ $timer['end'] ??= microtime(true);
$timer['duration'] = (float) number_format($timer['end'] - $timer['start'], $decimals);
}
diff --git a/system/Email/Email.php b/system/Email/Email.php
index a3d948d9edfd..9304734fd179 100644
--- a/system/Email/Email.php
+++ b/system/Email/Email.php
@@ -418,9 +418,7 @@ public function __construct($config = null)
{
$this->initialize($config);
- if (! isset(static::$func_overload)) {
- static::$func_overload = extension_loaded('mbstring') && ini_get('mbstring.func_overload');
- }
+ static::$func_overload ??= extension_loaded('mbstring') && ini_get('mbstring.func_overload');
}
/**
@@ -1461,10 +1459,7 @@ protected function prepQEncoding($str)
}
}
- // We might already have this set for UTF-8
- if (! isset($chars)) {
- $chars = static::strlen($str);
- }
+ $chars ??= static::strlen($str);
$output = '=?' . $this->charset . '?Q?';
diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php
index 973b9ded7979..36725b8198d3 100644
--- a/system/Filters/Filters.php
+++ b/system/Filters/Filters.php
@@ -556,13 +556,9 @@ public function addFilter(string $class, ?string $alias = null, string $position
{
$alias ??= md5($class);
- if (! isset($this->config->{$section})) {
- $this->config->{$section} = [];
- }
+ $this->config->{$section} ??= [];
- if (! isset($this->config->{$section}[$position])) {
- $this->config->{$section}[$position] = [];
- }
+ $this->config->{$section}[$position] ??= [];
$this->config->aliases[$alias] = $class;
diff --git a/system/HTTP/IncomingRequest.php b/system/HTTP/IncomingRequest.php
index f630767bcc35..5eb029df8385 100644
--- a/system/HTTP/IncomingRequest.php
+++ b/system/HTTP/IncomingRequest.php
@@ -208,9 +208,7 @@ public function detectLocale($config)
*/
public function negotiate(string $type, array $supported, bool $strictMatch = false): string
{
- if ($this->negotiator === null) {
- $this->negotiator = Services::negotiator($this, true);
- }
+ $this->negotiator ??= Services::negotiator($this, true);
return match (strtolower($type)) {
'media' => $this->negotiator->media($supported, $strictMatch),
@@ -750,9 +748,7 @@ public function getOldInput(string $key)
*/
public function getFiles(): array
{
- if ($this->files === null) {
- $this->files = new FileCollection();
- }
+ $this->files ??= new FileCollection();
return $this->files->all(); // return all files
}
@@ -765,9 +761,7 @@ public function getFiles(): array
*/
public function getFileMultiple(string $fileID)
{
- if ($this->files === null) {
- $this->files = new FileCollection();
- }
+ $this->files ??= new FileCollection();
return $this->files->getFileMultiple($fileID);
}
@@ -780,9 +774,7 @@ public function getFileMultiple(string $fileID)
*/
public function getFile(string $fileID)
{
- if ($this->files === null) {
- $this->files = new FileCollection();
- }
+ $this->files ??= new FileCollection();
return $this->files->getFile($fileID);
}
diff --git a/system/HTTP/RequestTrait.php b/system/HTTP/RequestTrait.php
index c08d1d0bb808..973757c8559e 100644
--- a/system/HTTP/RequestTrait.php
+++ b/system/HTTP/RequestTrait.php
@@ -338,9 +338,7 @@ public function fetchGlobal(string $name, $index = null, ?int $filter = null, $f
}
}
- if (! isset($value)) {
- $value = $this->globals[$name][$index] ?? null;
- }
+ $value ??= $this->globals[$name][$index] ?? null;
if (is_array($value)
&& (
@@ -379,9 +377,7 @@ public function fetchGlobal(string $name, $index = null, ?int $filter = null, $f
*/
protected function populateGlobals(string $name)
{
- if (! isset($this->globals[$name])) {
- $this->globals[$name] = [];
- }
+ $this->globals[$name] ??= [];
// Get data from Superglobals service instead of direct access
$this->globals[$name] = service('superglobals')->getGlobalArray($name);
diff --git a/system/HTTP/ResponseTrait.php b/system/HTTP/ResponseTrait.php
index 50a8ab8c319e..5b7e02c2a954 100644
--- a/system/HTTP/ResponseTrait.php
+++ b/system/HTTP/ResponseTrait.php
@@ -475,9 +475,7 @@ public function redirect(string $uri, string $method = 'auto', ?int $code = null
}
}
- if ($code === null) {
- $code = 302;
- }
+ $code ??= 302;
match ($method) {
'refresh' => $this->setHeader('Refresh', '0;url=' . $uri),
diff --git a/system/HTTP/URI.php b/system/HTTP/URI.php
index 3b91a8e18e8a..4b8b324dc80e 100644
--- a/system/HTTP/URI.php
+++ b/system/HTTP/URI.php
@@ -697,9 +697,7 @@ public function setAuthority(string $str)
{
$parts = parse_url($str);
- if (! isset($parts['path'])) {
- $parts['path'] = $this->getPath();
- }
+ $parts['path'] ??= $this->getPath();
if (! isset($parts['host']) && $parts['path'] !== '') {
$parts['host'] = $parts['path'];
diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php
index fc67aac601bf..1cf120acb78a 100644
--- a/system/Helpers/form_helper.php
+++ b/system/Helpers/form_helper.php
@@ -565,9 +565,7 @@ function set_value(string $field, $default = '', bool $htmlEscape = true)
// Try any old input data we may have first
$value = $request->getOldInput($field);
- if ($value === null) {
- $value = $request->getPost($field) ?? $default;
- }
+ $value ??= $request->getPost($field) ?? $default;
return ($htmlEscape) ? esc($value) : $value;
}
@@ -586,9 +584,7 @@ function set_select(string $field, string $value = '', bool $default = false): s
// Try any old input data we may have first
$input = $request->getOldInput($field);
- if ($input === null) {
- $input = $request->getPost($field);
- }
+ $input ??= $request->getPost($field);
if ($input === null) {
return $default ? ' selected="selected"' : '';
@@ -622,9 +618,7 @@ function set_checkbox(string $field, string $value = '', bool $default = false):
// Try any old input data we may have first
$input = $request->getOldInput($field);
- if ($input === null) {
- $input = $request->getPost($field);
- }
+ $input ??= $request->getPost($field);
if (is_array($input)) {
// Note: in_array('', array(0)) returns TRUE, do not use it
diff --git a/system/Helpers/html_helper.php b/system/Helpers/html_helper.php
index e206cbd0f5e5..9f0b86470aa8 100644
--- a/system/Helpers/html_helper.php
+++ b/system/Helpers/html_helper.php
@@ -102,12 +102,8 @@ function img($src = '', bool $indexPage = false, $attributes = ''): string
if (! is_array($src)) {
$src = ['src' => $src];
}
- if (! isset($src['src'])) {
- $src['src'] = $attributes['src'] ?? '';
- }
- if (! isset($src['alt'])) {
- $src['alt'] = $attributes['alt'] ?? '';
- }
+ $src['src'] ??= $attributes['src'] ?? '';
+ $src['alt'] ??= $attributes['alt'] ?? '';
$img = 'getUri()->getHost();
- }
+ $host ??= service('request')->getUri()->getHost();
// Handle localhost and IP addresses - they don't have subdomains
if ($host === 'localhost' || filter_var($host, FILTER_VALIDATE_IP)) {
diff --git a/system/Images/Handlers/BaseHandler.php b/system/Images/Handlers/BaseHandler.php
index 334075701465..906fc9f0b8e3 100644
--- a/system/Images/Handlers/BaseHandler.php
+++ b/system/Images/Handlers/BaseHandler.php
@@ -538,9 +538,7 @@ public function fit(int $width, ?int $height = null, string $position = 'center'
[$cropWidth, $cropHeight] = $this->calcAspectRatio($width, $height, $origWidth, $origHeight);
- if ($height === null) {
- $height = (int) ceil(($width / $cropWidth) * $cropHeight);
- }
+ $height ??= (int) ceil(($width / $cropWidth) * $cropHeight);
[$x, $y] = $this->calcCropCoords($cropWidth, $cropHeight, $origWidth, $origHeight, $position);
diff --git a/system/Images/Handlers/GDHandler.php b/system/Images/Handlers/GDHandler.php
index 2ba97437edda..f565ee317963 100644
--- a/system/Images/Handlers/GDHandler.php
+++ b/system/Images/Handlers/GDHandler.php
@@ -301,12 +301,10 @@ protected function createImage(string $path = '', string $imageType = '')
*/
protected function ensureResource()
{
- if ($this->resource === null) {
- $this->resource = $this->getImageResource(
- $this->image()->getPathname(),
- $this->image()->imageType,
- );
- }
+ $this->resource ??= $this->getImageResource(
+ $this->image()->getPathname(),
+ $this->image()->imageType,
+ );
}
/**
diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php
index 198168675fad..6ade80e6f9fc 100644
--- a/system/Router/RouteCollection.php
+++ b/system/Router/RouteCollection.php
@@ -1512,9 +1512,7 @@ private function checkSubdomains($subdomains): bool
return false;
}
- if ($this->currentSubdomain === null) {
- $this->currentSubdomain = parse_subdomain($this->httpHost);
- }
+ $this->currentSubdomain ??= parse_subdomain($this->httpHost);
if (! is_array($subdomains)) {
$subdomains = [$subdomains];
diff --git a/system/Session/Handlers/DatabaseHandler.php b/system/Session/Handlers/DatabaseHandler.php
index c4ce2b8222e7..433e85ba3cdc 100644
--- a/system/Session/Handlers/DatabaseHandler.php
+++ b/system/Session/Handlers/DatabaseHandler.php
@@ -115,9 +115,7 @@ public function read($id): false|string
return '';
}
- if (! isset($this->sessionID)) {
- $this->sessionID = $id;
- }
+ $this->sessionID ??= $id;
$builder = $this->db->table($this->table)->where('id', $this->idPrefix . $id);
diff --git a/system/Session/Handlers/FileHandler.php b/system/Session/Handlers/FileHandler.php
index a985b5f89793..0924aac43904 100644
--- a/system/Session/Handlers/FileHandler.php
+++ b/system/Session/Handlers/FileHandler.php
@@ -134,9 +134,7 @@ public function read($id): false|string
return false;
}
- if (! isset($this->sessionID)) {
- $this->sessionID = $id;
- }
+ $this->sessionID ??= $id;
if ($this->fileNew) {
chmod($this->filePath . $id, 0600);
diff --git a/system/Session/Handlers/MemcachedHandler.php b/system/Session/Handlers/MemcachedHandler.php
index 7b7775916019..c64ba65f6454 100644
--- a/system/Session/Handlers/MemcachedHandler.php
+++ b/system/Session/Handlers/MemcachedHandler.php
@@ -163,9 +163,7 @@ public function open($path, $name): bool
public function read($id): false|string
{
if (isset($this->memcached) && $this->lockSession($id)) {
- if (! isset($this->sessionID)) {
- $this->sessionID = $id;
- }
+ $this->sessionID ??= $id;
$data = (string) $this->memcached->get($this->keyPrefix . $id);
diff --git a/system/Session/Handlers/RedisHandler.php b/system/Session/Handlers/RedisHandler.php
index d1c3c02e6fe4..a6cce214f6d3 100644
--- a/system/Session/Handlers/RedisHandler.php
+++ b/system/Session/Handlers/RedisHandler.php
@@ -228,9 +228,7 @@ public function open($path, $name): bool
public function read($id): false|string
{
if (isset($this->redis) && $this->lockSession($id)) {
- if (! isset($this->sessionID)) {
- $this->sessionID = $id;
- }
+ $this->sessionID ??= $id;
$data = $this->redis->get($this->keyPrefix . $id);
diff --git a/system/Test/CIUnitTestCase.php b/system/Test/CIUnitTestCase.php
index 92b5d8631bf2..d86e543a9a61 100644
--- a/system/Test/CIUnitTestCase.php
+++ b/system/Test/CIUnitTestCase.php
@@ -283,9 +283,7 @@ protected function tearDown(): void
*/
private function callTraitMethods(string $stage): void
{
- if ($this->traits === null) {
- $this->traits = class_uses_recursive($this);
- }
+ $this->traits ??= class_uses_recursive($this);
foreach ($this->traits as $trait) {
$method = $stage . class_basename($trait);
diff --git a/system/Test/Fabricator.php b/system/Test/Fabricator.php
index c7cf97780fdc..c0b925d3cf66 100644
--- a/system/Test/Fabricator.php
+++ b/system/Test/Fabricator.php
@@ -129,10 +129,7 @@ public function __construct($model, ?array $formatters = null, ?string $locale =
$this->model = $model;
- // If no locale was specified then use the App default
- if ($locale === null) {
- $locale = config(App::class)->defaultLocale;
- }
+ $locale ??= config(App::class)->defaultLocale;
// There is no easy way to retrieve the locale from Faker so we will store it
$this->locale = $locale;
diff --git a/system/Test/FilterTestTrait.php b/system/Test/FilterTestTrait.php
index ac97db432133..554c9fd472ef 100644
--- a/system/Test/FilterTestTrait.php
+++ b/system/Test/FilterTestTrait.php
@@ -102,9 +102,7 @@ protected function setUpFilterTestTrait(): void
$this->filtersConfig ??= config(FiltersConfig::class);
$this->filters ??= new Filters($this->filtersConfig, $this->request, $this->response);
- if ($this->collection === null) {
- $this->collection = service('routes')->loadRoutes();
- }
+ $this->collection ??= service('routes')->loadRoutes();
$this->doneFilterSetUp = true;
}
diff --git a/system/Typography/Typography.php b/system/Typography/Typography.php
index e2adc4cd5057..66a13a0b3f06 100644
--- a/system/Typography/Typography.php
+++ b/system/Typography/Typography.php
@@ -236,44 +236,42 @@ public function formatCharacters(string $str): string
{
static $table;
- if (! isset($table)) {
- $table = [
- // nested smart quotes, opening and closing
- // note that rules for grammar (English) allow only for two levels deep
- // and that single quotes are _supposed_ to always be on the outside
- // but we'll accommodate both
- // Note that in all cases, whitespace is the primary determining factor
- // on which direction to curl, with non-word characters like punctuation
- // being a secondary factor only after whitespace is addressed.
- '/\'"(\s|$)/' => '’”$1',
- '/(^|\s|
)\'"/' => '$1‘“', - '/\'"(\W)/' => '’”$1', - '/(\W)\'"/' => '$1‘“', - '/"\'(\s|$)/' => '”’$1', - '/(^|\s|
)"\'/' => '$1“‘', - '/"\'(\W)/' => '”’$1', - '/(\W)"\'/' => '$1“‘', - // single quote smart quotes - '/\'(\s|$)/' => '’$1', - '/(^|\s|
)\'/' => '$1‘', - '/\'(\W)/' => '’$1', - '/(\W)\'/' => '$1‘', - // double quote smart quotes - '/"(\s|$)/' => '”$1', - '/(^|\s|
)"/' => '$1“', - '/"(\W)/' => '”$1', - '/(\W)"/' => '$1“', - // apostrophes - '/(\w)\'(\w)/' => '$1’$2', - // Em dash and ellipses dots - '/\s?\-\-\s?/' => '—', - '/(\w)\.{3}/' => '$1…', - // double space after sentences - '/(\W) /' => '$1 ', - // ampersands, if not a character entity - '/&(?!#?[a-zA-Z0-9]{2,};)/' => '&', - ]; - } + $table ??= [ + // nested smart quotes, opening and closing + // note that rules for grammar (English) allow only for two levels deep + // and that single quotes are _supposed_ to always be on the outside + // but we'll accommodate both + // Note that in all cases, whitespace is the primary determining factor + // on which direction to curl, with non-word characters like punctuation + // being a secondary factor only after whitespace is addressed. + '/\'"(\s|$)/' => '’”$1', + '/(^|\s|
)\'"/' => '$1‘“', + '/\'"(\W)/' => '’”$1', + '/(\W)\'"/' => '$1‘“', + '/"\'(\s|$)/' => '”’$1', + '/(^|\s|
)"\'/' => '$1“‘', + '/"\'(\W)/' => '”’$1', + '/(\W)"\'/' => '$1“‘', + // single quote smart quotes + '/\'(\s|$)/' => '’$1', + '/(^|\s|
)\'/' => '$1‘', + '/\'(\W)/' => '’$1', + '/(\W)\'/' => '$1‘', + // double quote smart quotes + '/"(\s|$)/' => '”$1', + '/(^|\s|
)"/' => '$1“', + '/"(\W)/' => '”$1', + '/(\W)"/' => '$1“', + // apostrophes + '/(\w)\'(\w)/' => '$1’$2', + // Em dash and ellipses dots + '/\s?\-\-\s?/' => '—', + '/(\w)\.{3}/' => '$1…', + // double space after sentences + '/(\W) /' => '$1 ', + // ampersands, if not a character entity + '/&(?!#?[a-zA-Z0-9]{2,};)/' => '&', + ]; return preg_replace(array_keys($table), $table, $str); } diff --git a/system/Validation/StrictRules/FileRules.php b/system/Validation/StrictRules/FileRules.php index d381f4f47301..575e02d9c01a 100644 --- a/system/Validation/StrictRules/FileRules.php +++ b/system/Validation/StrictRules/FileRules.php @@ -54,9 +54,7 @@ public function __construct(?RequestInterface $request = null) public function uploaded(?string $blank, string $name): bool { $files = $this->request->getFileMultiple($name); - if ($files === null) { - $files = [$this->request->getFile($name)]; - } + $files ??= [$this->request->getFile($name)]; foreach ($files as $file) { if ($file === null) { @@ -94,9 +92,7 @@ public function max_size(?string $blank, string $params): bool $name = array_shift($paramArray); $files = $this->request->getFileMultiple($name); - if ($files === null) { - $files = [$this->request->getFile($name)]; - } + $files ??= [$this->request->getFile($name)]; foreach ($files as $file) { if ($file === null) { @@ -131,9 +127,7 @@ public function is_image(?string $blank, string $params): bool $name = array_shift($params); $files = $this->request->getFileMultiple($name); - if ($files === null) { - $files = [$this->request->getFile($name)]; - } + $files ??= [$this->request->getFile($name)]; foreach ($files as $file) { if ($file === null) { @@ -171,9 +165,7 @@ public function mime_in(?string $blank, string $params): bool $name = array_shift($params); $files = $this->request->getFileMultiple($name); - if ($files === null) { - $files = [$this->request->getFile($name)]; - } + $files ??= [$this->request->getFile($name)]; foreach ($files as $file) { if ($file === null) { @@ -207,9 +199,7 @@ public function ext_in(?string $blank, string $params): bool $name = array_shift($params); $files = $this->request->getFileMultiple($name); - if ($files === null) { - $files = [$this->request->getFile($name)]; - } + $files ??= [$this->request->getFile($name)]; foreach ($files as $file) { if ($file === null) { @@ -247,9 +237,7 @@ public function max_dims(?string $blank, string $params): bool $name = array_shift($params); $files = $this->request->getFileMultiple($name); - if ($files === null) { - $files = [$this->request->getFile($name)]; - } + $files ??= [$this->request->getFile($name)]; foreach ($files as $file) { if ($file === null) { @@ -295,9 +283,7 @@ public function min_dims(?string $blank, string $params): bool $name = array_shift($params); $files = $this->request->getFileMultiple($name); - if ($files === null) { - $files = [$this->request->getFile($name)]; - } + $files ??= [$this->request->getFile($name)]; foreach ($files as $file) { if ($file === null) { diff --git a/system/View/Parser.php b/system/View/Parser.php index 56c3b093bc5d..2aea776dda39 100644 --- a/system/View/Parser.php +++ b/system/View/Parser.php @@ -103,9 +103,7 @@ public function __construct( public function render(string $view, ?array $options = null, ?bool $saveData = null): string { $start = microtime(true); - if ($saveData === null) { - $saveData = $this->config->saveData; - } + $saveData ??= $this->config->saveData; $fileExt = pathinfo($view, PATHINFO_EXTENSION); $view = ($fileExt === '') ? $view . '.php' : $view; // allow Views as .html, .tpl, etc (from CI3) @@ -135,9 +133,7 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n } } - if ($this->tempData === null) { - $this->tempData = $this->data; - } + $this->tempData ??= $this->data; $template = file_get_contents($file); $output = $this->parse($template, $this->tempData, $options); @@ -171,13 +167,9 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n public function renderString(string $template, ?array $options = null, ?bool $saveData = null): string { $start = microtime(true); - if ($saveData === null) { - $saveData = $this->config->saveData; - } + $saveData ??= $this->config->saveData; - if ($this->tempData === null) { - $this->tempData = $this->data; - } + $this->tempData ??= $this->data; $output = $this->parse($template, $this->tempData, $options); @@ -494,9 +486,7 @@ protected function parseConditionals(string $template): string // Parse the PHP itself, or insert an error so they can debug ob_start(); - if ($this->tempData === null) { - $this->tempData = $this->data; - } + $this->tempData ??= $this->data; extract($this->tempData); diff --git a/system/View/Table.php b/system/View/Table.php index 42ee5402adff..5d4958088b2d 100644 --- a/system/View/Table.php +++ b/system/View/Table.php @@ -503,9 +503,7 @@ protected function _compileTemplate() } foreach ($this->_defaultTemplate() as $field => $template) { - if (! isset($this->template[$field])) { - $this->template[$field] = $template; - } + $this->template[$field] ??= $template; } } diff --git a/tests/system/Validation/ValidationTest.php b/tests/system/Validation/ValidationTest.php index b43bb057b52f..49baeaba0c79 100644 --- a/tests/system/Validation/ValidationTest.php +++ b/tests/system/Validation/ValidationTest.php @@ -1683,9 +1683,7 @@ public static function provideSplittingOfComplexStringRules(): iterable */ protected function placeholderReplacementResultDetermination(string $placeholder = 'id', ?array $data = null): void { - if ($data === null) { - $data = [$placeholder => '12']; - } + $data ??= [$placeholder => '12']; $validationRules = self::getPrivateMethodInvoker($this->validation, 'fillPlaceholders')($this->validation->getRules(), $data); $fieldRules = $validationRules['foo']['rules'] ?? $validationRules['foo']; diff --git a/tests/system/View/ParserTest.php b/tests/system/View/ParserTest.php index 730acb6cf8c1..95d807729c58 100644 --- a/tests/system/View/ParserTest.php +++ b/tests/system/View/ParserTest.php @@ -432,9 +432,7 @@ public function testMismatchedVarPair(): void #[DataProvider('provideEscHandling')] public function testEscHandling($value, $expected = null): void { - if ($expected === null) { - $expected = $value; - } + $expected ??= $value; $this->assertSame($expected, \esc($value)); }