EntitySelect   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 68
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 3

10 Methods

Rating   Name   Duplication   Size   Complexity  
A select() 0 4 1
A __construct() 0 5 1
A findById() 0 4 1
A find() 0 4 1
A findOne() 0 4 1
A findAll() 0 4 1
A criteria() 0 5 1
A orderBy() 0 5 1
A offsetStart() 0 5 1
A offsetLength() 0 5 1
1
<?php
2
3
namespace Core\Utils\EntityUtils;
4
5
use Core\DatabaseManager;
6
use Doctrine\ORM\EntityRepository;
7
8
class EntitySelect
9
{
10
    /**
11
     * @var EntityRepository
12
     */
13
    private $repository = null;
14
15
    private $entityName = null;
16
    private $criteria = null;
17
    private $orderBy = null;
18
    private $offsetStart = null;
19
    private $offsetLength = null;
20
21
    public static function select($entityName)
22
    {
23
        return new self($entityName);
24
    }
25
26
    private function __construct($entityName)
27
    {
28
        $this->entityName = $entityName;
29
        $this->repository = DatabaseManager::getEntityManager()->getRepository($entityName);
30
    }
31
32
    public function findById($id)
33
    {
34
        return $this->repository->find($id);
35
    }
36
37
    public function find()
38
    {
39
        return $this->repository->findBy($this->criteria, $this->orderBy, $this->offsetLength, $this->offsetStart);
40
    }
41
42
    public function findOne()
43
    {
44
        return $this->repository->findOneBy($this->criteria, $this->orderBy);
45
    }
46
47
    public function findAll()
48
    {
49
        return $this->repository->findAll();
50
    }
51
52
    public function criteria(array $criteria)
53
    {
54
        $this->criteria = $criteria;
55
        return $this;
56
    }
57
58
    public function orderBy(array $orderBy)
59
    {
60
        $this->orderBy = $orderBy;
61
        return $this;
62
    }
63
64
    public function offsetStart($offsetStart)
65
    {
66
        $this->offsetStart = $offsetStart;
67
        return $this;
68
    }
69
70
    public function offsetLength($offsetLength)
71
    {
72
        $this->offsetLength = $offsetLength;
73
        return $this;
74
    }
75
}