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 ( 0a6f96...b0c756 )
by Ross
12s queued 10s
created

EntitySaverFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSaverForEntity() 0 12 3
A getSaverFqn() 0 9 1
A __construct() 0 3 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
    public function __construct(EntityManager $entityManager)
21
    {
22
        $this->entityManager = $entityManager;
23
    }
24
25
    /**
26
     * Gets the Entity Specific Saver if one is defined, otherwise the standard Entity Saver
27
     *
28
     * @param EntityInterface $entity
29
     *
30
     * @return EntitySaverInterface
31
     */
32
    public function getSaverForEntity(
33
        EntityInterface $entity
34
    ): EntitySaverInterface {
35
        $saverFqn = $this->getSaverFqn($entity);
36
        if (class_exists($saverFqn)) {
37
            return new $saverFqn($this->entityManager);
38
        }
39
        if (null === $this->genericEntitySaver) {
40
            $this->genericEntitySaver = new EntitySaver($this->entityManager);
41
        }
42
43
        return $this->genericEntitySaver;
44
    }
45
46
    /**
47
     * Get the fully qualified name of the saver for the entity we are testing.
48
     *
49
     * @param EntityInterface $entity
50
     *
51
     * @return string
52
     */
53
    protected function getSaverFqn(
54
        EntityInterface $entity
55
    ): string {
56
57
        return \str_replace(
58
            'Entities',
59
            'Entity\\Savers',
60
            \get_class($entity)
61
        ).'Saver';
62
    }
63
}
64