PactInitializer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 4
cts 4
cp 1
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
namespace SmartGamma\Behat\PactExtension\Context\Initializer;
4
5
use Behat\Behat\Context\Context;
6
use Behat\Behat\Context\Initializer\ContextInitializer;
7
use SmartGamma\Behat\PactExtension\Context\Authenticator;
8
use SmartGamma\Behat\PactExtension\Context\PactContextInterface;
9
use SmartGamma\Behat\PactExtension\Infrastructure\Pact;
10
use SmartGamma\Behat\PactExtension\Infrastructure\ProviderState\ProviderState;
11
12
class PactInitializer implements ContextInitializer
13
{
14
    /**
15
     * @var Pact
16
     */
17
    private $pact;
18
19
    /**
20
     * @var ProviderState
21
     */
22
    private $providerState;
23
24
    /**
25
     * @var Authenticator
26
     */
27
    private $authenticator;
28
29
    /**
30
     * PactInitializer constructor.
31
     *
32
     * @param Pact          $pact
33
     * @param ProviderState $providerState
34
     * @param Authenticator $authenticator
35
     */
36 3
    public function __construct(
37
        Pact $pact,
38
        ProviderState $providerState,
39
        Authenticator $authenticator
40
    )
41
    {
42 3
        $this->pact          = $pact;
43 3
        $this->providerState = $providerState;
44 3
        $this->authenticator = $authenticator;
45
    }
46
47
    /**
48
     * @param mixed $context
49
     *
50
     * @return bool
51
     */
52 2
    public function supports($context)
53
    {
54 2
        return $context instanceof PactContextInterface;
55
    }
56
57
    /**
58
     * @param Context $context
59
     *
60
     * @return bool
61
     */
62 2
    public function initializeContext(Context $context)
63
    {
64 2
        if (false === $this->supports($context)) {
65
66 1
            return false;
67
        }
68
69 1
        $context->initialize($this->pact, $this->providerState, $this->authenticator);
70
71 1
        return true;
72
    }
73
}
74