mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 03:35:01 +01:00
Merge pull request #2952 from gnutix/ReturnTypeDeclarationRector/add-broken-test-array-index
ReturnTypeDeclarationRector: add broken test on array indexes (?)
This commit is contained in:
commit
c025d4c33d
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\ReturnTypeDeclarationRector\Fixture;
|
||||
|
||||
interface RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param int[] $ids
|
||||
* @param int[] $expenseReportIds
|
||||
*
|
||||
* @return \stdClass[]
|
||||
*/
|
||||
public function listBy(?array $ids = null, ?array $expenseReportIds = null): array;
|
||||
}
|
||||
|
||||
final class SkipArrayIndex
|
||||
{
|
||||
/**
|
||||
* @var RepositoryInterface
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
public function __construct(RepositoryInterface $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function __invoke(object $query): \stdClass
|
||||
{
|
||||
$objects = $this->repository->listBy([$query->id]);
|
||||
|
||||
if (empty($objects)) {
|
||||
throw new \InvalidArgumentException($query->id);
|
||||
}
|
||||
|
||||
if (1 !== count($objects)) {
|
||||
throw new \UnexpectedValueException();
|
||||
}
|
||||
|
||||
return $objects[0];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user