Skip to content

Commit

Permalink
Merge branch 'craft-5' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Mar 12, 2024
2 parents 3a91f6e + e19fba7 commit e3e5498
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/JsonFeedV1Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
18 changes: 9 additions & 9 deletions src/PaginatorAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -105,7 +105,7 @@ public function getCount(): int
*
* @param int $count
*/
public function setCount($count)
public function setCount(int $count): void
{
$this->count = $count;
}
Expand All @@ -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();

Expand Down
8 changes: 4 additions & 4 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
}
Expand All @@ -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] = [
Expand Down
4 changes: 2 additions & 2 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ class Settings extends Model
/**
* @var array The endpoint configurations.
*/
public $endpoints = [];
public array $endpoints = [];

/**
* Returns the default endpoint configuration.
*
* @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;
}
Expand Down
20 changes: 10 additions & 10 deletions src/resources/ElementResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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');
}

Expand Down

0 comments on commit e3e5498

Please sign in to comment.