Completed
Pull Request — master (#75)
by
unknown
05:07
created

ApiClientContextInitializer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

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