-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
TraversableToTraversableTransformer
now gives a Countable
r…
…esult if the source is `Countable`.
- Loading branch information
Showing
6 changed files
with
132 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/mapper package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rekalogika\Mapper\Model; | ||
|
||
/** | ||
* @template TKey | ||
* @template TValue | ||
* @implements \IteratorAggregate<TKey,TValue> | ||
*/ | ||
final class TraversableCountableWrapper implements \IteratorAggregate, \Countable | ||
{ | ||
/** | ||
* @param \Traversable<TKey,TValue> $traversable | ||
*/ | ||
public function __construct( | ||
private \Traversable $traversable, | ||
private \Countable|int $countable, | ||
) { | ||
} | ||
|
||
public function getIterator(): \Traversable | ||
{ | ||
return $this->traversable; | ||
} | ||
|
||
public function count(): int | ||
{ | ||
if (is_int($this->countable)) { | ||
return $this->countable; | ||
} | ||
|
||
return $this->countable->count(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
tests/Fixtures/ArrayLike/LazyDoctrineCollectionWithPresetCountable.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/mapper package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rekalogika\Mapper\Tests\Fixtures\ArrayLike; | ||
|
||
use Doctrine\Common\Collections\AbstractLazyCollection; | ||
|
||
/** | ||
* @extends AbstractLazyCollection<array-key,mixed> | ||
*/ | ||
class LazyDoctrineCollectionWithPresetCountable extends AbstractLazyCollection | ||
{ | ||
protected function doInitialize() | ||
{ | ||
throw new \LogicException("Not expected to be initialized"); | ||
} | ||
|
||
public function count(): int | ||
{ | ||
return 31337; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/Fixtures/ArrayLike/ObjectWithLazyDoctrineCollectionWithPresetCountableProperty.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/mapper package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rekalogika\Mapper\Tests\Fixtures\ArrayLike; | ||
|
||
class ObjectWithLazyDoctrineCollectionWithPresetCountableProperty | ||
{ | ||
public LazyDoctrineCollectionWithPresetCountable $property; | ||
|
||
public function __construct() | ||
{ | ||
$this->property = new LazyDoctrineCollectionWithPresetCountable(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters