ClientCreator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 49
c 0
b 0
f 0
ccs 16
cts 16
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 17 1
1
<?php
2
3
namespace LaFourchette\AdobeCampaignClientBundle\Client;
4
5
use LaFourchette\AdobeCampaignClientBundle\Client\Client;
6
7
/**
8
 * Create a Client for a given schema
9
 */
10
class ClientCreator
11
{
12
    const WSDL_PATH = '/nl/jsp/schemawsdl.jsp?schema=%s&__sessiontoken=%s';
13
14
    /**
15
     * @var ConfigurationProvider
16
     */
17
    private $configurationProvider;
18
19
    /**
20
     * @var ClientInstantiator
21
     */
22
    private $clientInstantiator;
23
24
    /**
25
     * @param ConfigurationProvider $configurationProvider
26
     * @param ClientInstantiator $clientInstantiator
27
     */
28 1
    public function __construct(ConfigurationProvider $configurationProvider, ClientInstantiator $clientInstantiator)
29
    {
30 1
        $this->configurationProvider = $configurationProvider;
31 1
        $this->clientInstantiator = $clientInstantiator;
32 1
    }
33
34
    /**
35
     * Build a Client based on a schema name
36
     *
37
     * @param string $schema
38
     *
39
     * @return Client
40
     */
41 1
    public function create($schema)
42
    {
43 1
        $configuration = $this->configurationProvider->getConfiguration();
44
45 1
        $client = $this->clientInstantiator->instantiateClient(
46 1
            $configuration->getBaseUri().sprintf(self::WSDL_PATH, $schema, $configuration->getSession())
47 1
        );
48
49 1
        $client->setSchema($schema);
50 1
        $client->setConfiguration($configuration);
51 1
        $client->setHttpHeaders(array(
52 1
            'X-Security-Token' => $configuration->getSecurity(),
53 1
            'cookie' => '__sessiontoken=' . $configuration->getSession(),
54 1
        ));
55
56 1
        return $client;
57
    }
58
}
59