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 (#166)
by Ross
06:42
created

FakerDataFillerFactory   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 101
c 0
b 0
f 0
rs 10
ccs 0
cts 48
cp 0
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstanceFromEntityFqn() 0 5 1
A setCustomFakerDataFillersFqns() 0 3 1
A setFakerDataProviders() 0 5 1
A getInstanceFromDataTransferObjectFqn() 0 5 1
A setSeed() 0 5 1
A getInstanceFromDsm() 0 22 3
A __construct() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\EntityGenerator;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper;
7
use EdmondsCommerce\DoctrineStaticMeta\DoctrineStaticMeta;
8
9
class FakerDataFillerFactory
10
{
11
    /**
12
     * @var array
13
     */
14
    private $instances = [];
15
    /**
16
     * @var NamespaceHelper
17
     */
18
    private $namespaceHelper;
19
    /**
20
     * @var array
21
     */
22
    private $fakerDataProviders;
23
    /**
24
     * @var float|null
25
     */
26
    private $seed;
27
    /**
28
     * @var EntityManagerInterface
29
     */
30
    private $entityManager;
31
    /**
32
     * @var array
33
     */
34
    private $customFakerDataFillersFqns = [];
35
36
    public function __construct(NamespaceHelper $namespaceHelper, EntityManagerInterface $entityManager)
37
    {
38
        $this->namespaceHelper = $namespaceHelper;
39
        $this->entityManager   = $entityManager;
40
    }
41
42
    /**
43
     * @param array $customFakerDataFillersFqns
44
     */
45
    public function setCustomFakerDataFillersFqns(array $customFakerDataFillersFqns): void
46
    {
47
        $this->customFakerDataFillersFqns = $customFakerDataFillersFqns;
48
    }
49
50
    /**
51
     * @param array $fakerDataProviders
52
     *
53
     * @return FakerDataFillerFactory
54
     */
55
    public function setFakerDataProviders(?array $fakerDataProviders): FakerDataFillerFactory
56
    {
57
        $this->fakerDataProviders = $fakerDataProviders;
58
59
        return $this;
60
    }
61
62
    /**
63
     * @param float $seed
64
     *
65
     * @return FakerDataFillerFactory
66
     */
67
    public function setSeed(?float $seed): FakerDataFillerFactory
68
    {
69
        $this->seed = $seed;
70
71
        return $this;
72
    }
73
74
    public function getInstanceFromDataTransferObjectFqn(string $dtoFqn): FakerDataFillerInterface
75
    {
76
        $entityFqn = $this->namespaceHelper->getEntityFqnFromEntityDtoFqn($dtoFqn);
0 ignored issues
show
Deprecated Code introduced by
The function EdmondsCommerce\Doctrine...tyFqnFromEntityDtoFqn() has been deprecated: please use the static method on the DTO directly ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

76
        $entityFqn = /** @scrutinizer ignore-deprecated */ $this->namespaceHelper->getEntityFqnFromEntityDtoFqn($dtoFqn);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
77
78
        return $this->getInstanceFromEntityFqn($entityFqn);
79
    }
80
81
    public function getInstanceFromEntityFqn(string $entityFqn): FakerDataFillerInterface
82
    {
83
        $dsm = $entityFqn::getDoctrineStaticMeta();
84
85
        return $this->getInstanceFromDsm($dsm);
86
    }
87
88
    public function getInstanceFromDsm(DoctrineStaticMeta $doctrineStaticMeta): FakerDataFillerInterface
89
    {
90
        $entityFqn = $doctrineStaticMeta->getReflectionClass()->getName();
91
        if (array_key_exists($entityFqn, $this->instances)) {
92
            return $this->instances[$entityFqn];
93
        }
94
        if (null === $this->fakerDataProviders) {
95
            throw new \RuntimeException('You must call setFakerDataProviders before trying to get an instance');
96
        }
97
        $doctrineStaticMeta->setMetaData($this->entityManager->getMetadataFactory()->getMetadataFor($entityFqn));
98
99
        $fakerDataFillerFqn = $this->customFakerDataFillersFqns[$entityFqn] ?? FakerDataFiller::class;
100
101
        $this->instances[$entityFqn] = new $fakerDataFillerFqn(
102
            $this,
103
            $doctrineStaticMeta,
104
            $this->namespaceHelper,
105
            $this->fakerDataProviders,
106
            $this->seed
107
        );
108
109
        return $this->instances[$entityFqn];
110
    }
111
}
112