Merge pull request #2952 from gnutix/ReturnTypeDeclarationRector/add-broken-test-array-index

ReturnTypeDeclarationRector: add broken test on array indexes (?)
This commit is contained in:
Tomas Votruba 2020-02-29 01:02:14 +01:00 committed by GitHub
commit c025d4c33d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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];
}
}