From 9e84d5d0042df8d2bd271441e7e2173ba17cf236 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 7 Oct 2025 13:30:40 -0600 Subject: [PATCH] more fixes for Symfony7 PHP 8+ Signed-off-by: Andy Miller --- system/src/Grav/Console/ConsoleCommand.php | 6 ++-- system/src/Grav/Console/ConsoleTrait.php | 6 ++-- system/src/Grav/Console/GpmCommand.php | 6 ++-- system/src/Grav/Console/GravCommand.php | 6 ++-- .../Grav/Console/Plugin/PluginListCommand.php | 5 +++ .../src/Grav/Framework/Cache/CacheTrait.php | 32 ++++++++++--------- 6 files changed, 38 insertions(+), 23 deletions(-) diff --git a/system/src/Grav/Console/ConsoleCommand.php b/system/src/Grav/Console/ConsoleCommand.php index beee3d0f3..869b3ca0c 100644 --- a/system/src/Grav/Console/ConsoleCommand.php +++ b/system/src/Grav/Console/ConsoleCommand.php @@ -26,11 +26,13 @@ class ConsoleCommand extends Command * @param OutputInterface $output * @return int */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $this->setupConsole($input, $output); - return $this->serve(); + $result = $this->serve(); + + return is_int($result) ? $result : self::SUCCESS; } /** diff --git a/system/src/Grav/Console/ConsoleTrait.php b/system/src/Grav/Console/ConsoleTrait.php index becc16ab6..21413c3d1 100644 --- a/system/src/Grav/Console/ConsoleTrait.php +++ b/system/src/Grav/Console/ConsoleTrait.php @@ -9,6 +9,7 @@ namespace Grav\Console; +use Closure; use Exception; use Grav\Common\Cache; use Grav\Common\Grav; @@ -83,13 +84,14 @@ trait ConsoleTrait * @param int|null $mode The option mode: One of the InputOption::VALUE_* constants * @param string $description A description text * @param string|string[]|int|bool|null $default The default value (must be null for InputOption::VALUE_NONE) + * @param \Closure|array $suggestedValues Suggested values or completion callback * @return $this * @throws InvalidArgumentException If option mode is invalid or incompatible */ - public function addOption(string $name, array|string|null $shortcut = null, ?int $mode = null, string $description = '', mixed $default = null): static + public function addOption(string $name, array|string|null $shortcut = null, ?int $mode = null, string $description = '', mixed $default = null, Closure|array $suggestedValues = []): static { if ($name !== 'env' && $name !== 'lang') { - parent::addOption($name, $shortcut, $mode, $description, $default); + parent::addOption($name, $shortcut, $mode, $description, $default, $suggestedValues); } return $this; diff --git a/system/src/Grav/Console/GpmCommand.php b/system/src/Grav/Console/GpmCommand.php index a70f1707d..b38a2bc25 100644 --- a/system/src/Grav/Console/GpmCommand.php +++ b/system/src/Grav/Console/GpmCommand.php @@ -28,7 +28,7 @@ class GpmCommand extends Command * @param OutputInterface $output * @return int */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $this->setupConsole($input, $output); @@ -38,7 +38,9 @@ class GpmCommand extends Command // @phpstan-ignore-next-line $grav['accounts']; - return $this->serve(); + $result = $this->serve(); + + return is_int($result) ? $result : self::SUCCESS; } /** diff --git a/system/src/Grav/Console/GravCommand.php b/system/src/Grav/Console/GravCommand.php index 791a5f359..8f1ccb3a1 100644 --- a/system/src/Grav/Console/GravCommand.php +++ b/system/src/Grav/Console/GravCommand.php @@ -26,7 +26,7 @@ class GravCommand extends Command * @param OutputInterface $output * @return int */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $this->setupConsole($input, $output); @@ -36,7 +36,9 @@ class GravCommand extends Command $this->initializeGrav(); } - return $this->serve(); + $result = $this->serve(); + + return is_int($result) ? $result : self::SUCCESS; } /** diff --git a/system/src/Grav/Console/Plugin/PluginListCommand.php b/system/src/Grav/Console/Plugin/PluginListCommand.php index 36d8c51f9..3e648f5ed 100644 --- a/system/src/Grav/Console/Plugin/PluginListCommand.php +++ b/system/src/Grav/Console/Plugin/PluginListCommand.php @@ -21,6 +21,11 @@ class PluginListCommand extends ConsoleCommand { protected static $defaultName = 'plugins:list'; + public function __construct() + { + parent::__construct(self::$defaultName); + } + /** * @return void */ diff --git a/system/src/Grav/Framework/Cache/CacheTrait.php b/system/src/Grav/Framework/Cache/CacheTrait.php index d3178b83d..125f48d81 100644 --- a/system/src/Grav/Framework/Cache/CacheTrait.php +++ b/system/src/Grav/Framework/Cache/CacheTrait.php @@ -46,7 +46,7 @@ trait CacheTrait * @return void * @throws InvalidArgumentException */ - protected function init($namespace = '', $defaultLifetime = null) + protected function init(string $namespace = '', DateInterval|int|null $defaultLifetime = null): void { $this->namespace = (string) $namespace; $this->defaultLifetime = $this->convertTtl($defaultLifetime); @@ -57,7 +57,7 @@ trait CacheTrait * @param bool $validation * @return void */ - public function setValidation($validation) + public function setValidation(bool $validation): void { $this->validation = (bool) $validation; } @@ -65,7 +65,7 @@ trait CacheTrait /** * @return string */ - protected function getNamespace() + protected function getNamespace(): string { return $this->namespace; } @@ -73,7 +73,7 @@ trait CacheTrait /** * @return int|null */ - protected function getDefaultLifetime() + protected function getDefaultLifetime(): ?int { return $this->defaultLifetime; } @@ -84,7 +84,7 @@ trait CacheTrait * @return mixed|null * @throws InvalidArgumentException */ - public function get($key, $default = null) + public function get(string $key, mixed $default = null): mixed { $this->validateKey($key); @@ -99,7 +99,7 @@ trait CacheTrait * @return bool * @throws InvalidArgumentException */ - public function set($key, mixed $value, $ttl = null) + public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool { $this->validateKey($key); @@ -114,7 +114,7 @@ trait CacheTrait * @return bool * @throws InvalidArgumentException */ - public function delete($key) + public function delete(string $key): bool { $this->validateKey($key); @@ -124,7 +124,7 @@ trait CacheTrait /** * @return bool */ - public function clear() + public function clear(): bool { return $this->doClear(); } @@ -135,7 +135,7 @@ trait CacheTrait * @return iterable * @throws InvalidArgumentException */ - public function getMultiple($keys, $default = null) + public function getMultiple(iterable $keys, mixed $default = null): iterable { if ($keys instanceof Traversable) { $keys = iterator_to_array($keys, false); @@ -178,7 +178,7 @@ trait CacheTrait * @return bool * @throws InvalidArgumentException */ - public function setMultiple($values, $ttl = null) + public function setMultiple(iterable $values, DateInterval|int|null $ttl = null): bool { if ($values instanceof Traversable) { $values = iterator_to_array($values, true); @@ -211,7 +211,7 @@ trait CacheTrait * @return bool * @throws InvalidArgumentException */ - public function deleteMultiple($keys) + public function deleteMultiple(iterable $keys): bool { if ($keys instanceof Traversable) { $keys = iterator_to_array($keys, false); @@ -239,7 +239,7 @@ trait CacheTrait * @return bool * @throws InvalidArgumentException */ - public function has($key) + public function has(string $key): bool { $this->validateKey($key); @@ -300,7 +300,7 @@ trait CacheTrait * @return void * @throws InvalidArgumentException */ - protected function validateKey($key) + protected function validateKey(mixed $key): void { if (!is_string($key)) { throw new InvalidArgumentException( @@ -330,7 +330,7 @@ trait CacheTrait * @return void * @throws InvalidArgumentException */ - protected function validateKeys($keys) + protected function validateKeys(iterable $keys): void { if (!$this->validation) { return; @@ -346,7 +346,7 @@ trait CacheTrait * @return int|null * @throws InvalidArgumentException */ - protected function convertTtl($ttl) + protected function convertTtl(DateInterval|int|null $ttl): ?int { if ($ttl === null) { return $this->getDefaultLifetime(); @@ -359,6 +359,8 @@ trait CacheTrait if ($ttl instanceof DateInterval) { $date = DateTime::createFromFormat('U', '0'); $ttl = $date ? (int)$date->add($ttl)->format('U') : 0; + + return $ttl; } throw new InvalidArgumentException(