DeviceContext::__construct()   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
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Alpha\VisitorTrackingBundle\Features\Context;
4
5
use Alpha\VisitorTrackingBundle\Entity\Session;
6
use Alpha\VisitorTrackingBundle\EventListener\VisitorTrackingSubscriber;
7
use Behat\Behat\Context\Context;
8
use Behat\Behat\Context\SnippetAcceptingContext;
9
use Behat\MinkExtension\Context\RawMinkContext;
10
use Doctrine\Inflector\InflectorFactory;
11
use Doctrine\ORM\EntityManagerInterface;
12
use Alpha\VisitorTrackingBundle\Entity\Lifetime;
13
14
class DeviceContext extends RawMinkContext implements Context, SnippetAcceptingContext
0 ignored issues
show
Deprecated Code introduced by
The interface Behat\Behat\Context\SnippetAcceptingContext has been deprecated: will be removed in 4.0. Use --snippets-for CLI option instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

14
class DeviceContext extends RawMinkContext implements Context, /** @scrutinizer ignore-deprecated */ SnippetAcceptingContext

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
15
{
16
    private $entityManager;
17
18
    /**
19
     * @var array<int, string>
20
     */
21
    private $utmCodes = [
22
        'utm_source',
23
        'utm_medium',
24
        'utm_campaign',
25
        'utm_term',
26
        'utm_content'
27
    ];
28
29
    public function __construct(EntityManagerInterface $entityManager)
30
    {
31
        $this->entityManager = $entityManager;
32
    }
33
34
    /**
35
     * @Given /^a user session exists$/
36
     */
37
    public function theCookieHasTheValue(): void
38
    {
39
        $session = new Session();
40
        $session->setIp('127.0.0.1');
41
        $session->setReferrer('');
42
        $session->setUserAgent('');
43
        $session->setQueryString('');
44
        $session->setLoanTerm('');
45
        $session->setRepApr('');
46
        foreach ($this->utmCodes as $code) {
47
            $method = 'set'.InflectorFactory::create()->build()->classify($code);
48
            $session->$method('');
49
        }
50
51
        $lifetime = new Lifetime();
52
        $lifetime->addSession($session);
53
        $session->setLifetime($lifetime);
54
55
        $this->entityManager->persist($lifetime);
56
        $this->entityManager->persist($session);
57
        $this->entityManager->flush();
58
59
        $this->getSession()->setCookie(VisitorTrackingSubscriber::COOKIE_SESSION, $session->getId());
60
    }
61
}
62