Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 1 addition & 3 deletions system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions system/CLI/SignalTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 1 addition & 3 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions system/Commands/ListCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 2 additions & 6 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 1 addition & 3 deletions system/Config/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Expand Down
4 changes: 1 addition & 3 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
Expand Down
9 changes: 2 additions & 7 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions system/Database/BaseUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
4 changes: 1 addition & 3 deletions system/Database/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
4 changes: 1 addition & 3 deletions system/Database/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 2 additions & 5 deletions system/Database/SQLSRV/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Database/SQLite3/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions system/Debug/BaseExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
8 changes: 2 additions & 6 deletions system/Debug/Timer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '.', '');
}
Expand All @@ -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);
}
Expand Down
9 changes: 2 additions & 7 deletions system/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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?';

Expand Down
8 changes: 2 additions & 6 deletions system/Filters/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 4 additions & 12 deletions system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
8 changes: 2 additions & 6 deletions system/HTTP/RequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
&& (
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions system/HTTP/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 1 addition & 3 deletions system/HTTP/URI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
12 changes: 3 additions & 9 deletions system/Helpers/form_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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"' : '';
Expand Down Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions system/Helpers/html_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<img';

Expand Down
Loading
Loading