Completed
Push — master ( 06b24d...207a26 )
by Kevin
20s queued 17s
created

RepositoryStub::findAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 2
rs 10
eloc 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Zenstruck\Foundry\Tests\Unit;
4
5
use Doctrine\Persistence\ObjectRepository;
6
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Zenstruck\Foundry\RepositoryProxy;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 */
12
final class RepositoryProxyTest extends TestCase
13
{
14
    /**
15
     * @test
16
     * @dataProvider objectRepositoryWithoutFindOneByOrderBy
17
     */
18
    public function calling_find_one_by_with_order_by_when_wrapped_repo_does_not_have_throws_exception(ObjectRepository $inner): void
19
    {
20
        $proxy = new RepositoryProxy($inner);
21
22
        $this->expectException(\RuntimeException::class);
23
24
        $proxy->findOneBy([], ['id' => 'DESC']);
25
    }
26
27
    public static function objectRepositoryWithoutFindOneByOrderBy(): iterable
28
    {
29
        yield [new RepositoryProxy(new class() extends RepositoryStub {
30
            public function findOneBy(array $criteria): ?object
31
            {
32
            }
33
        })];
34
35
        yield [new RepositoryProxy(new class() extends RepositoryStub {
36
            public function findOneBy(array $criteria, ?array $foo = null): ?object
37
            {
38
            }
39
        })];
40
41
        yield [new RepositoryProxy(new class() extends RepositoryStub {
42
            public function findOneBy(array $criteria, $orderBy = null): ?object
43
            {
44
            }
45
        })];
46
47
        yield [new RepositoryProxy(new class() extends RepositoryStub {
48
            public function findOneBy(array $criteria, ?string $orderBy = null): ?object
49
            {
50
            }
51
        })];
52
    }
53
}
54
55
abstract class RepositoryStub implements ObjectRepository
56
{
57
    public function find($id): ?object
58
    {
59
    }
60
61
    public function findAll(): array
62
    {
63
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return array. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
64
65
    public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
66
    {
67
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return array. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
68
69
    public function getClassName(): string
70
    {
71
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
72
}
73