GuzzleAwareInitializer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 52
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A initializeContext() 0 9 2
1
<?php
2
/**
3
 * Behat Guzzle Extension
4
 *
5
 * PHP version 5
6
 *
7
 * @package Behat\GuzzleExtension
8
 * @author  Dave Nash <[email protected]>
9
 * @license http://opensource.org/licenses/MIT The MIT License
10
 * @version GIT: $Id$
11
 * @link    https://github.com/teaandcode/behat-guzzle-extension GuzzleExtension
12
 */
13
14
namespace Behat\GuzzleExtension\Context\Initializer;
15
16
use Behat\Behat\Context\Context;
17
use Behat\Behat\Context\Initializer\ContextInitializer;
18
use Behat\GuzzleExtension\Context\GuzzleAwareContext;
19
use Guzzle\Service\Client;
20
use Guzzle\Service\Description\ServiceDescription;
21
22
/**
23
 * Guzzle aware contexts initializer
24
 *
25
 * @package Behat\GuzzleExtension\Context\Initializer
26
 * @author  Dave Nash <[email protected]>
27
 * @license http://opensource.org/licenses/MIT The MIT License
28
 * @version Release: @package_version@
29
 * @link    https://github.com/teaandcode/behat-guzzle-extension GuzzleExtension
30
 */
31
class GuzzleAwareInitializer implements ContextInitializer
32
{
33
    /**
34
     * @var Client
35
     *
36
     * @access private
37
     */
38
    private $client;
39
40
    /**
41
     * @var array
42
     *
43
     * @access private
44
     */
45
    private $parameters;
46
47
    /**
48
     * Initializes initializer
49
     *
50
     * @param Client $client
51
     * @param array  $parameters
52
     */
53 3
    public function __construct(Client $client, array $parameters)
54
    {
55 3
        $this->client = $client;
56 3
        $this->parameters = $parameters;
57
58 3
        if (!empty($parameters['service_descriptions'])) {
59 3
            $this->client->setDescription(
60 3
                ServiceDescription::factory($parameters['service_descriptions'])
61 3
            );
62 3
        }
63 3
    }
64
65
    /**
66
     * Initializes provided context
67
     *
68
     * @param Context $context
69
     *
70
     * @access public
71
     * @return void
72
     */
73 2
    public function initializeContext(Context $context)
74
    {
75 2
        if (!$context instanceof GuzzleAwareContext) {
76 1
            return;
77
        }
78
79 1
        $context->setGuzzleClient($this->client);
80 1
        $context->setGuzzleParameters($this->parameters);
81 1
    }
82
}
83