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.

FakerDataFillerFactory::getInstanceFromEntityFqn()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 5
rs 10
ccs 0
cts 4
cp 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\EntityGenerator;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper;
9
use EdmondsCommerce\DoctrineStaticMeta\DoctrineStaticMeta;
10
use RuntimeException;
11
12
class FakerDataFillerFactory
13
{
14
    /**
15
     * @var array
16
     */
17
    private $instances = [];
18
    /**
19
     * @var NamespaceHelper
20
     */
21
    private $namespaceHelper;
22
    /**
23
     * @var array
24
     */
25
    private $fakerDataProviders;
26
    /**
27
     * @var float|null
28
     */
29
    private $seed;
30
    /**
31
     * @var EntityManagerInterface
32
     */
33
    private $entityManager;
34
    /**
35
     * @var array
36
     */
37
    private $customFakerDataFillersFqns = [];
38
39
    public function __construct(NamespaceHelper $namespaceHelper, EntityManagerInterface $entityManager)
40
    {
41
        $this->namespaceHelper = $namespaceHelper;
42
        $this->entityManager   = $entityManager;
43
    }
44
45
    /**
46
     * Custom Faker Data Fillers are used to generate bespoke fake data on an Entity FQN basis
47
     *
48
     * The array should contain Entity FQNs => Custom Faker Data Filler FQN
49
     *
50
     * The custom faker data filler must implement of FakerDataFillerInterface and can extend FakerDataFiller
51
     *
52
     * @param array<string, string> $customFakerDataFillersFqns
53
     */
54
    public function setCustomFakerDataFillersFqns(array $customFakerDataFillersFqns): void
55
    {
56
        $this->customFakerDataFillersFqns = $customFakerDataFillersFqns;
57
    }
58
59
    /**
60
     * @param array $fakerDataProviders
61
     *
62
     * @return FakerDataFillerFactory
63
     */
64
    public function setFakerDataProviders(?array $fakerDataProviders): FakerDataFillerFactory
65
    {
66
        $this->fakerDataProviders = $fakerDataProviders;
67
68
        return $this;
69
    }
70
71
    /**
72
     * @param float $seed
73
     *
74
     * @return FakerDataFillerFactory
75
     */
76
    public function setSeed(?float $seed): FakerDataFillerFactory
77
    {
78
        $this->seed = $seed;
79
80
        return $this;
81
    }
82
83
    public function getInstanceFromDataTransferObjectFqn(string $dtoFqn): FakerDataFillerInterface
84
    {
85
        $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

85
        $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...
86
87
        return $this->getInstanceFromEntityFqn($entityFqn);
88
    }
89
90
    public function getInstanceFromEntityFqn(string $entityFqn): FakerDataFillerInterface
91
    {
92
        $dsm = $entityFqn::getDoctrineStaticMeta();
93
94
        return $this->getInstanceFromDsm($dsm);
95
    }
96
97
    /**
98
     * This will return an instance of FakerDataFillerInterface
99
     *
100
     * If there has been configured a custom Faker Data Filler for the Entity FQN then an instance of that will be
101
     * returned, otherwise it will be the standard and generic Faker Data Filler
102
     *
103
     * If you want to register a custom faker data filler, you need to call setCustomFakerDataFillersFqns()
104
     *
105
     * @param DoctrineStaticMeta $doctrineStaticMeta
106
     *
107
     * @return FakerDataFillerInterface
108
     */
109
    public function getInstanceFromDsm(DoctrineStaticMeta $doctrineStaticMeta): FakerDataFillerInterface
110
    {
111
        $entityFqn = $doctrineStaticMeta->getReflectionClass()->getName();
112
        if (array_key_exists($entityFqn, $this->instances)) {
113
            return $this->instances[$entityFqn];
114
        }
115
        if (null === $this->fakerDataProviders) {
116
            throw new RuntimeException('You must call setFakerDataProviders before trying to get an instance');
117
        }
118
        $doctrineStaticMeta->setMetaData($this->entityManager->getMetadataFactory()->getMetadataFor($entityFqn));
119
120
        $fakerDataFillerFqn = $this->customFakerDataFillersFqns[$entityFqn] ?? FakerDataFiller::class;
121
122
        $this->instances[$entityFqn] = new $fakerDataFillerFqn(
123
            $this,
124
            $doctrineStaticMeta,
125
            $this->namespaceHelper,
126
            $this->fakerDataProviders,
127
            $this->seed
128
        );
129
130
        return $this->instances[$entityFqn];
131
    }
132
}
133