From 13256df0c2a5aba37e620856c6ee0299ba86c3c1 Mon Sep 17 00:00:00 2001 From: Kristof Feys Date: Thu, 15 Feb 2024 11:24:07 +0100 Subject: [PATCH] update types --- src/JsonFeedV1Serializer.php | 4 ++-- src/Plugin.php | 8 ++++---- src/Settings.php | 4 ++-- src/resources/ElementResource.php | 18 +++++++++--------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/JsonFeedV1Serializer.php b/src/JsonFeedV1Serializer.php index f48072e..e18b27e 100644 --- a/src/JsonFeedV1Serializer.php +++ b/src/JsonFeedV1Serializer.php @@ -40,8 +40,8 @@ public function meta(array $meta): array */ public function paginator(PaginatorInterface $paginator): array { - $currentPage = (int)$paginator->getCurrentPage(); - $lastPage = (int)$paginator->getLastPage(); + $currentPage = $paginator->getCurrentPage(); + $lastPage = $paginator->getLastPage(); if ($currentPage < $lastPage) { return [ diff --git a/src/Plugin.php b/src/Plugin.php index 4badd50..53cf680 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -26,12 +26,12 @@ class Plugin extends \craft\base\Plugin * @var array The default Fractal resource adapter configuration * @see getDefaultResourceAdapterConfig() */ - private $_defaultResourceAdapterConfig; + private array $_defaultResourceAdapterConfig; /** * @inheritdoc */ - public function init() + public function init(): void { parent::init(); @@ -59,7 +59,7 @@ function(RegisterCacheOptionsEvent $event) { * @param string $pattern * @return callable|array|ResourceAdapterInterface|null */ - public function getEndpoint($pattern) + public function getEndpoint(string $pattern) { return $this->getSettings()->endpoints[$pattern] ?? null; } @@ -83,7 +83,7 @@ public function getDefaultResourceAdapterConfig(): array * * @param RegisterUrlRulesEvent $event */ - public function registerUrlRules(RegisterUrlRulesEvent $event) + public function registerUrlRules(RegisterUrlRulesEvent $event): void { foreach ($this->getSettings()->endpoints as $pattern => $config) { $event->rules[$pattern] = [ diff --git a/src/Settings.php b/src/Settings.php index 743ca37..c4fdef3 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -20,7 +20,7 @@ class Settings extends Model /** * @var array The endpoint configurations. */ - public $endpoints = []; + public array $endpoints = []; /** * Returns the default endpoint configuration. @@ -28,7 +28,7 @@ class Settings extends Model * @return array The default endpoint configuration. * @since 2.6.0 */ - public function getDefaults() + public function getDefaults(): array { return is_callable($this->defaults) ? call_user_func($this->defaults) : $this->defaults; } diff --git a/src/resources/ElementResource.php b/src/resources/ElementResource.php index f4877a5..da4d197 100644 --- a/src/resources/ElementResource.php +++ b/src/resources/ElementResource.php @@ -30,12 +30,12 @@ class ElementResource extends BaseObject implements ResourceAdapterInterface /** * @var string The element type class name */ - public $elementType; + public string $elementType; /** * @var array The element criteria params that should be used to filter the matching elements */ - public $criteria = []; + public array $criteria = []; /** * @var callable|string|array|TransformerAbstract The transformer config, or an actual transformer object @@ -45,34 +45,34 @@ class ElementResource extends BaseObject implements ResourceAdapterInterface /** * @var bool Whether to only return one result */ - public $one = false; + public bool $one = false; /** * @var bool Whether to paginate the results */ - public $paginate = true; + public bool $paginate = true; /** * @var int The number of elements to include per page * @see paginate */ - public $elementsPerPage = 100; + public int $elementsPerPage = 100; /** * @var string The query string param name that should be used to specify the page number * @see paginate */ - public $pageParam = 'page'; + public string $pageParam = 'page'; /** * @var string|null The resource key that should be set on the resource */ - public $resourceKey; + public ?string $resourceKey; /** * @var array|null Custom meta values */ - public $meta; + public ?array $meta; /** * @inheritdoc @@ -91,7 +91,7 @@ public function __construct(array $config = []) * @inheritdoc * @throws InvalidConfigException */ - public function init() + public function init(): void { if ($this->elementType === null || !is_subclass_of($this->elementType, ElementInterface::class)) { throw new InvalidConfigException('Endpoint has an invalid elementType');