Minor fixes

This commit is contained in:
Matias Griese
2021-11-30 19:02:42 +02:00
parent d220812f5e
commit e4f79dbfce
8 changed files with 20 additions and 14 deletions

View File

@@ -122,7 +122,7 @@ class Pipeline extends PropertyObject
// Compute uid based on assets and timestamp
$json_assets = json_encode($assets);
$uid = md5($json_assets . $this->css_minify . $this->css_rewrite . $group);
$uid = md5($json_assets . (int)$this->css_minify . (int)$this->css_rewrite . $group);
$file = $uid . '.css';
$relative_path = "{$this->base_url}{$this->assets_url}/{$file}";

View File

@@ -145,7 +145,7 @@ class Backups
{
$backups = static::getAvailableBackups();
return array_sum(array_column($backups, 'size'));
return $backups ? array_sum(array_column($backups, 'size')) : 0;
}
/**

View File

@@ -99,7 +99,7 @@ class Blueprint extends BlueprintForm
*/
public function getDefaultValue(string $name)
{
$path = explode('.', $name) ?: [];
$path = explode('.', $name);
$current = $this->getDefaults();
foreach ($path as $field) {

View File

@@ -816,7 +816,7 @@ class Validation
{
$value = static::filterArray($value, $params, $field);
return Utils::arrayUnflattenDotNotation($value);
return is_array($value) ? Utils::arrayUnflattenDotNotation($value) : null;
}
/**

View File

@@ -513,7 +513,7 @@ abstract class Folder
}
$directories = glob($directory . '/*', GLOB_ONLYDIR);
return count($directories);
return $directories ? count($directories) : false;
}
/**
@@ -530,7 +530,8 @@ abstract class Folder
}
// Go through all items in filesystem and recursively remove everything.
$files = array_diff(scandir($folder, SCANDIR_SORT_NONE), array('.', '..'));
$files = scandir($folder, SCANDIR_SORT_NONE);
$files = $files ? array_diff($files, ['.', '..']) : [];
foreach ($files as $file) {
$path = "{$folder}/{$file}";
is_dir($path) ? self::doDelete($path) : @unlink($path);

View File

@@ -131,7 +131,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
{
$key = $this->isAllowedElement($element) ? $this->getCurrentKey($element) : null;
if (!$key || !isset($this->entries[$key])) {
if (null !== $key || !isset($this->entries[$key])) {
return false;
}
@@ -148,7 +148,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return $this->containsKey($offset);
return $offset !== null ? $this->containsKey($offset) : false;
}
/**
@@ -159,7 +159,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->get($offset);
return $offset !== null ? $this->get($offset) : null;
}
/**
@@ -172,9 +172,9 @@ abstract class AbstractIndexCollection implements CollectionInterface
{
if (null === $offset) {
$this->add($value);
} else {
$this->set($offset, $value);
}
$this->set($offset, $value);
}
/**
@@ -185,7 +185,9 @@ abstract class AbstractIndexCollection implements CollectionInterface
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
$this->remove($offset);
if ($offset !== null) {
$this->remove($offset);
}
}
/**

View File

@@ -191,8 +191,9 @@ class AbstractFile implements FileInterface
$this->handle = @fopen($this->filepath, 'cb+') ?: null;
if (!$this->handle) {
$error = error_get_last();
$message = $error['message'] ?? 'Unknown error';
throw new RuntimeException("Opening file for writing failed on error {$error['message']}");
throw new RuntimeException("Opening file for writing failed on error {$message}");
}
}

View File

@@ -107,7 +107,9 @@ class YamlFormatter extends AbstractFormatter
$saved = @ini_get('yaml.decode_php');
@ini_set('yaml.decode_php', '0');
$decoded = @yaml_parse($data);
@ini_set('yaml.decode_php', $saved);
if ($saved !== false) {
@ini_set('yaml.decode_php', $saved);
}
if ($decoded !== false) {
return (array) $decoded;