diff --git a/system/src/Grav/Framework/Collection/AbstractIndexCollection.php b/system/src/Grav/Framework/Collection/AbstractIndexCollection.php index 341c2e078..9d7d6bb3d 100644 --- a/system/src/Grav/Framework/Collection/AbstractIndexCollection.php +++ b/system/src/Grav/Framework/Collection/AbstractIndexCollection.php @@ -407,7 +407,7 @@ abstract class AbstractIndexCollection implements CollectionInterface $keys = $this->getKeys(); shuffle($keys); - return $this->createFrom(array_replace(array_flip($keys), $this->entries) ?? []); + return $this->createFrom(array_replace(array_flip($keys), $this->entries)); } /** diff --git a/system/src/Grav/Framework/Flex/Flex.php b/system/src/Grav/Framework/Flex/Flex.php index e60dc50e1..28dc94345 100644 --- a/system/src/Grav/Framework/Flex/Flex.php +++ b/system/src/Grav/Framework/Flex/Flex.php @@ -62,7 +62,7 @@ class Flex implements FlexInterface */ public function addDirectoryType(string $type, string $blueprint, array $config = []) { - $config = array_replace_recursive(['enabled' => true], $this->config ?? [], $config); + $config = array_replace_recursive(['enabled' => true], $this->config, $config); $this->types[$type] = new FlexDirectory($type, $blueprint, $config); @@ -143,7 +143,7 @@ class Flex implements FlexInterface public function getMixedCollection(array $keys, array $options = []): FlexCollectionInterface { $collectionClass = $options['collection_class'] ?? ObjectCollection::class; - if (!class_exists($collectionClass)) { + if (!is_a($collectionClass, FlexCollectionInterface::class, true)) { throw new RuntimeException(sprintf('Cannot create collection: Class %s does not exist', $collectionClass)); } @@ -233,7 +233,7 @@ class Flex implements FlexInterface // Use the original key ordering. if (!$guessed) { - $list = array_replace(array_fill_keys($keys, null), $list) ?? []; + $list = array_replace(array_fill_keys($keys, null), $list); } else { // We have mixed keys, we need to map flex keys back to storage keys. $results = []; diff --git a/system/src/Grav/Framework/Flex/FlexCollection.php b/system/src/Grav/Framework/Flex/FlexCollection.php index 48d18ef0f..2a8a16712 100644 --- a/system/src/Grav/Framework/Flex/FlexCollection.php +++ b/system/src/Grav/Framework/Flex/FlexCollection.php @@ -47,7 +47,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface private $_flexDirectory; /** @var string */ - private $_keyField; + private $_keyField = 'storage_key'; /** * Get list of cached methods. @@ -487,7 +487,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface */ public function getKeyField(): string { - return $this->_keyField ?? 'storage_key'; + return $this->_keyField; } /** diff --git a/system/src/Grav/Framework/Flex/FlexDirectory.php b/system/src/Grav/Framework/Flex/FlexDirectory.php index c84e3d185..a96ff6bed 100644 --- a/system/src/Grav/Framework/Flex/FlexDirectory.php +++ b/system/src/Grav/Framework/Flex/FlexDirectory.php @@ -495,6 +495,9 @@ class FlexDirectory implements FlexDirectoryInterface { /** @phpstan-var class-string $className */ $className = $this->objectClassName ?: $this->getObjectClass(); + if (!is_a($className, FlexObjectInterface::class, true)) { + throw new \RuntimeException('Bad object class: ' . $className); + } return new $className($data, $key, $this, $validate); } @@ -509,6 +512,9 @@ class FlexDirectory implements FlexDirectoryInterface { /** phpstan-var class-string $className */ $className = $this->collectionClassName ?: $this->getCollectionClass(); + if (!is_a($className, FlexCollectionInterface::class, true)) { + throw new \RuntimeException('Bad collection class: ' . $className); + } return $className::createFromArray($entries, $this, $keyField); } @@ -523,6 +529,9 @@ class FlexDirectory implements FlexDirectoryInterface { /** @phpstan-var class-string $className */ $className = $this->indexClassName ?: $this->getIndexClass(); + if (!is_a($className, FlexIndexInterface::class, true)) { + throw new \RuntimeException('Bad index class: ' . $className); + } return $className::createFromArray($entries, $this, $keyField); } diff --git a/system/src/Grav/Framework/Flex/FlexIndex.php b/system/src/Grav/Framework/Flex/FlexIndex.php index 98b26679f..14a48f5a4 100644 --- a/system/src/Grav/Framework/Flex/FlexIndex.php +++ b/system/src/Grav/Framework/Flex/FlexIndex.php @@ -40,14 +40,14 @@ use function in_array; * @implements FlexIndexInterface * @mixin C */ -class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexIndexInterface +class FlexIndex extends ObjectIndex implements FlexIndexInterface { const VERSION = 1; /** @var FlexDirectory|null */ private $_flexDirectory; /** @var string */ - private $_keyField; + private $_keyField = 'storage_key'; /** @var array */ private $_indexKeys; @@ -353,7 +353,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde */ public function getKeyField(): string { - return $this->_keyField ?? 'storage_key'; + return $this->_keyField; } /** @@ -416,7 +416,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde $previous = $search; } - return $this->createFrom(array_replace($previous ?? [], $this->getEntries()) ?? []); + return $this->createFrom(array_replace($previous ?? [], $this->getEntries())); } /** diff --git a/system/src/Grav/Framework/Flex/FlexObject.php b/system/src/Grav/Framework/Flex/FlexObject.php index f77059225..f4987a43c 100644 --- a/system/src/Grav/Framework/Flex/FlexObject.php +++ b/system/src/Grav/Framework/Flex/FlexObject.php @@ -888,8 +888,8 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface public function getDefaultValue(string $name, string $separator = null) { $separator = $separator ?: '.'; - $path = explode($separator, $name) ?: []; - $offset = array_shift($path) ?? ''; + $path = explode($separator, $name); + $offset = array_shift($path); $current = $this->getDefaultValues(); diff --git a/system/src/Grav/Framework/Flex/Pages/Traits/PageContentTrait.php b/system/src/Grav/Framework/Flex/Pages/Traits/PageContentTrait.php index f534c132c..0fac6d608 100644 --- a/system/src/Grav/Framework/Flex/Pages/Traits/PageContentTrait.php +++ b/system/src/Grav/Framework/Flex/Pages/Traits/PageContentTrait.php @@ -288,7 +288,7 @@ trait PageContentTrait 'process', $var, function ($value) { - $value = array_replace(Grav::instance()['config']->get('system.pages.process', []), is_array($value) ? $value : []) ?? []; + $value = array_replace(Grav::instance()['config']->get('system.pages.process', []), is_array($value) ? $value : []); foreach ($value as $process => $status) { $value[$process] = (bool)$status; } @@ -664,6 +664,7 @@ trait PageContentTrait */ protected function processContent($content): string { + $content = is_string($content) ? $content : ''; $grav = Grav::instance(); /** @var Config $config */ @@ -676,7 +677,6 @@ trait PageContentTrait $twig_first = $this->getNestedProperty('header.twig_first') ?? $config->get('system.pages.twig_first', false); $never_cache_twig = $this->getNestedProperty('header.never_cache_twig') ?? $config->get('system.pages.never_cache_twig', false); - $cached = null; if ($cache_enable) { $cache = $this->getCache('render'); $key = md5($this->getCacheKey() . '-content'); @@ -688,12 +688,10 @@ trait PageContentTrait if ($process_twig && $never_cache_twig) { $this->_content = $this->processTwig($this->_content); } - } else { - $cached = null; } } - if (!$cached) { + if (null === $this->_content) { $markdown_options = []; if ($process_markdown) { // Build markdown options. diff --git a/system/src/Grav/Framework/Flex/Storage/AbstractFilesystemStorage.php b/system/src/Grav/Framework/Flex/Storage/AbstractFilesystemStorage.php index 1934f50cf..2e3132146 100644 --- a/system/src/Grav/Framework/Flex/Storage/AbstractFilesystemStorage.php +++ b/system/src/Grav/Framework/Flex/Storage/AbstractFilesystemStorage.php @@ -127,6 +127,10 @@ abstract class AbstractFilesystemStorage implements FlexStorageInterface $formatterClassName = $formatter['class'] ?? JsonFormatter::class; $formatterOptions = $formatter['options'] ?? []; + if (!is_a($formatterClassName, FileFormatterInterface::class, true)) { + throw new \InvalidArgumentException('Bad Data Formatter'); + } + $this->dataFormatter = new $formatterClassName($formatterOptions); } diff --git a/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php b/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php index 66c868852..c2bc66891 100644 --- a/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php +++ b/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php @@ -44,7 +44,7 @@ trait FlexMediaTrait } /** @var array */ - protected $_uploads; + protected $_uploads = []; /** * @return string|null @@ -119,7 +119,7 @@ trait FlexMediaTrait // Load settings for the field. $schema = $this->getBlueprint()->schema(); - $settings = $field && is_object($schema) ? (array)$schema->getProperty($field) : null; + $settings = (array)$schema->getProperty($field); if (!is_array($settings)) { return null; } @@ -405,7 +405,7 @@ trait FlexMediaTrait */ protected function getUpdatedMedia(): array { - return $this->_uploads ?? []; + return $this->_uploads; } /**