diff --git a/src/Adapter/ArrayAdapter.php b/src/Adapter/ArrayAdapter.php index cd6ba70..12e3d89 100644 --- a/src/Adapter/ArrayAdapter.php +++ b/src/Adapter/ArrayAdapter.php @@ -4,20 +4,13 @@ namespace Laminas\Paginator\Adapter; -use ReturnTypeWillChange; // phpcs:ignore +use ReturnTypeWillChange; use function array_slice; use function count; class ArrayAdapter implements AdapterInterface { - /** - * ArrayAdapter - * - * @var array - */ - protected $array; - /** * Item count * @@ -28,9 +21,8 @@ class ArrayAdapter implements AdapterInterface /** * @param array $array ArrayAdapter to paginate */ - public function __construct(array $array = []) + public function __construct(protected array $array = []) { - $this->array = $array; $this->count = count($array); } diff --git a/src/Adapter/DbSelect.php b/src/Adapter/DbSelect.php index 549dd27..1601542 100644 --- a/src/Adapter/DbSelect.php +++ b/src/Adapter/DbSelect.php @@ -27,20 +27,6 @@ class DbSelect implements AdapterInterface /** @var Sql */ protected $sql; - /** - * Database query - * - * @var Select - */ - protected $select; - - /** - * Database count query - * - * @var Select|null - */ - protected $countSelect; - /** @var ResultSet */ protected $resultSetPrototype; @@ -57,14 +43,14 @@ class DbSelect implements AdapterInterface * @throws Exception\InvalidArgumentException */ public function __construct( - Select $select, + protected Select $select, $adapterOrSqlObject, ?ResultSetInterface $resultSetPrototype = null, - ?Select $countSelect = null + /** + * Database count query + */ + protected ?Select $countSelect = null ) { - $this->select = $select; - $this->countSelect = $countSelect; - if ($adapterOrSqlObject instanceof Adapter) { $adapterOrSqlObject = new Sql($adapterOrSqlObject); } diff --git a/src/Adapter/NullFill.php b/src/Adapter/NullFill.php index 478f3ea..1447ddc 100644 --- a/src/Adapter/NullFill.php +++ b/src/Adapter/NullFill.php @@ -10,19 +10,11 @@ class NullFill implements AdapterInterface { - /** - * Item count - * - * @var int - */ - protected $count; - /** * @param int $count Total item count (Optional) */ - public function __construct($count = 0) + public function __construct(protected $count = 0) { - $this->count = $count; } /** diff --git a/src/Adapter/Service/CallbackFactory.php b/src/Adapter/Service/CallbackFactory.php index 64ae6f9..9d3f6ff 100644 --- a/src/Adapter/Service/CallbackFactory.php +++ b/src/Adapter/Service/CallbackFactory.php @@ -62,7 +62,6 @@ public function createService(ServiceLocatorInterface $container, $name = null, /** * Options to use with factory (v2) * - * @param array $creationOptions * @return void */ public function setCreationOptions(array $creationOptions) diff --git a/src/Adapter/Service/DbSelectFactory.php b/src/Adapter/Service/DbSelectFactory.php index 0655515..35d5667 100644 --- a/src/Adapter/Service/DbSelectFactory.php +++ b/src/Adapter/Service/DbSelectFactory.php @@ -61,7 +61,6 @@ public function createService(ServiceLocatorInterface $container, $name = null, /** * Options to use with factory (v2) * - * @param array $creationOptions * @return void */ public function setCreationOptions(array $creationOptions) diff --git a/src/Adapter/Service/DbTableGatewayFactory.php b/src/Adapter/Service/DbTableGatewayFactory.php index 950a70f..a231b4b 100644 --- a/src/Adapter/Service/DbTableGatewayFactory.php +++ b/src/Adapter/Service/DbTableGatewayFactory.php @@ -65,7 +65,6 @@ public function createService( /** * Options to use with factory (v2) * - * @param array $creationOptions * @return void */ public function setCreationOptions(array $creationOptions) diff --git a/src/Adapter/Service/IteratorFactory.php b/src/Adapter/Service/IteratorFactory.php index d3f6a9c..50413d4 100644 --- a/src/Adapter/Service/IteratorFactory.php +++ b/src/Adapter/Service/IteratorFactory.php @@ -70,7 +70,6 @@ public function createService( /** * Options to use with factory (v2) * - * @param array $creationOptions * @return void */ public function setCreationOptions(array $creationOptions) diff --git a/src/AdapterPluginManager.php b/src/AdapterPluginManager.php index 2468848..446645f 100644 --- a/src/AdapterPluginManager.php +++ b/src/AdapterPluginManager.php @@ -122,12 +122,11 @@ public function validate($instance) /** * Validate that a plugin is an adapter (v2) * - * @param mixed $plugin * @throws Exception\RuntimeException * @return void * @psalm-assert AdapterInterface $instance */ - public function validatePlugin($plugin) + public function validatePlugin(mixed $plugin) { try { $this->validate($plugin); diff --git a/src/AdapterPluginManagerFactory.php b/src/AdapterPluginManagerFactory.php index c0222b5..2a8df99 100644 --- a/src/AdapterPluginManagerFactory.php +++ b/src/AdapterPluginManagerFactory.php @@ -60,7 +60,6 @@ public function createService(ServiceLocatorInterface $container, $name = null, /** * laminas-servicemanager v2 support for invocation options. * - * @param array $options * @return void */ public function setCreationOptions(array $options) diff --git a/src/Factory.php b/src/Factory.php index 6e293f3..15fa8dd 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -52,11 +52,9 @@ protected static function createAdapterFromItems($items) /** * Get adapter from manager if necessary, and return paginator * - * @param mixed $items - * @param mixed $adapter * @return Paginator */ - protected static function getAdapterFromManager($items, $adapter) + protected static function getAdapterFromManager(mixed $items, mixed $adapter) { if ($adapter instanceof AdapterInterface || $adapter instanceof AdapterAggregateInterface) { return new Paginator($adapter); @@ -68,11 +66,9 @@ protected static function getAdapterFromManager($items, $adapter) /** * Create paginator with items and adapter * - * @param mixed $items - * @param mixed $adapter * @return Paginator */ - public static function factory($items, $adapter = null) + public static function factory(mixed $items, mixed $adapter = null) { if (null === $adapter) { return static::createAdapterFromItems($items); diff --git a/src/Paginator.php b/src/Paginator.php index 34c022b..9d65cbd 100644 --- a/src/Paginator.php +++ b/src/Paginator.php @@ -18,8 +18,9 @@ use Laminas\Stdlib\ArrayUtils; use Laminas\View; use Laminas\View\Renderer\RendererInterface; -use ReturnTypeWillChange; // phpcs:ignore +use ReturnTypeWillChange; use stdClass; +use Stringable; use Throwable; use Traversable; @@ -28,6 +29,7 @@ use function count; use function gettype; use function is_array; +use function is_countable; use function is_object; use function is_string; use function iterator_count; @@ -36,8 +38,8 @@ use function md5; use function min; use function sprintf; +use function str_starts_with; use function strlen; -use function strpos; use function strtolower; use function substr; use function trigger_error; @@ -48,7 +50,7 @@ use const JSON_HEX_QUOT; use const JSON_HEX_TAG; -class Paginator implements Countable, IteratorAggregate +class Paginator implements Countable, IteratorAggregate, Stringable { /** * The cache tag prefix used to namespace Paginator results in the cache @@ -334,10 +336,8 @@ public function __construct($adapter) /** * Serializes the object as a string. Proxies to {@link render()}. - * - * @return string */ - public function __toString() + public function __toString(): string { try { return $this->render(); @@ -402,7 +402,7 @@ public function clearPageItemCache($pageNumber = null) $cacheIterator = static::$cache->getIterator(); $cacheIterator->setMode(CacheIterator::CURRENT_AS_KEY); foreach ($cacheIterator as $key) { - if (0 === strpos($key, self::CACHE_TAG_PREFIX)) { + if (str_starts_with($key, self::CACHE_TAG_PREFIX)) { static::$cache->removeItem($this->_getCacheId((int) substr($key, $prefixLength))); } } @@ -596,11 +596,11 @@ public function setItemCountPerPage($itemCountPerPage = -1) * @param mixed $items Items * @return int */ - public function getItemCount($items) + public function getItemCount(mixed $items) { $itemCount = 0; - if (is_array($items) || $items instanceof Countable) { + if (is_countable($items)) { $itemCount = count($items); } elseif ($items instanceof Traversable) { // $items is something like LimitIterator $itemCount = iterator_count($items); @@ -736,7 +736,7 @@ public function getPageItemCache() $cacheIterator = static::$cache->getIterator(); $cacheIterator->setMode(CacheIterator::CURRENT_AS_VALUE); foreach ($cacheIterator as $key => $value) { - if (0 === strpos($key, self::CACHE_TAG_PREFIX)) { + if (str_starts_with($key, self::CACHE_TAG_PREFIX)) { $data[(int) substr($key, $prefixLength)] = $value; } } diff --git a/src/PaginatorIterator.php b/src/PaginatorIterator.php index 04af01e..ec0a5a7 100644 --- a/src/PaginatorIterator.php +++ b/src/PaginatorIterator.php @@ -18,13 +18,6 @@ */ class PaginatorIterator implements OuterIterator { - /** - * Internal Paginator for iteration - * - * @var Paginator $paginator - */ - protected $paginator; - /** * Value for valid method * @@ -32,9 +25,12 @@ class PaginatorIterator implements OuterIterator */ protected $valid = true; - public function __construct(Paginator $paginator) - { - $this->paginator = $paginator; + public function __construct( + /** + * Internal Paginator for iteration + */ + protected Paginator $paginator + ) { } /** diff --git a/src/ScrollingStylePluginManager.php b/src/ScrollingStylePluginManager.php index 5034207..e4103f5 100644 --- a/src/ScrollingStylePluginManager.php +++ b/src/ScrollingStylePluginManager.php @@ -98,12 +98,11 @@ public function validate($instance) /** * Validate a plugin (v2) * - * @param mixed $plugin * @throws Exception\InvalidArgumentException * @return void * @psalm-assert ScrollingStyleInterface $instance */ - public function validatePlugin($plugin) + public function validatePlugin(mixed $plugin) { try { $this->validate($plugin); diff --git a/src/ScrollingStylePluginManagerFactory.php b/src/ScrollingStylePluginManagerFactory.php index fd08b3b..9191c49 100644 --- a/src/ScrollingStylePluginManagerFactory.php +++ b/src/ScrollingStylePluginManagerFactory.php @@ -40,7 +40,6 @@ public function createService(ServiceLocatorInterface $container, $name = null, /** * laminas-servicemanager v2 support for invocation options. * - * @param array $options * @return void */ public function setCreationOptions(array $options) diff --git a/src/SerializableLimitIterator.php b/src/SerializableLimitIterator.php index 4cf73d3..4980ddc 100644 --- a/src/SerializableLimitIterator.php +++ b/src/SerializableLimitIterator.php @@ -96,10 +96,9 @@ public function offsetGet($offset) * Required by the ArrayAccess implementation * * @param int $offset - * @param mixed $value */ #[ReturnTypeWillChange] - public function offsetSet($offset, $value) + public function offsetSet($offset, mixed $value) { } @@ -119,7 +118,7 @@ public function offsetExists($offset) $current = $this->current(); $this->seek($currentOffset); return null !== $current; - } catch (OutOfBoundsException $e) { + } catch (OutOfBoundsException) { // reset position in case of exception is assigned null $this->seek($currentOffset); return false; diff --git a/test/Adapter/ArrayTest.php b/test/Adapter/ArrayTest.php index 7540292..3e5ce23 100644 --- a/test/Adapter/ArrayTest.php +++ b/test/Adapter/ArrayTest.php @@ -5,8 +5,10 @@ namespace LaminasTest\Paginator\Adapter; use Laminas\Paginator\Adapter; +use Laminas\Paginator\Adapter\ArrayAdapter; use PHPUnit\Framework\TestCase; +use function assert; use function range; /** @@ -15,8 +17,7 @@ */ class ArrayTest extends TestCase { - /** @var Adapter\ArrayAdapter */ - private $adapter; + private ?ArrayAdapter $adapter; /** * Prepares the environment before running a test. @@ -39,19 +40,27 @@ protected function tearDown(): void public function testGetsItemsAtOffsetZero(): void { $expected = range(1, 10); - $actual = $this->adapter->getItems(0, 10); + + assert($this->adapter instanceof ArrayAdapter); + + $actual = $this->adapter->getItems(0, 10); $this->assertEquals($expected, $actual); } public function testGetsItemsAtOffsetTen(): void { $expected = range(11, 20); - $actual = $this->adapter->getItems(10, 10); + + assert($this->adapter instanceof ArrayAdapter); + + $actual = $this->adapter->getItems(10, 10); $this->assertEquals($expected, $actual); } public function testReturnsCorrectCount(): void { + assert($this->adapter instanceof ArrayAdapter); + $this->assertEquals(101, $this->adapter->count()); } diff --git a/test/Adapter/CallbackTest.php b/test/Adapter/CallbackTest.php index 285baac..26bd7ac 100644 --- a/test/Adapter/CallbackTest.php +++ b/test/Adapter/CallbackTest.php @@ -19,13 +19,9 @@ public function testMustDefineTwoCallbacksOnConstructor(): void $itemsCallback = /** $itemsCallback = * @return array $itemsCallback = * @psalm-return array - */ - function (): array { - return []; - }; - $countCallback = function (): int { - return 0; - }; + */ + static fn(): array => []; + $countCallback = static fn(): int => 0; $adapter = new Callback($itemsCallback, $countCallback); $this->assertSame([], $adapter->getItems(1, 1)); @@ -37,10 +33,8 @@ public function testShouldAcceptAnyCallableOnConstructor(): void $itemsCallback = /** $itemsCallback = * @return int[] $itemsCallback = * @psalm-return non-empty-list - */ - function (): array { - return range(1, 10); - }; + */ + static fn(): array => range(1, 10); $countCallback = 'rand'; $adapter = new Callback($itemsCallback, $countCallback); @@ -54,11 +48,9 @@ public function testMustRunItemCallbackToGetItems(): void $itemsCallback = /** $itemsCallback = * @return int[] $itemsCallback = * @psalm-return non-empty-list - */ - function () use ($data): array { - return $data; - }; - $countCallback = function (): void { + */ + static fn(): array => $data; + $countCallback = static function (): void { }; $adapter = new Callback($itemsCallback, $countCallback); @@ -71,11 +63,9 @@ public function testMustPassArgumentsToGetItemCallback(): void $itemsCallback = /** $itemsCallback = * @return (float|int|string)[] $itemsCallback = * @psalm-return non-empty-list - */ - function ($offset, $itemCountPerPage): array { - return range($offset, $itemCountPerPage); - }; - $countCallback = function (): void { + */ + static fn($offset, $itemCountPerPage): array => range($offset, $itemCountPerPage); + $countCallback = static function (): void { }; $adapter = new Callback($itemsCallback, $countCallback); @@ -85,11 +75,9 @@ function ($offset, $itemCountPerPage): array { public function testMustRunCountCallbackToCount(): void { $count = 1988; - $itemsCallback = function (): void { - }; - $countCallback = function () use ($count): int { - return $count; + $itemsCallback = static function (): void { }; + $countCallback = static fn(): int => $count; $adapter = new Callback($itemsCallback, $countCallback); $this->assertSame($count, $adapter->count()); diff --git a/test/Adapter/IteratorTest.php b/test/Adapter/IteratorTest.php index 66b9cc4..63c1a2c 100644 --- a/test/Adapter/IteratorTest.php +++ b/test/Adapter/IteratorTest.php @@ -7,12 +7,12 @@ use ArrayIterator; use Laminas\Paginator\Adapter; use Laminas\Paginator\Adapter\Exception\InvalidArgumentException; -use Laminas\Paginator\Adapter\Iterator; use Laminas\Paginator\Paginator; use Laminas\Paginator\SerializableLimitIterator; use LimitIterator; use PHPUnit\Framework\TestCase; +use function assert; use function iterator_to_array; use function range; use function serialize; @@ -24,8 +24,7 @@ */ class IteratorTest extends TestCase { - /** @var Iterator */ - private $adapter; + private ?Adapter\Iterator $adapter; /** * Prepares the environment before running a test. @@ -48,6 +47,8 @@ protected function tearDown(): void public function testGetsItemsAtOffsetZero(): void { + assert($this->adapter instanceof Adapter\Iterator); + $actual = $this->adapter->getItems(0, 10); $this->assertInstanceOf('LimitIterator', $actual); @@ -60,6 +61,8 @@ public function testGetsItemsAtOffsetZero(): void public function testGetsItemsAtOffsetTen(): void { + assert($this->adapter instanceof Adapter\Iterator); + $actual = $this->adapter->getItems(10, 10); $this->assertInstanceOf('LimitIterator', $actual); @@ -72,6 +75,8 @@ public function testGetsItemsAtOffsetTen(): void public function testReturnsCorrectCount(): void { + assert($this->adapter instanceof Adapter\Iterator); + $this->assertEquals(101, $this->adapter->count()); } @@ -101,6 +106,8 @@ public function testDoesNotThrowOutOfBoundsExceptionIfIteratorIsEmpty(): void */ public function testGetItemsSerializable(): void { + assert($this->adapter instanceof Adapter\Iterator); + /** @psalm-var SerializableLimitIterator $items */ $items = $this->adapter->getItems(0, 1); $innerIterator = $items->getInnerIterator(); diff --git a/test/Adapter/NullFillTest.php b/test/Adapter/NullFillTest.php index 18032d6..f740e9c 100644 --- a/test/Adapter/NullFillTest.php +++ b/test/Adapter/NullFillTest.php @@ -6,10 +6,10 @@ use Laminas\Paginator; use Laminas\Paginator\Adapter; -use Laminas\Paginator\Adapter\NullFill; use PHPUnit\Framework\TestCase; use function array_fill; +use function assert; /** * @group Laminas_Paginator @@ -17,8 +17,7 @@ */ class NullFillTest extends TestCase { - /** @var NullFill */ - private $adapter; + private ?Adapter\NullFill $adapter; /** * Prepares the environment before running a test. @@ -40,12 +39,16 @@ protected function tearDown(): void public function testGetsItems(): void { + assert($this->adapter instanceof Adapter\NullFill); + $actual = $this->adapter->getItems(0, 10); $this->assertEquals(array_fill(0, 10, null), $actual); } public function testReturnsCorrectCount(): void { + assert($this->adapter instanceof Adapter\NullFill); + $this->assertEquals(101, $this->adapter->count()); } diff --git a/test/AdapterPluginManagerFactoryTest.php b/test/AdapterPluginManagerFactoryTest.php index e08d0d9..a03cf9a 100644 --- a/test/AdapterPluginManagerFactoryTest.php +++ b/test/AdapterPluginManagerFactoryTest.php @@ -114,9 +114,7 @@ public function testConfiguresPaginatorServicesWhenFound(): void $paginator = $this->createMock(AdapterInterface::class); /** @psalm-var callable(): MockObject&AdapterInterface $factory */ - $factory = function () use ($paginator): AdapterInterface { - return $paginator; - }; + $factory = static fn(): AdapterInterface => $paginator; $config = [ 'paginators' => [ diff --git a/test/AdapterPluginManagerTest.php b/test/AdapterPluginManagerTest.php index d8d349f..9998fb9 100644 --- a/test/AdapterPluginManagerTest.php +++ b/test/AdapterPluginManagerTest.php @@ -42,12 +42,8 @@ public function pluginProvider(): iterable yield 'iterator-adapter' => ['iterator', [new ArrayIterator(range(1, 101))], Adapter\Iterator::class]; yield 'null-adapter' => ['null', [101], Adapter\NullFill::class]; - $itemsCallback = function (): array { - return []; - }; - $countCallback = function (): int { - return 0; - }; + $itemsCallback = static fn(): array => []; + $countCallback = static fn(): int => 0; yield 'callback-adapter' => ['callback', [$itemsCallback, $countCallback], Adapter\Callback::class]; } diff --git a/test/PaginatorTest.php b/test/PaginatorTest.php index eb8c514..21f3317 100644 --- a/test/PaginatorTest.php +++ b/test/PaginatorTest.php @@ -922,9 +922,7 @@ public function testPaginatorShouldProduceDifferentCacheIdsWithDifferentAdapterI public function testAcceptsComplexAdapters(): void { $paginator = new Paginator\Paginator( - new TestAsset\TestAdapter(function () { - return 'test'; - }) + new TestAsset\TestAdapter(static fn(): string => 'test') ); $this->assertInstanceOf('ArrayObject', $paginator->getCurrentItems()); } diff --git a/test/ScrollingStyle/AllTest.php b/test/ScrollingStyle/AllTest.php index 6654fcd..847bbe8 100644 --- a/test/ScrollingStyle/AllTest.php +++ b/test/ScrollingStyle/AllTest.php @@ -10,6 +10,7 @@ use PHPUnit\Framework\TestCase; use function array_combine; +use function assert; use function range; /** @@ -18,11 +19,9 @@ */ class AllTest extends TestCase { - /** @var All */ - private $scrollingStyle; + private ?All $scrollingStyle; - /** @var Paginator */ - private $paginator; + private ?Paginator $paginator; /** * Prepares the environment before running a test. @@ -48,12 +47,18 @@ protected function tearDown(): void public function testGetsPages(): void { $expected = array_combine(range(1, 11), range(1, 11)); - $pages = $this->scrollingStyle->getPages($this->paginator); + + assert($this->scrollingStyle instanceof All); + assert($this->paginator instanceof Paginator); + + $pages = $this->scrollingStyle->getPages($this->paginator); $this->assertEquals($expected, $pages); } public function testGetsNextAndPreviousPageForFirstPage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(1); $pages = $this->paginator->getPages('All'); @@ -62,6 +67,8 @@ public function testGetsNextAndPreviousPageForFirstPage(): void public function testGetsNextAndPreviousPageForSecondPage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(2); $pages = $this->paginator->getPages('All'); $this->assertEquals(1, $pages->previous); @@ -70,6 +77,8 @@ public function testGetsNextAndPreviousPageForSecondPage(): void public function testGetsNextAndPreviousPageForMiddlePage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(6); $pages = $this->paginator->getPages('All'); $this->assertEquals(5, $pages->previous); @@ -78,6 +87,8 @@ public function testGetsNextAndPreviousPageForMiddlePage(): void public function testGetsNextAndPreviousPageForSecondLastPage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(10); $pages = $this->paginator->getPages('All'); $this->assertEquals(9, $pages->previous); @@ -86,6 +97,8 @@ public function testGetsNextAndPreviousPageForSecondLastPage(): void public function testGetsNextAndPreviousPageForLastPage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(11); $pages = $this->paginator->getPages('All'); $this->assertEquals(10, $pages->previous); diff --git a/test/ScrollingStyle/ElasticTest.php b/test/ScrollingStyle/ElasticTest.php index 08886ec..05d4334 100644 --- a/test/ScrollingStyle/ElasticTest.php +++ b/test/ScrollingStyle/ElasticTest.php @@ -10,6 +10,7 @@ use PHPUnit\Framework\TestCase; use function array_combine; +use function assert; use function count; use function range; @@ -19,10 +20,8 @@ */ class ElasticTest extends TestCase { - /** @var Elastic */ - private $scrollingStyle; - /** @var Paginator */ - private $paginator; + private ?Elastic $scrollingStyle; + private ?Paginator $paginator; /** * Prepares the environment before running a test. @@ -48,6 +47,9 @@ protected function tearDown(): void public function testGetsPagesInRangeForFirstPage(): void { + assert($this->paginator instanceof Paginator); + assert($this->scrollingStyle instanceof Elastic); + $this->paginator->setCurrentPageNumber(1); $actual = $this->scrollingStyle->getPages($this->paginator); $expected = array_combine(range(1, 5), range(1, 5)); @@ -56,6 +58,9 @@ public function testGetsPagesInRangeForFirstPage(): void public function testGetsPagesInRangeForSecondPage(): void { + assert($this->paginator instanceof Paginator); + assert($this->scrollingStyle instanceof Elastic); + $this->paginator->setCurrentPageNumber(2); $actual = $this->scrollingStyle->getPages($this->paginator); $expected = array_combine(range(1, 6), range(1, 6)); @@ -64,6 +69,9 @@ public function testGetsPagesInRangeForSecondPage(): void public function testGetsPagesInRangeForTenthPage(): void { + assert($this->paginator instanceof Paginator); + assert($this->scrollingStyle instanceof Elastic); + $this->paginator->setCurrentPageNumber(10); $actual = $this->scrollingStyle->getPages($this->paginator); $expected = array_combine(range(6, 14), range(6, 14)); @@ -72,6 +80,9 @@ public function testGetsPagesInRangeForTenthPage(): void public function testGetsPagesInRangeForLastPage(): void { + assert($this->paginator instanceof Paginator); + assert($this->scrollingStyle instanceof Elastic); + $this->paginator->setCurrentPageNumber(21); $actual = $this->scrollingStyle->getPages($this->paginator); $expected = array_combine(range(17, 21), range(17, 21)); @@ -80,6 +91,8 @@ public function testGetsPagesInRangeForLastPage(): void public function testGetsNextAndPreviousPageForFirstPage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(1); $pages = $this->paginator->getPages('Elastic'); @@ -88,6 +101,8 @@ public function testGetsNextAndPreviousPageForFirstPage(): void public function testGetsNextAndPreviousPageForSecondPage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(2); $pages = $this->paginator->getPages('Elastic'); $this->assertEquals(1, $pages->previous); @@ -96,6 +111,8 @@ public function testGetsNextAndPreviousPageForSecondPage(): void public function testGetsNextAndPreviousPageForMiddlePage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(10); $pages = $this->paginator->getPages('Elastic'); $this->assertEquals(9, $pages->previous); @@ -104,6 +121,8 @@ public function testGetsNextAndPreviousPageForMiddlePage(): void public function testGetsNextAndPreviousPageForSecondLastPage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(20); $pages = $this->paginator->getPages('Elastic'); $this->assertEquals(19, $pages->previous); @@ -112,6 +131,8 @@ public function testGetsNextAndPreviousPageForSecondLastPage(): void public function testGetsNextAndPreviousPageForLastPage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(21); $pages = $this->paginator->getPages('Elastic'); $this->assertEquals(20, $pages->previous); @@ -119,6 +140,8 @@ public function testGetsNextAndPreviousPageForLastPage(): void public function testNoPagesOnLastPageEqualsPageRange(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setPageRange(3); $this->paginator->setCurrentPageNumber(21); $pages = $this->paginator->getPages('Elastic'); @@ -127,6 +150,8 @@ public function testNoPagesOnLastPageEqualsPageRange(): void public function testNoPagesOnSecondLastPageEqualsPageRangeMinOne(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setPageRange(3); $this->paginator->setCurrentPageNumber(20); $pages = $this->paginator->getPages('Elastic'); @@ -135,6 +160,8 @@ public function testNoPagesOnSecondLastPageEqualsPageRangeMinOne(): void public function testNoPagesBeforeSecondLastPageEqualsPageRangeMinTwo(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setPageRange(3); $this->paginator->setCurrentPageNumber(19); $pages = $this->paginator->getPages('Elastic'); diff --git a/test/ScrollingStyle/JumpingTest.php b/test/ScrollingStyle/JumpingTest.php index 3e7c90e..b3ce5b1 100644 --- a/test/ScrollingStyle/JumpingTest.php +++ b/test/ScrollingStyle/JumpingTest.php @@ -10,6 +10,7 @@ use PHPUnit\Framework\TestCase; use function array_combine; +use function assert; use function range; /** @@ -18,14 +19,11 @@ */ class JumpingTest extends TestCase { - /** @var Jumping */ - private $scrollingStyle; + private ?Jumping $scrollingStyle; - /** @var Paginator */ - private $paginator; + private ?Paginator $paginator; - /** @var array */ - private $expectedRange; + private array $expectedRange; /** * Prepares the environment before running a test. @@ -52,6 +50,9 @@ protected function tearDown(): void public function testGetsPagesInRangeForFirstPage(): void { + assert($this->paginator instanceof Paginator); + assert($this->scrollingStyle instanceof Jumping); + $this->paginator->setCurrentPageNumber(1); $actual = $this->scrollingStyle->getPages($this->paginator); $this->assertEquals($this->expectedRange, $actual); @@ -59,6 +60,9 @@ public function testGetsPagesInRangeForFirstPage(): void public function testGetsPagesInRangeForSecondPage(): void { + assert($this->paginator instanceof Paginator); + assert($this->scrollingStyle instanceof Jumping); + $this->paginator->setCurrentPageNumber(2); $actual = $this->scrollingStyle->getPages($this->paginator); $this->assertEquals($this->expectedRange, $actual); @@ -66,6 +70,9 @@ public function testGetsPagesInRangeForSecondPage(): void public function testGetsPagesInRangeForSecondLastPage(): void { + assert($this->paginator instanceof Paginator); + assert($this->scrollingStyle instanceof Jumping); + $this->paginator->setCurrentPageNumber(10); $actual = $this->scrollingStyle->getPages($this->paginator); $this->assertEquals($this->expectedRange, $actual); @@ -73,6 +80,9 @@ public function testGetsPagesInRangeForSecondLastPage(): void public function testGetsPagesInRangeForLastPage(): void { + assert($this->paginator instanceof Paginator); + assert($this->scrollingStyle instanceof Jumping); + $this->paginator->setCurrentPageNumber(11); $actual = $this->scrollingStyle->getPages($this->paginator); $expected = [11 => 11]; @@ -81,6 +91,8 @@ public function testGetsPagesInRangeForLastPage(): void public function testGetsNextAndPreviousPageForFirstPage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(1); $pages = $this->paginator->getPages('Jumping'); @@ -89,6 +101,8 @@ public function testGetsNextAndPreviousPageForFirstPage(): void public function testGetsNextAndPreviousPageForSecondPage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(2); $pages = $this->paginator->getPages('Jumping'); $this->assertEquals(1, $pages->previous); @@ -97,6 +111,8 @@ public function testGetsNextAndPreviousPageForSecondPage(): void public function testGetsNextAndPreviousPageForMiddlePage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(6); $pages = $this->paginator->getPages('Jumping'); $this->assertEquals(5, $pages->previous); @@ -105,6 +121,8 @@ public function testGetsNextAndPreviousPageForMiddlePage(): void public function testGetsNextAndPreviousPageForSecondLastPage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(10); $pages = $this->paginator->getPages('Jumping'); $this->assertEquals(9, $pages->previous); @@ -113,6 +131,8 @@ public function testGetsNextAndPreviousPageForSecondLastPage(): void public function testGetsNextAndPreviousPageForLastPage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(11); $pages = $this->paginator->getPages('Jumping'); $this->assertEquals(10, $pages->previous); diff --git a/test/ScrollingStyle/SlidingTest.php b/test/ScrollingStyle/SlidingTest.php index 0a89f6e..5bb299f 100644 --- a/test/ScrollingStyle/SlidingTest.php +++ b/test/ScrollingStyle/SlidingTest.php @@ -10,6 +10,7 @@ use PHPUnit\Framework\TestCase; use function array_combine; +use function assert; use function range; /** @@ -19,14 +20,9 @@ class SlidingTest extends TestCase { // @codingStandardsIgnoreStart - /** - * @var \Laminas\Paginator\ScrollingStyle\Sliding - */ - private $_scrollingStyle; + private ?Sliding $_scrollingStyle; // @codingStandardsIgnoreEnd - - /** @var Paginator */ - private $paginator; + private ?Paginator $paginator; /** * Prepares the environment before running a test. @@ -52,6 +48,9 @@ protected function tearDown(): void public function testGetsPagesInRangeForFirstPage(): void { + assert($this->paginator instanceof Paginator); + assert($this->_scrollingStyle instanceof Sliding); + $this->paginator->setCurrentPageNumber(1); $actual = $this->_scrollingStyle->getPages($this->paginator); $expected = array_combine(range(1, 5), range(1, 5)); @@ -60,6 +59,9 @@ public function testGetsPagesInRangeForFirstPage(): void public function testGetsPagesInRangeForSecondPage(): void { + assert($this->paginator instanceof Paginator); + assert($this->_scrollingStyle instanceof Sliding); + $this->paginator->setCurrentPageNumber(2); $actual = $this->_scrollingStyle->getPages($this->paginator); $expected = array_combine(range(1, 5), range(1, 5)); @@ -68,6 +70,9 @@ public function testGetsPagesInRangeForSecondPage(): void public function testGetsPagesInRangeForFifthPage(): void { + assert($this->paginator instanceof Paginator); + assert($this->_scrollingStyle instanceof Sliding); + $this->paginator->setCurrentPageNumber(5); $actual = $this->_scrollingStyle->getPages($this->paginator); $expected = array_combine(range(3, 7), range(3, 7)); @@ -76,6 +81,9 @@ public function testGetsPagesInRangeForFifthPage(): void public function testGetsPagesInRangeForLastPage(): void { + assert($this->paginator instanceof Paginator); + assert($this->_scrollingStyle instanceof Sliding); + $this->paginator->setCurrentPageNumber(11); $actual = $this->_scrollingStyle->getPages($this->paginator); $expected = array_combine(range(7, 11), range(7, 11)); @@ -84,6 +92,9 @@ public function testGetsPagesInRangeForLastPage(): void public function testGetsNextAndPreviousPageForFirstPage(): void { + assert($this->paginator instanceof Paginator); + assert($this->_scrollingStyle instanceof Sliding); + $this->paginator->setCurrentPageNumber(1); $pages = $this->paginator->getPages('Sliding'); @@ -92,6 +103,8 @@ public function testGetsNextAndPreviousPageForFirstPage(): void public function testGetsNextAndPreviousPageForSecondPage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(2); $pages = $this->paginator->getPages('Sliding'); $this->assertEquals(1, $pages->previous); @@ -100,6 +113,8 @@ public function testGetsNextAndPreviousPageForSecondPage(): void public function testGetsNextAndPreviousPageForMiddlePage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(6); $pages = $this->paginator->getPages('Sliding'); $this->assertEquals(5, $pages->previous); @@ -108,6 +123,8 @@ public function testGetsNextAndPreviousPageForMiddlePage(): void public function testGetsNextAndPreviousPageForSecondLastPage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(10); $pages = $this->paginator->getPages('Sliding'); $this->assertEquals(9, $pages->previous); @@ -116,6 +133,8 @@ public function testGetsNextAndPreviousPageForSecondLastPage(): void public function testGetsNextAndPreviousPageForLastPage(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setCurrentPageNumber(11); $pages = $this->paginator->getPages('Sliding'); $this->assertEquals(10, $pages->previous); @@ -123,6 +142,8 @@ public function testGetsNextAndPreviousPageForLastPage(): void public function testAcceptsPageRangeLargerThanPageCount(): void { + assert($this->paginator instanceof Paginator); + $this->paginator->setPageRange(100); $pages = $this->paginator->getPages(); $this->assertEquals(11, $pages->last); diff --git a/test/TestAsset/TestAdapter.php b/test/TestAsset/TestAdapter.php index 7622af4..7df1811 100644 --- a/test/TestAsset/TestAdapter.php +++ b/test/TestAsset/TestAdapter.php @@ -12,15 +12,8 @@ class TestAdapter implements AdapterInterface { - /** @var mixed */ - public $property; - - /** - * @param mixed $property - */ - public function __construct($property = null) + public function __construct(public mixed $property = null) { - $this->property = $property; } /**