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
Pull Request — master (#52)
by joseph
38:21 queued 34:31
created

EntitySaverFactory::getSaverFqn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 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