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 (#153)
by joseph
29:27
created

FakerDataFillerFactory::setSeed()   A

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 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
ccs 0
cts 4
cp 0
crap 2
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
    public function __construct(NamespaceHelper $namespaceHelper, EntityManagerInterface $entityManager)
33
    {
34
        $this->namespaceHelper = $namespaceHelper;
35
        $this->entityManager   = $entityManager;
36
    }
37
38
    /**
39
     * @param array $fakerDataProviders
40
     *
41
     * @return FakerDataFillerFactory
42
     */
43
    public function setFakerDataProviders(?array $fakerDataProviders): FakerDataFillerFactory
44
    {
45
        $this->fakerDataProviders = $fakerDataProviders;
46
47
        return $this;
48
    }
49
50
    /**
51
     * @param float $seed
52
     *
53
     * @return FakerDataFillerFactory
54
     */
55
    public function setSeed(?float $seed): FakerDataFillerFactory
56
    {
57
        $this->seed = $seed;
58
59
        return $this;
60
    }
61
62
    public function getInstanceFromDataTransferObjectFqn(string $dtoFqn): FakerDataFiller
63
    {
64
        $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

64
        $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...
65
66
        return $this->getInstanceFromEntityFqn($entityFqn);
67
    }
68
69
    public function getInstanceFromEntityFqn(string $entityFqn): FakerDataFiller
70
    {
71
        $dsm = $entityFqn::getDoctrineStaticMeta();
72
73
        return $this->getInstanceFromDsm($dsm);
74
    }
75
76
    public function getInstanceFromDsm(DoctrineStaticMeta $doctrineStaticMeta)
77
    {
78
        $entityFqn = $doctrineStaticMeta->getReflectionClass()->getName();
79
        if (array_key_exists($entityFqn, $this->instances)) {
80
            return $this->instances[$entityFqn];
81
        }
82
        if (null === $this->fakerDataProviders) {
83
            throw new \RuntimeException('You must call setFakerDataProviders before trying to get an instance');
84
        }
85
        $doctrineStaticMeta->setMetaData($this->entityManager->getMetadataFactory()->getMetadataFor($entityFqn));
86
87
        $this->instances[$entityFqn] = new FakerDataFiller(
88
            $this,
89
            $doctrineStaticMeta,
90
            $this->namespaceHelper,
91
            $this->fakerDataProviders,
92
            $this->seed
93
        );
94
95
        return $this->instances[$entityFqn];
96
    }
97
}