Skip to content

Commit fcf7a3e

Browse files
committed
refactor: fix ternary.shortNotAllowed errors
1 parent f9f18fb commit fcf7a3e

23 files changed

Lines changed: 54 additions & 149 deletions

File tree

‎system/CLI/CLI.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ public static function getWidth(int $default = 80): int
741741
static::generateDimensions();
742742
}
743743

744-
return static::$width ?: $default;
744+
return (static::$width === null || static::$width === 0) ? $default : static::$width;
745745
}
746746

747747
/**
@@ -753,7 +753,7 @@ public static function getHeight(int $default = 32): int
753753
static::generateDimensions();
754754
}
755755

756-
return static::$height ?: $default;
756+
return (static::$height === null || static::$height === 0) ? $default : static::$height;
757757
}
758758

759759
/**

‎system/Commands/Utilities/Namespaces.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ private function outputCINamespaces(array $params): array
145145
$pathOutput = $this->truncate(clean_path($path), $maxLength);
146146
}
147147

148-
$path = realpath($path) ?: $path;
148+
$realPath = realpath($path);
149+
$path = $realPath === false ? $path : $realPath;
149150

150151
$tbody[] = [
151152
$ns,

‎system/Common.php‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ function clean_path(string $path): string
9595
{
9696
// Resolve relative paths
9797
try {
98-
$path = realpath($path) ?: $path;
98+
$realPath = realpath($path);
99+
$path = $realPath === false ? $path : $realPath;
99100
} catch (ErrorException|ValueError) {
100101
$path = 'error file path: ' . urlencode($path);
101102
}
@@ -1347,7 +1348,11 @@ function class_uses_recursive($class)
13471348
*/
13481349
function trait_uses_recursive($trait)
13491350
{
1350-
$traits = class_uses($trait) ?: [];
1351+
$traits = class_uses($trait);
1352+
1353+
if ($traits === false) {
1354+
return [];
1355+
}
13511356

13521357
foreach ($traits as $trait) {
13531358
$traits += trait_uses_recursive($trait);

‎system/Cookie/Cookie.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ final public function __construct(string $name, string $value = '', array $optio
254254

255255
// to preserve backward compatibility with array-based cookies in previous CI versions
256256
$prefix = ($options['prefix'] === '') ? self::$defaults['prefix'] : $options['prefix'];
257-
$path = $options['path'] ?: self::$defaults['path'];
258-
$domain = $options['domain'] ?: self::$defaults['domain'];
257+
$path = ($options['path'] === '') ? self::$defaults['path'] : $options['path'];
258+
$domain = ($options['domain'] === '') ? self::$defaults['domain'] : $options['domain'];
259259

260260
// empty string SameSite should use the default for browsers
261-
$samesite = $options['samesite'] ?: self::$defaults['samesite'];
261+
$samesite = ($options['samesite'] === '') ? self::$defaults['samesite'] : $options['samesite'];
262262

263263
$raw = $options['raw'];
264264
$secure = $options['secure'];
@@ -429,7 +429,7 @@ public function getOptions(): array
429429
'domain' => $this->domain,
430430
'secure' => $this->secure,
431431
'httponly' => $this->httponly,
432-
'samesite' => $this->samesite ?: ucfirst(self::SAMESITE_LAX),
432+
'samesite' => ($this->samesite === '') ? ucfirst(self::SAMESITE_LAX) : $this->samesite,
433433
];
434434
}
435435

‎system/Debug/Toolbar/Collectors/Database.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static function collect(Query $query)
8888
$config = config(Toolbar::class);
8989

9090
// Provide default in case it's not set
91-
$max = $config->maxQueries ?: 100;
91+
$max = ($config->maxQueries === 0) ? 100 : $config->maxQueries;
9292

9393
if (count(static::$queries) < $max) {
9494
$queryString = $query->getQuery();

‎system/Files/File.php‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ public function getSizeByUnit(string $unit = 'b')
111111
public function guessExtension(): ?string
112112
{
113113
// naively get the path extension using pathinfo
114-
$pathinfo = pathinfo($this->getRealPath() ?: $this->__toString()) + ['extension' => ''];
114+
$realPath = $this->getRealPath();
115+
$pathinfo = pathinfo($realPath === false ? $this->__toString() : $realPath) + ['extension' => ''];
115116

116117
$proposedExtension = $pathinfo['extension'];
117118

@@ -131,9 +132,10 @@ public function getMimeType(): string
131132
return $this->originalMimeType ?? 'application/octet-stream'; // @codeCoverageIgnore
132133
}
133134

134-
$finfo = finfo_open(FILEINFO_MIME_TYPE);
135+
$finfo = finfo_open(FILEINFO_MIME_TYPE);
136+
$realPath = $this->getRealPath();
135137

136-
return finfo_file($finfo, $this->getRealPath() ?: $this->__toString());
138+
return finfo_file($finfo, $realPath === false ? $this->__toString() : $realPath);
137139
}
138140

139141
/**
@@ -159,7 +161,8 @@ public function move(string $targetPath, ?string $name = null, bool $overwrite =
159161
$name ??= $this->getBasename();
160162
$destination = $overwrite ? $targetPath . $name : $this->getDestination($targetPath . $name);
161163

162-
$oldName = $this->getRealPath() ?: $this->__toString();
164+
$realPath = $this->getRealPath();
165+
$oldName = $realPath === false ? $this->__toString() : $realPath;
163166

164167
if (! @rename($oldName, $destination)) {
165168
$error = error_get_last();

‎system/HTTP/CURLRequest.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,8 @@ private function applySslOptions(array $curlOptions, array $config): array
587587
// SSL Verification
588588
if (isset($config['verify'])) {
589589
if (is_string($config['verify'])) {
590-
$file = realpath($config['verify']) ?: $config['verify'];
590+
$realPath = realpath($config['verify']);
591+
$file = $realPath === false ? $config['verify'] : $realPath;
591592

592593
if (! is_file($file)) {
593594
throw HTTPException::forInvalidSSLKey($config['verify']);

‎system/HTTP/ResponseTrait.php‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public function getJSON()
195195
$body = service('format')->getFormatter('application/json')->format($body);
196196
}
197197

198-
return $body ?: null;
198+
return ($body === null || $body === '') ? null : $body;
199199
}
200200

201201
/**
@@ -541,10 +541,12 @@ public function setCookie(
541541

542542
if (is_numeric($expire)) {
543543
$expire = $expire > 0 ? Time::now()->getTimestamp() + $expire : 0;
544+
} else {
545+
$expire = 0;
544546
}
545547

546548
$cookie = new Cookie($name, $value, [
547-
'expires' => $expire ?: 0,
549+
'expires' => $expire,
548550
'domain' => $domain,
549551
'path' => $path,
550552
'prefix' => $prefix,

‎system/Helpers/filesystem_helper.php‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ function write_file(string $path, string $data, string $mode = 'wb'): bool
155155
*/
156156
function delete_files(string $path, bool $delDir = false, bool $htdocs = false, bool $hidden = false): bool
157157
{
158-
$path = realpath($path) ?: $path;
159-
$path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
158+
$realPath = realpath($path);
159+
$path = $realPath === false ? $path : $realPath;
160+
$path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
160161

161162
try {
162163
foreach (new RecursiveIteratorIterator(
@@ -208,7 +209,8 @@ function get_filenames(
208209
): array {
209210
$files = [];
210211

211-
$sourceDir = realpath($sourceDir) ?: $sourceDir;
212+
$realPath = realpath($sourceDir);
213+
$sourceDir = $realPath === false ? $sourceDir : $realPath;
212214
$sourceDir = rtrim($sourceDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
213215

214216
try {

‎system/I18n/TimeTrait.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function __construct(?string $time = null, $timezone = null, ?string $loc
8787
}
8888
}
8989

90-
$timezone = $timezone ?: date_default_timezone_get();
90+
$timezone = ($timezone === null || $timezone === '') ? date_default_timezone_get() : $timezone;
9191
$this->timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone);
9292

9393
// If the time string was a relative string (i.e. 'next Tuesday')

0 commit comments

Comments
 (0)