-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from acelaya-forks/feature/phpstan-generics
Enable missing generics checks with phpstan
- Loading branch information
Showing
12 changed files
with
118 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,3 @@ includes: | |
parameters: | ||
ignoreErrors: | ||
- identifier: missingType.iterableValue | ||
- identifier: missingType.generics |
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
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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shlinkio\Shlink\Common\Paginator\Util; | ||
|
||
use Laminas\Stdlib\ArrayUtils; | ||
use Pagerfanta\Pagerfanta; | ||
|
||
use function array_map; | ||
use function count; | ||
use function sprintf; | ||
|
||
/** | ||
* @template T | ||
*/ | ||
final class PagerfantaUtils | ||
{ | ||
/** | ||
* @param Pagerfanta<T> $paginator | ||
* @param null|callable(T): mixed $serializer | ||
*/ | ||
public static function serializePaginator( | ||
Pagerfanta $paginator, | ||
?callable $serializer = null, | ||
string $dataProp = 'data', | ||
): array { | ||
$currentPageItems = ArrayUtils::iteratorToArray($paginator->getCurrentPageResults()); | ||
|
||
return [ | ||
$dataProp => self::serializeItems($currentPageItems, $serializer), | ||
'pagination' => [ | ||
'currentPage' => $paginator->getCurrentPage(), | ||
'pagesCount' => $paginator->getNbPages(), | ||
'itemsPerPage' => $paginator->getMaxPerPage(), | ||
'itemsInCurrentPage' => count($currentPageItems), | ||
'totalItems' => $paginator->getNbResults(), | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @param T[] $items | ||
* @param null|callable(T): array $serializer | ||
*/ | ||
private static function serializeItems(array $items, ?callable $serializer = null): array | ||
{ | ||
return $serializer === null ? $items : array_map($serializer, $items); | ||
} | ||
|
||
/** | ||
* @param Pagerfanta<T> $paginator | ||
*/ | ||
public static function formatCurrentPageMessage(Pagerfanta $paginator, string $pattern): string | ||
{ | ||
return sprintf($pattern, $paginator->getCurrentPage(), $paginator->getNbPages()); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
namespace Shlinkio\Shlink\Common\Rest; | ||
|
||
/** @deprecated */ | ||
interface DataTransformerInterface | ||
{ | ||
/** | ||
|
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
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
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