GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 647edc...edf045 )
by joseph
18s queued 16s
created

EntitySaverFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 56
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSaverForEntity() 0 9 2
A getSaverFqn() 0 9 1
A __construct() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Savers;
4
5
use Doctrine\ORM\EntityManager;
6
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface;
7
8
class EntitySaverFactory
9
{
10
    /**
11
     * @var EntityManager
12
     */
13
    protected $entityManager;
14
15
    /**
16
     * @var EntitySaver
17
     */
18
    protected $genericEntitySaver;
19
    /**
20
     * @var EntitySaver
21
     */
22
    protected $genericSaver;
23
24 3
    public function __construct(EntityManager $entityManager, EntitySaver $genericSaver)
25
    {
26 3
        $this->entityManager = $entityManager;
27 3
        $this->genericSaver = $genericSaver;
28 3
    }
29
30
    /**
31
     * Gets the Entity Specific Saver if one is defined, otherwise the standard Entity Saver
32
     *
33
     * @param EntityInterface $entity
34
     *
35
     * @return EntitySaverInterface
36
     */
37 2
    public function getSaverForEntity(
38
        EntityInterface $entity
39
    ): EntitySaverInterface {
40 2
        $saverFqn = $this->getSaverFqn($entity);
41 2
        if (class_exists($saverFqn)) {
42 1
            return new $saverFqn($this->entityManager);
43
        }
44
45 1
        return $this->genericSaver;
46
    }
47
48
    /**
49
     * Get the fully qualified name of the saver for the entity we are testing.
50
     *
51
     * @param EntityInterface $entity
52
     *
53
     * @return string
54
     */
55 2
    protected function getSaverFqn(
56
        EntityInterface $entity
57
    ): string {
58
59 2
        return \str_replace(
60 2
                   'Entities',
61 2
                   'Entity\\Savers',
62 2
                   \get_class($entity)
63 2
               ).'Saver';
64
    }
65
}
66