ConfigurationFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of Laravel HTTP Adapter.
5
 *
6
 * (c) Hidde Beydals <[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 HiddeCo\HttpAdapter;
13
14
use Ivory\HttpAdapter\Configuration;
15
16
class ConfigurationFactory
17
{
18
    /**
19
     * @var \Ivory\HttpAdapter\ConfigurationInterface
20
     */
21
    protected $configuration;
22
23
    /**
24
     * Create a new configuration factory instance.
25
     *
26
     * @param Configuration $configuration
27
     */
28
    public function __construct(Configuration $configuration)
29
    {
30
        $this->configuration = $configuration;
31
    }
32
33
    /**
34
     * Make a new configuration instance.
35
     *
36
     * @param array $config
37
     *
38
     * @return \Ivory\HttpAdapter\ConfigurationInterface
39
     */
40
    public function create(array $config)
41
    {
42
        foreach ($config as $key => $value) {
43
            $this->configuration->{$this->getMethod($key)}($value);
44
        }
45
46
        return $this->configuration;
47
    }
48
49
    /**
50
     * Gets a method name.
51
     *
52
     * @param string $property
53
     *
54
     * @return string
55
     */
56
    protected function getMethod($property)
57
    {
58
        return 'set'.str_replace('_', '', $property);
59
    }
60
}
61