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
4 changes: 2 additions & 2 deletions system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ public static function getWidth(int $default = 80): int
static::generateDimensions();
}

return static::$width ?: $default;
return (static::$width === null || static::$width === 0) ? $default : static::$width;
}

/**
Expand All @@ -753,7 +753,7 @@ public static function getHeight(int $default = 32): int
static::generateDimensions();
}

return static::$height ?: $default;
return (static::$height === null || static::$height === 0) ? $default : static::$height;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion system/Commands/Utilities/Namespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ private function outputCINamespaces(array $params): array
$pathOutput = $this->truncate(clean_path($path), $maxLength);
}

$path = realpath($path) ?: $path;
$realPath = realpath($path);
$path = $realPath === false ? $path : $realPath;

$tbody[] = [
$ns,
Expand Down
9 changes: 7 additions & 2 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ function clean_path(string $path): string
{
// Resolve relative paths
try {
$path = realpath($path) ?: $path;
$realPath = realpath($path);
$path = $realPath === false ? $path : $realPath;
} catch (ErrorException|ValueError) {
$path = 'error file path: ' . urlencode($path);
}
Expand Down Expand Up @@ -1347,7 +1348,11 @@ function class_uses_recursive($class)
*/
function trait_uses_recursive($trait)
{
$traits = class_uses($trait) ?: [];
$traits = class_uses($trait);

if ($traits === false) {
return [];
}

foreach ($traits as $trait) {
$traits += trait_uses_recursive($trait);
Expand Down
8 changes: 4 additions & 4 deletions system/Cookie/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ final public function __construct(string $name, string $value = '', array $optio

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

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

$raw = $options['raw'];
$secure = $options['secure'];
Expand Down Expand Up @@ -429,7 +429,7 @@ public function getOptions(): array
'domain' => $this->domain,
'secure' => $this->secure,
'httponly' => $this->httponly,
'samesite' => $this->samesite ?: ucfirst(self::SAMESITE_LAX),
'samesite' => ($this->samesite === '') ? ucfirst(self::SAMESITE_LAX) : $this->samesite,
];
}

Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Toolbar/Collectors/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static function collect(Query $query)
$config = config(Toolbar::class);

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

if (count(static::$queries) < $max) {
$queryString = $query->getQuery();
Expand Down
11 changes: 7 additions & 4 deletions system/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public function getSizeByUnit(string $unit = 'b')
public function guessExtension(): ?string
{
// naively get the path extension using pathinfo
$pathinfo = pathinfo($this->getRealPath() ?: $this->__toString()) + ['extension' => ''];
$realPath = $this->getRealPath();
$pathinfo = pathinfo($realPath === false ? $this->__toString() : $realPath) + ['extension' => ''];

$proposedExtension = $pathinfo['extension'];

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

$finfo = finfo_open(FILEINFO_MIME_TYPE);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$realPath = $this->getRealPath();

return finfo_file($finfo, $this->getRealPath() ?: $this->__toString());
return finfo_file($finfo, $realPath === false ? $this->__toString() : $realPath);
}

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

$oldName = $this->getRealPath() ?: $this->__toString();
$realPath = $this->getRealPath();
$oldName = $realPath === false ? $this->__toString() : $realPath;

if (! @rename($oldName, $destination)) {
$error = error_get_last();
Expand Down
3 changes: 2 additions & 1 deletion system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,8 @@ private function applySslOptions(array $curlOptions, array $config): array
// SSL Verification
if (isset($config['verify'])) {
if (is_string($config['verify'])) {
$file = realpath($config['verify']) ?: $config['verify'];
$realPath = realpath($config['verify']);
$file = $realPath === false ? $config['verify'] : $realPath;

if (! is_file($file)) {
throw HTTPException::forInvalidSSLKey($config['verify']);
Expand Down
6 changes: 4 additions & 2 deletions system/HTTP/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function getJSON()
$body = service('format')->getFormatter('application/json')->format($body);
}

return $body ?: null;
return ($body === null || $body === '') ? null : $body;
}

/**
Expand Down Expand Up @@ -541,10 +541,12 @@ public function setCookie(

if (is_numeric($expire)) {
$expire = $expire > 0 ? Time::now()->getTimestamp() + $expire : 0;
} else {
$expire = 0;
}

$cookie = new Cookie($name, $value, [
'expires' => $expire ?: 0,
'expires' => $expire,
'domain' => $domain,
'path' => $path,
'prefix' => $prefix,
Expand Down
8 changes: 5 additions & 3 deletions system/Helpers/filesystem_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ function write_file(string $path, string $data, string $mode = 'wb'): bool
*/
function delete_files(string $path, bool $delDir = false, bool $htdocs = false, bool $hidden = false): bool
{
$path = realpath($path) ?: $path;
$path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$realPath = realpath($path);
$path = $realPath === false ? $path : $realPath;
$path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;

try {
foreach (new RecursiveIteratorIterator(
Expand Down Expand Up @@ -208,7 +209,8 @@ function get_filenames(
): array {
$files = [];

$sourceDir = realpath($sourceDir) ?: $sourceDir;
$realPath = realpath($sourceDir);
$sourceDir = $realPath === false ? $sourceDir : $realPath;
$sourceDir = rtrim($sourceDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;

try {
Expand Down
2 changes: 1 addition & 1 deletion system/I18n/TimeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function __construct(?string $time = null, $timezone = null, ?string $loc
}
}

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

// If the time string was a relative string (i.e. 'next Tuesday')
Expand Down
4 changes: 3 additions & 1 deletion system/Pager/Pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ public function getCurrentPage(string $group = 'default'): int
{
$this->ensureGroup($group);

return $this->groups[$group]['currentPage'] ?: 1;
$currentPage = $this->groups[$group]['currentPage'];

return ($currentPage === 0) ? 1 : $currentPage;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion system/Router/AutoRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public function getRoute(string $uri, string $httpVerb): array
// If it doesn't, no biggie - the default method name
// has already been set.
if ($segments !== []) {
$this->method = array_shift($segments) ?: $this->method;
$method = array_shift($segments);
$this->method = $method === '' ? $this->method : $method;
}

// Prevent access to initController method
Expand Down
4 changes: 2 additions & 2 deletions system/Test/Mock/MockCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function deleteMatching(string $pattern): int
public function increment(string $key, int $offset = 1): bool
{
$key = static::validateKey($key, $this->prefix);
$data = $this->cache[$key] ?: null;
$data = $this->cache[$key] ?? null;

if ($data === null) {
$data = 0;
Expand All @@ -162,7 +162,7 @@ public function decrement(string $key, int $offset = 1): bool
{
$key = static::validateKey($key, $this->prefix);

$data = $this->cache[$key] ?: null;
$data = $this->cache[$key] ?? null;

if ($data === null) {
$data = 0;
Expand Down
3 changes: 2 additions & 1 deletion system/Validation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,8 @@ protected function splitRules(string $rules): array
) {
// the pipe is inside the brackets causing the closing bracket to
// not be included. so, we adjust the rule to include that portion.
$pos = strpos($string, '|', $cursor + strlen($rule) + 1) ?: $length;
$next = strpos($string, '|', $cursor + strlen($rule) + 1);
$pos = $next === false ? $length : $next;
$rule = substr($string, $cursor, $pos - $cursor);
}

Expand Down
4 changes: 2 additions & 2 deletions system/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n
ob_start();
include $this->renderVars['file'];

return ob_get_clean() ?: '';
return (string) ob_get_clean();
})();

// Get back current vars
Expand Down Expand Up @@ -331,7 +331,7 @@ public function renderString(string $view, ?array $options = null, ?bool $saveDa
ob_start();
eval('?>' . $view);

return ob_get_clean() ?: '';
return (string) ob_get_clean();
})($view);

$this->logPerformance($start, microtime(true), $this->excerpt($view));
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Commands/Generators/CellGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function getFileContents(string $filepath): string
return '';
}

return file_get_contents($filepath) ?: '';
return (string) file_get_contents($filepath);
}

public function testGenerateCell(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Commands/Generators/CommandGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function getFileContents(string $filepath): string
return '';
}

return file_get_contents($filepath) ?: '';
return (string) file_get_contents($filepath);
}

public function testGenerateCommand(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function getFileContents(string $filepath): string
return '';
}

return file_get_contents($filepath) ?: '';
return (string) file_get_contents($filepath);
}

public function testGenerateController(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Commands/Generators/ModelGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private function getFileContent(string $filepath): string
return '';
}

return file_get_contents($filepath) ?: '';
return (string) file_get_contents($filepath);
}

public function testGenerateModel(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Commands/Generators/ScaffoldGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected function getFileContents(string $filepath): string
return '';
}

return file_get_contents($filepath) ?: '';
return (string) file_get_contents($filepath);
}

public function testCreateComponentProducesManyFiles(): void
Expand Down
3 changes: 2 additions & 1 deletion tests/system/Publisher/PublisherSupportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public function testWipe(): void
{
$directory = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . bin2hex(random_bytes(6));
mkdir($directory, 0700);
$directory = realpath($directory) ?: $directory;
$realPath = realpath($directory);
$directory = $realPath === false ? $directory : $realPath;
$this->assertDirectoryExists($directory);
config('Publisher')->restrictions[$directory] = ''; // Allow the directory

Expand Down
3 changes: 1 addition & 2 deletions utils/phpstan-baseline/loader.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 1560 errors
# total 1527 errors

includes:
- argument.type.neon
Expand All @@ -20,4 +20,3 @@ includes:
- property.phpDocType.neon
- return.type.neon
- staticMethod.notFound.neon
- ternary.shortNotAllowed.neon
Loading
Loading