Completed
Push — master ( 63e481...1e8bb2 )
by Dominik
01:52
created

Resolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A findResolver() 0 6 1
A findOneByResolver() 0 6 1
A findByCollection() 0 11 1
1
<?php
2
3
namespace Chubbyphp\Model;
4
5
use Chubbyphp\Model\Collection\LazyPersistedModelCollection;
6
7
final class Resolver implements ResolverInterface
8
{
9
    /**
10
     * @param RepositoryInterface $repository
11
     * @param string $id
12
     * @return \Closure
13
     */
14
    public function findResolver(RepositoryInterface $repository, string $id): \Closure
15
    {
16
        return function () use ($repository, $id) {
17
            return $repository->find($id);
18
        };
19
    }
20
21
    /**
22
     * @param RepositoryInterface $repository
23
     * @param array $criteria
24
     * @return \Closure
25
     */
26
    public function findOneByResolver(RepositoryInterface $repository, array $criteria): \Closure
27
    {
28
        return function () use ($repository, $criteria) {
29
            return $repository->findOneBy($criteria);
30
        };
31
    }
32
33
    /**
34
     * @param RepositoryInterface $repository
35
     * @param array $criteria
36
     * @param array|null $orderBy
37
     * @param int|null $limit
38
     * @param int|null $offset
39
     * @return LazyPersistedModelCollection
40
     */
41
    public function findByCollection(
42
        RepositoryInterface $repository,
43
        array $criteria, array
44
        $orderBy = null,
45
        int $limit = null,
46
        int $offset = null
47
    ): LazyPersistedModelCollection {
48
        return new LazyPersistedModelCollection(function () use ($repository, $criteria, $orderBy, $limit, $offset) {
49
            return $repository->findBy($criteria, $orderBy, $limit, $offset);
50
        });
51
    }
52
}
53