LoadOrganisations::getOrder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the vseth-semesterly-reports project.
5
 *
6
 * (c) Florian Moser <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace App\DataFixtures;
13
14
use App\DataFixtures\Base\BaseFixture;
15
use App\Entity\Organisation;
16
use Doctrine\Common\Persistence\ObjectManager;
17
use Symfony\Component\Serializer\SerializerInterface;
18
19
class LoadOrganisations extends BaseFixture
20
{
21
    const ORDER = 1;
22
23
    /**
24
     * @var SerializerInterface
25
     */
26
    private $serializer;
27
28
    /**
29
     * LoadEvent constructor.
30
     */
31
    public function __construct(SerializerInterface $serializer)
32
    {
33
        $this->serializer = $serializer;
34
    }
35
36
    /**
37
     * Load data fixtures with the passed EntityManager.
38
     */
39
    public function load(ObjectManager $manager)
40
    {
41
        //prepare resources
42
        $json = file_get_contents(__DIR__ . '/Resources/organisations.json');
43
        $organisations = $this->serializer->deserialize($json, Organisation::class . '[]', 'json');
44
45
        foreach ($organisations as $organisation) {
46
            $manager->persist($organisation);
47
        }
48
49
        $manager->flush();
50
    }
51
52
    /**
53
     * Get the order of this fixture.
54
     *
55
     * @return int
56
     */
57
    public function getOrder()
58
    {
59
        return static::ORDER;
60
    }
61
}
62