Completed
Push — master ( c5110b...a167e6 )
by Valentyn
13:46
created

CountriesFixtures::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 0
cts 14
cp 0
rs 9.6
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace App\Countries\DataFixtures;
4
5
use App\Countries\Entity\Country;
6
use App\Countries\Entity\ImdbCountry;
7
use Doctrine\Bundle\FixturesBundle\Fixture;
8
use Doctrine\Common\Persistence\ObjectManager;
9
use Doctrine\ORM\EntityManager;
10
11
class CountriesFixtures extends Fixture
12
{
13
    const COUNTRY_UKR_ID = 1;
14
    const COUNTRY_UKR_CODE = 'UKR';
15
    const COUNTRY_POL_ID = 2;
16
    const COUNTRY_POL_CODE = 'POL';
17
18
    public function load(ObjectManager $manager): void
19
    {
20
        if ($manager instanceof EntityManager === false) {
21
            throw new \InvalidArgumentException('UsersFixtures $manager should be instance of EntityManager');
22
        }
23
        /* @var $manager EntityManager */
24
25
        $ukr = new Country('Ukraine', 'UKR');
26
        $pol = new Country('Poland', 'POL');
27
        $imdbUkr = new ImdbCountry($ukr);
28
        $imdbPol = new ImdbCountry($pol);
29
30
        $manager->getConnection()->exec("ALTER SEQUENCE countries_id_seq RESTART WITH 1; UPDATE countries SET id=nextval('countries_id_seq');");
31
32
        $manager->persist($ukr);
33
        $manager->persist($pol);
34
        $manager->persist($imdbUkr);
35
        $manager->persist($imdbPol);
36
        $manager->flush();
37
    }
38
}
39