Completed
Pull Request — develop (#39)
by Axel
14:01 queued 11:18
created

LoadFeedbackData   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 39
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setContainer() 0 3 1
A load() 0 20 2
A getOrder() 0 3 1
1
<?php
2
namespace Developtech\AgilityBundle\DataFixtures\ORM;
3
4
use Doctrine\Common\Persistence\ObjectManager;
5
use Doctrine\Common\DataFixtures\{
6
    AbstractFixture,
7
    OrderedFixtureInterface
8
};
9
use Symfony\Component\DependencyInjection\{
10
    ContainerInterface,
11
    ContainerAwareInterface
12
};
13
use Developtech\AgilityBundle\Entity\Feedback;
14
15
class LoadFeedbackData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface {
16
    /** @var ContainerInterface */
17
    private $container;
18
    /**
19
     * @param ContainerInterface $container
20
     */
21
    public function setContainer(ContainerInterface $container = null) {
22
        $this->container = $container;
0 ignored issues
show
Documentation Bug introduced by
It seems like $container can also be of type object<Symfony\Component...ion\ContainerInterface>. However, the property $container is declared as type object<ContainerInterface>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
23
    }
24
    /**
25
     * @param ObjectManager $manager
26
     */
27
    public function load(ObjectManager $manager) {
28
        $data = include('fixtures/feedbacks.php');
29
        foreach ($data as $feedbackData)
30
        {
31
            $feedback =
32
                (new Feedback())
33
                ->setId($feedbackData['id'])
34
                ->setProject($this->getReference("project-{$feedbackData['project_id']}"))
35
                ->setName($feedbackData['name'])
36
                ->setSlug($feedbackData['slug'])
37
                ->setDescription($feedbackData['description'])
38
                ->setStatus($feedbackData['status'])
39
                ->setCreatedAt(new \DateTime($feedbackData['created_at']))
40
                ->setUpdatedAt(new \DateTime($feedbackData['updated_at']))
41
            ;
42
            $manager->persist($feedback);
43
        }
44
        $manager->flush();
45
        $manager->clear(Feedback::class);
46
    }
47
    /**
48
     * @return int
49
     */
50
    public function getOrder() {
51
        return 2;
52
    }
53
}
54