diff --git a/system/src/Grav/Framework/Flex/FlexForm.php b/system/src/Grav/Framework/Flex/FlexForm.php index b679f5ce1..6ded34590 100644 --- a/system/src/Grav/Framework/Flex/FlexForm.php +++ b/system/src/Grav/Framework/Flex/FlexForm.php @@ -20,6 +20,7 @@ use Grav\Framework\Form\Traits\FormTrait; use Grav\Framework\Route\Route; use Twig\Error\LoaderError; use Twig\Error\SyntaxError; +use Twig\Template; use Twig\TemplateWrapper; /** @@ -277,7 +278,7 @@ class FlexForm implements FlexFormInterface /** * @param string $layout - * @return TemplateWrapper + * @return Template|TemplateWrapper * @throws LoaderError * @throws SyntaxError */ diff --git a/system/src/Grav/Framework/Flex/FlexIndex.php b/system/src/Grav/Framework/Flex/FlexIndex.php index 29ac33bbc..8b96b4a9a 100644 --- a/system/src/Grav/Framework/Flex/FlexIndex.php +++ b/system/src/Grav/Framework/Flex/FlexIndex.php @@ -312,9 +312,10 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde // Ordering can be done by using index only. $previous = null; foreach (array_reverse($orderings) as $field => $ordering) { + $field = (string)$field; if ($this->getKeyField() === $field) { $keys = $this->getKeys(); - $search = array_combine($keys, $keys); + $search = array_combine($keys, $keys) ?: []; } elseif ($field === 'flex_key') { $search = $this->getFlexKeys(); } else { @@ -462,7 +463,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde $first = reset($entries); if ($first) { $keys = array_keys($first); - $keys = array_combine($keys, $keys); + $keys = array_combine($keys, $keys) ?: []; } else { $keys = []; } diff --git a/system/src/Grav/Framework/Flex/FlexObject.php b/system/src/Grav/Framework/Flex/FlexObject.php index 5208fc196..01f45d079 100644 --- a/system/src/Grav/Framework/Flex/FlexObject.php +++ b/system/src/Grav/Framework/Flex/FlexObject.php @@ -31,6 +31,7 @@ use Psr\SimpleCache\InvalidArgumentException; use RocketTheme\Toolbox\Event\Event; use Twig\Error\LoaderError; use Twig\Error\SyntaxError; +use Twig\Template; use Twig\TemplateWrapper; /** @@ -391,7 +392,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface } try { - $data = $cache ? $cache->get($key) : null; + $data = $cache && $key ? $cache->get($key) : null; $block = $data ? HtmlBlock::fromArray($data) : null; } catch (InvalidArgumentException $e) { @@ -410,7 +411,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface } if (!$block) { - $block = HtmlBlock::create($key); + $block = HtmlBlock::create($key ?: null); $block->setChecksum($checksum); if ($key === false) { $block->disableCache(); @@ -434,7 +435,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface $block->setContent($output); try { - $cache && $block->isCached() && $cache->set($key, $block->toArray()); + $cache && $key && $block->isCached() && $cache->set($key, $block->toArray()); } catch (InvalidArgumentException $e) { $debugger->addException($e); } @@ -541,7 +542,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface $result = $this->getFlexDirectory()->getStorage()->replaceRows([$this->getStorageKey() => $this->prepareStorage()]); $value = reset($result); - $storageKey = key($result); + $storageKey = (string)key($result); if ($value && $storageKey) { $this->setStorageKey($storageKey); if (!$this->hasKey()) { @@ -558,7 +559,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface if (method_exists($this, 'clearMediaCache')) { $this->clearMediaCache(); } - } catch (InvalidArgumentException $e) { + } catch (\Exception $e) { /** @var Debugger $debugger */ $debugger = Grav::instance()['debugger']; $debugger->addException($e); @@ -586,7 +587,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface if (method_exists($this, 'clearMediaCache')) { $this->clearMediaCache(); } - } catch (InvalidArgumentException $e) { + } catch (\Exception $e) { /** @var Debugger $debugger */ $debugger = Grav::instance()['debugger']; $debugger->addException($e); @@ -807,7 +808,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface /** * @param string $layout - * @return TemplateWrapper + * @return Template|TemplateWrapper * @throws LoaderError * @throws SyntaxError */ diff --git a/system/src/Grav/Framework/Flex/Storage/AbstractFilesystemStorage.php b/system/src/Grav/Framework/Flex/Storage/AbstractFilesystemStorage.php index b547cc227..cc460ccd0 100644 --- a/system/src/Grav/Framework/Flex/Storage/AbstractFilesystemStorage.php +++ b/system/src/Grav/Framework/Flex/Storage/AbstractFilesystemStorage.php @@ -128,7 +128,7 @@ abstract class AbstractFilesystemStorage implements FlexStorageInterface return $path; } - return (string) $locator->findResource($path) ?: $locator->findResource($path, true, true); + return (string)($locator->findResource($path) ?: $locator->findResource($path, true, true)); } /** diff --git a/system/src/Grav/Framework/Flex/Storage/FolderStorage.php b/system/src/Grav/Framework/Flex/Storage/FolderStorage.php index 2304e8013..76397c235 100644 --- a/system/src/Grav/Framework/Flex/Storage/FolderStorage.php +++ b/system/src/Grav/Framework/Flex/Storage/FolderStorage.php @@ -455,6 +455,8 @@ class FolderStorage extends AbstractFilesystemStorage protected function initOptions(array $options): void { $extension = $this->dataFormatter->getDefaultFileExtension(); + + /** @var string $pattern */ $pattern = !empty($options['pattern']) ? $options['pattern'] : $this->dataPattern; $this->dataFolder = $options['folder']; diff --git a/system/src/Grav/Framework/Flex/Storage/SimpleStorage.php b/system/src/Grav/Framework/Flex/Storage/SimpleStorage.php index 209ba3382..088b9527e 100644 --- a/system/src/Grav/Framework/Flex/Storage/SimpleStorage.php +++ b/system/src/Grav/Framework/Flex/Storage/SimpleStorage.php @@ -227,7 +227,12 @@ class SimpleStorage extends AbstractFilesystemStorage $keys = array_keys($this->data); $keys[array_search($src, $keys, true)] = $dst; - $this->data = array_combine($keys, $this->data); + $data = array_combine($keys, $this->data); + if (false === $data) { + throw new \LogicException('Bad data'); + } + + $this->data = $data; return true; } diff --git a/tests/phpstan/phpstan.neon b/tests/phpstan/phpstan.neon index e8e24ff51..29781281b 100644 --- a/tests/phpstan/phpstan.neon +++ b/tests/phpstan/phpstan.neon @@ -41,14 +41,15 @@ parameters: message: '#Grav\\Common\\GPM\\Remote\\GravCore::__construct\(\) does not call parent constructor from Grav\\Common\\GPM\\Remote\\AbstractPackageCollection#' path: 'system/src/Grav/Common/GPM/Remote/GravCore.php' + # PSR-16 Exception interfaces do not extend \Throwable + - '#PHPDoc tag \@throws with type Psr\\SimpleCache\\(CacheException|InvalidArgumentException) is not subtype of Throwable#' + - '#expects Exception, Psr\\SimpleCache\\InvalidArgumentException&Throwable given#' + # Needed: psr-17 (http-factories) support (through decorator or further investigations) - message: '#Call to an undefined static method Grav\\Framework\\Psr7\\Stream::create\(\)#' path: 'system/src/Grav/Framework/Form/FormFlashFile.php' - # PSR-16 Exception interfaces do not extend \Throwable - - '#PHPDoc tag \@throws with type Psr\\SimpleCache\\(CacheException|InvalidArgumentException) is not subtype of Throwable#' - # Medium __call() methods - '#Call to an undefined method Grav\\Common\\Page\\Medium\\(\w*)Medium::#'