Skip to content

Commit

Permalink
Make AuditReaderInterface generic
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored and jordisala1991 committed Oct 29, 2021
1 parent 5098f37 commit 4fc33a0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/Model/AuditManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public function hasReader(string $class): bool;
*
* @throws \LogicException
*
* @phpstan-param class-string $class
* @phpstan-template T of object
* @phpstan-param class-string<T> $class
* @phpstan-return AuditReaderInterface<T>
*/
public function getReader(string $class): AuditReaderInterface;
}
11 changes: 6 additions & 5 deletions src/Model/AuditReaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@

/**
* @author Thomas Rabaix <[email protected]>
*
* @phpstan-template T of object
*/
interface AuditReaderInterface
{
/**
* @param int|string $id
* @param int|string $revisionId
*
* @phpstan-template T of object
* @phpstan-param class-string<T> $className
* @phpstan-return T|null
*/
Expand All @@ -31,14 +32,14 @@ public function find(string $className, $id, $revisionId): ?object;
/**
* @return Revision[]
*
* @phpstan-param class-string $className
* @phpstan-param class-string<T> $className
*/
public function findRevisionHistory(string $className, int $limit = 20, int $offset = 0): array;

/**
* @param int|string $revisionId
*
* @phpstan-param class-string $className
* @phpstan-param class-string<T> $className
*/
public function findRevision(string $className, $revisionId): ?Revision;

Expand All @@ -47,7 +48,7 @@ public function findRevision(string $className, $revisionId): ?Revision;
*
* @return Revision[]
*
* @phpstan-param class-string $className
* @phpstan-param class-string<T> $className
*/
public function findRevisions(string $className, $id): array;

Expand All @@ -58,7 +59,7 @@ public function findRevisions(string $className, $id): array;
*
* @return array<string, array{old: mixed, new: mixed, same: mixed}>
*
* @phpstan-param class-string $className
* @phpstan-param class-string<T> $className
*/
public function diff(string $className, $id, $oldRevisionId, $newRevisionId): array;
}
3 changes: 3 additions & 0 deletions tests/Fixtures/Model/AuditReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
use Sonata\AdminBundle\Model\AuditReaderInterface;
use Sonata\AdminBundle\Model\Revision;

/**
* @phpstan-implements AuditReaderInterface<object>
*/
final class AuditReader implements AuditReaderInterface
{
public function find(string $className, $id, $revisionId): ?object
Expand Down

0 comments on commit 4fc33a0

Please sign in to comment.