diff --git a/README.md b/README.md index 4af1d7c..5381ef4 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ It’s powered by Phil Sturgeon’s excellent [Fractal](http://fractal.thephplea ## Requirements -This plugin requires Craft CMS 4.0 or later. +This plugin requires Craft CMS 4.0.0+ or 5.0.0+. ## Installation diff --git a/composer.json b/composer.json index dce219c..5b240b6 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "craftcms/cms": "^4.0.0-RC3", + "craftcms/cms": "^4.0.0-RC3|^5.0.0-beta.1", "league/fractal": "^0.20.1" }, "require-dev": { diff --git a/composer.lock b/composer.lock index d208f5b..5eab996 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "393695a3b1d1e9e19ee64298aa11306f", + "content-hash": "ae356faea7dac544d8d151d9ce97044b", "packages": [ { "name": "cebe/markdown", 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/PaginatorAdapter.php b/src/PaginatorAdapter.php index 236a7b4..22bc2ff 100644 --- a/src/PaginatorAdapter.php +++ b/src/PaginatorAdapter.php @@ -17,32 +17,32 @@ class PaginatorAdapter implements PaginatorInterface /** * @var int */ - protected $elementsPerPage; + protected int $elementsPerPage; /** * @var int */ - protected $totalElements; + protected int $totalElements; /** * @var string */ - protected $pageParam; + protected string $pageParam; /** * @var int */ - protected $totalPages; + protected int $totalPages; /** * @var int */ - protected $currentPage; + protected int $currentPage; /** * @var int */ - protected $count; + protected int $count; /** * Constructor @@ -51,7 +51,7 @@ class PaginatorAdapter implements PaginatorInterface * @param integer $totalElements * @param string $pageParam */ - public function __construct($elementsPerPage, $totalElements, $pageParam) + public function __construct(int $elementsPerPage, int $totalElements, string $pageParam) { $this->elementsPerPage = $elementsPerPage; $this->totalElements = $totalElements; @@ -105,7 +105,7 @@ public function getCount(): int * * @param int $count */ - public function setCount($count) + public function setCount(int $count): void { $this->count = $count; } @@ -126,7 +126,7 @@ public function getPerPage(): int * @param int $page * @return string */ - public function getUrl($page): string + public function getUrl(int $page): string { $request = Craft::$app->getRequest(); diff --git a/src/Plugin.php b/src/Plugin.php index 4badd50..306afc1 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 = null; /** * @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..a549135 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 = 'data'; /** * @var array|null Custom meta values */ - public $meta; + public ?array $meta = null; /** * @inheritdoc @@ -91,9 +91,9 @@ 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)) { + if (!isset($this->elementType) || !is_subclass_of($this->elementType, ElementInterface::class)) { throw new InvalidConfigException('Endpoint has an invalid elementType'); }