VisitsFixture::load()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 19
rs 9.9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioApiTest\Shlink\Rest\Fixtures;
6
7
use Doctrine\Common\DataFixtures\AbstractFixture;
8
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
9
use Doctrine\Persistence\ObjectManager;
10
use Shlinkio\Shlink\Core\Entity\ShortUrl;
11
use Shlinkio\Shlink\Core\Entity\Visit;
12
use Shlinkio\Shlink\Core\Model\Visitor;
13
14
class VisitsFixture extends AbstractFixture implements DependentFixtureInterface
15
{
16
    public function getDependencies(): array
17
    {
18
        return [ShortUrlsFixture::class];
19
    }
20
21
    public function load(ObjectManager $manager): void
22
    {
23
        /** @var ShortUrl $abcShortUrl */
24
        $abcShortUrl = $this->getReference('abc123_short_url');
25
        $manager->persist(new Visit($abcShortUrl, new Visitor('shlink-tests-agent', '', '44.55.66.77')));
26
        $manager->persist(new Visit($abcShortUrl, new Visitor('shlink-tests-agent', 'https://google.com', '4.5.6.7')));
27
        $manager->persist(new Visit($abcShortUrl, new Visitor('shlink-tests-agent', '', '1.2.3.4')));
28
29
        /** @var ShortUrl $defShortUrl */
30
        $defShortUrl = $this->getReference('def456_short_url');
31
        $manager->persist(new Visit($defShortUrl, new Visitor('shlink-tests-agent', '', '127.0.0.1')));
32
        $manager->persist(new Visit($defShortUrl, new Visitor('shlink-tests-agent', 'https://app.shlink.io', '')));
33
34
        /** @var ShortUrl $defShortUrl */
35
        $defShortUrl = $this->getReference('ghi789_short_url');
36
        $manager->persist(new Visit($defShortUrl, new Visitor('shlink-tests-agent', '', '1.2.3.4')));
37
        $manager->persist(new Visit($defShortUrl, new Visitor('shlink-tests-agent', 'https://app.shlink.io', '')));
38
39
        $manager->flush();
40
    }
41
}
42