ApiClientAwareInitializer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 29
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A initializeContext() 0 6 2
1
<?php
2
3
/*
4
 * This file is part of the Behat WebApiExtension.
5
 * (c) Konstantin Kudryashov <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Behat\WebApiExtension\Context\Initializer;
12
13
use Behat\Behat\Context\Context;
14
use Behat\Behat\Context\Initializer\ContextInitializer;
15
use Behat\WebApiExtension\Context\ApiClientAwareContext;
16
use GuzzleHttp\ClientInterface;
17
18
/**
19
 * Guzzle-aware contexts initializer.
20
 *
21
 * Sets Guzzle client instance to the ApiClientAwareContext.
22
 *
23
 * @author Frédéric G. Marand <[email protected]>
24
 */
25
class ApiClientAwareInitializer implements ContextInitializer
26
{
27
    /**
28
     * @var ClientInterface
29
     */
30
    private $client;
31
32
    /**
33
     * Initializes initializer.
34
     *
35
     * @param ClientInterface $client
36
     */
37
    public function __construct(ClientInterface $client)
38
    {
39
        $this->client = $client;
40
    }
41
42
    /**
43
     * Initializes provided context.
44
     *
45
     * @param Context $context
46
     */
47
    public function initializeContext(Context $context)
48
    {
49
        if ($context instanceof ApiClientAwareContext) {
50
            $context->setClient($this->client);
51
        }
52
    }
53
}
54