Skip to content

Commit

Permalink
Merge pull request #49 from e-belair/fix-dbselect
Browse files Browse the repository at this point in the history
Add ArrayCopyInterface to be implemented by DbSelect adapters
  • Loading branch information
Ocramius authored Nov 18, 2022
2 parents 83c3ff8 + 505dabc commit 7070769
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 39 deletions.
40 changes: 3 additions & 37 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.24.0@06dd975cb55d36af80f242561738f16c5f58264f">
<files psalm-version="4.30.0@d0bc6e25d89f649e4f36a534f330f8bb4643dd69">
<file src="src/Adapter/Callback.php">
<InvalidFunctionCall occurrences="2">
<code>call_user_func($this-&gt;countCallback)</code>
Expand Down Expand Up @@ -167,7 +167,8 @@
<MixedArrayAccess occurrences="1">
<code>$page[$itemNumber - 1]</code>
</MixedArrayAccess>
<MixedAssignment occurrences="13">
<MixedAssignment occurrences="14">
<code>$adapterToSerialize</code>
<code>$adapters</code>
<code>$cacheIterator</code>
<code>$cacheIterator</code>
Expand Down Expand Up @@ -311,11 +312,6 @@
<code>$this-&gt;__serialize</code>
</UndefinedThisPropertyFetch>
</file>
<file src="test/Adapter/ArrayTest.php">
<PossiblyNullPropertyAssignmentValue occurrences="1">
<code>null</code>
</PossiblyNullPropertyAssignmentValue>
</file>
<file src="test/Adapter/CallbackTest.php">
<MissingClosureParamType occurrences="2">
<code>$itemCountPerPage</code>
Expand All @@ -339,14 +335,6 @@
<MixedMethodCall occurrences="1">
<code>getInnerIterator</code>
</MixedMethodCall>
<PossiblyNullPropertyAssignmentValue occurrences="1">
<code>null</code>
</PossiblyNullPropertyAssignmentValue>
</file>
<file src="test/Adapter/NullFillTest.php">
<PossiblyNullPropertyAssignmentValue occurrences="1">
<code>null</code>
</PossiblyNullPropertyAssignmentValue>
</file>
<file src="test/AdapterPluginManagerCompatibilityTest.php">
<MixedArgument occurrences="3">
Expand Down Expand Up @@ -443,34 +431,12 @@
<code>addPath</code>
</UndefinedInterfaceMethod>
</file>
<file src="test/ScrollingStyle/AllTest.php">
<PossiblyNullPropertyAssignmentValue occurrences="2">
<code>null</code>
<code>null</code>
</PossiblyNullPropertyAssignmentValue>
</file>
<file src="test/ScrollingStyle/ElasticTest.php">
<MixedArgument occurrences="3">
<code>$pages-&gt;pagesInRange</code>
<code>$pages-&gt;pagesInRange</code>
<code>$pages-&gt;pagesInRange</code>
</MixedArgument>
<PossiblyNullPropertyAssignmentValue occurrences="2">
<code>null</code>
<code>null</code>
</PossiblyNullPropertyAssignmentValue>
</file>
<file src="test/ScrollingStyle/JumpingTest.php">
<PossiblyNullPropertyAssignmentValue occurrences="2">
<code>null</code>
<code>null</code>
</PossiblyNullPropertyAssignmentValue>
</file>
<file src="test/ScrollingStyle/SlidingTest.php">
<PossiblyNullPropertyAssignmentValue occurrences="2">
<code>null</code>
<code>null</code>
</PossiblyNullPropertyAssignmentValue>
</file>
<file src="test/TestAsset/TestAdapter.php">
<ParamNameMismatch occurrences="1">
Expand Down
3 changes: 1 addition & 2 deletions src/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Laminas\Db\ResultSet\AbstractResultSet;
use Laminas\Filter\FilterInterface;
use Laminas\Paginator\Adapter\AdapterInterface;
use Laminas\Paginator\Adapter\DbSelect;
use Laminas\Paginator\ScrollingStyle\ScrollingStyleInterface;
use Laminas\ServiceManager\ServiceManager;
use Laminas\Stdlib\ArrayUtils;
Expand Down Expand Up @@ -894,7 +893,7 @@ protected function _getCacheId($page = null)
protected function _getCacheInternalId()
{
$adapter = $this->getAdapter();
$adapterToSerialize = $adapter instanceof DbSelect
$adapterToSerialize = method_exists($adapter, 'getArrayCopy')
? $adapter->getArrayCopy()
: $adapter;

Expand Down
17 changes: 17 additions & 0 deletions test/PaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,23 @@ public function testPaginatorShouldProduceDifferentCacheIdsWithDifferentAdapterI
$this->assertNotEquals($firstCacheId, $secondCacheId);
}

public function testPaginatorShouldProduceDifferentCacheIdsDependingOnGetArrayCopy(): void
{
$paginator = new Paginator\Paginator(new TestAsset\TestAdapter('foo'));
$reflectionGetCacheInternalId = new ReflectionMethod($paginator, '_getCacheInternalId');
$reflectionGetCacheInternalId->setAccessible(true);
/** @var string $firstCacheId */
$firstCacheId = $reflectionGetCacheInternalId->invoke($paginator);

$paginator = new Paginator\Paginator(new TestAsset\TestArrayCopyAdapter('foo'));
$reflectionGetCacheInternalId = new ReflectionMethod($paginator, '_getCacheInternalId');
$reflectionGetCacheInternalId->setAccessible(true);
/** @var string $secondCacheId */
$secondCacheId = $reflectionGetCacheInternalId->invoke($paginator);

$this->assertNotEquals($firstCacheId, $secondCacheId);
}

public function testAcceptsComplexAdapters(): void
{
$paginator = new Paginator\Paginator(
Expand Down
16 changes: 16 additions & 0 deletions test/TestAsset/TestArrayCopyAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace LaminasTest\Paginator\TestAsset;

class TestArrayCopyAdapter extends TestAdapter
{
/**
* @return array
*/
public function getArrayCopy()
{
return [];
}
}

0 comments on commit 7070769

Please sign in to comment.