Completed
Push — feature/middleware ( a35412...bb427e )
by Derek Stephen
03:50
created

DragonService   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 58
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createFromArray() 0 8 3
A saveDragon() 0 4 1
A deleteDragon() 0 4 1
A getRepository() 0 7 1
1
<?php
2
3
namespace BoneMvc\Module\Dragon\Service;
4
5
use BoneMvc\Module\Dragon\Entity\Dragon;
6
use BoneMvc\Module\Dragon\Repository\DragonRepository;
7
use Doctrine\ORM\EntityManager;
8
9
class DragonService
10
{
11
    /** @var EntityManager $em */
12
    private $em;
13
14
    /**
15
     * @param EntityManager $em
16
     */
17
    public function __construct(EntityManager $em)
18
    {
19
        $this->em = $em;
20
    }
21
22
    /**
23
     * @param array $data
24
     * @return $Dragon
0 ignored issues
show
Documentation introduced by
The doc-type $Dragon could not be parsed: Unknown type name "$Dragon" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
25
     */
26
    public function createFromArray(array $data)
27
    {
28
        $dragon = new Dragon();
29
        isset($data['id']) ? $dragon->setId($data['id']) : null;
30
        isset($data['name']) ? $dragon->setName($data['name']) : null;
31
32
        return $dragon;
33
    }
34
35
    /**
36
     * @param Dragon $dragon
37
     * @return Dragon
38
     * @throws \Doctrine\ORM\ORMException
39
     * @throws \Doctrine\ORM\OptimisticLockException
40
     */
41
    public function saveDragon(Dragon $dragon): Dragon
42
    {
43
        return $this->getRepository()->save($dragon);
44
    }
45
46
    /**
47
     * @param Dragon $dragon
48
     * @throws \Doctrine\ORM\ORMException
49
     * @throws \Doctrine\ORM\OptimisticLockException
50
     */
51
    public function deleteDragon(Dragon $dragon)
52
    {
53
        return $this->getRepository()->delete($dragon);
54
    }
55
56
    /**
57
     * @return DragonRepository
58
     */
59
    public function getRepository(): DragonRepository
60
    {
61
        /** @var DragonRepository $repository */
62
        $repository = $this->em->getRepository(Dragon::class);
63
64
        return $repository;
65
    }
66
}
67