AdapterResolver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A resolve() 0 20 4
1
<?php
2
3
/**
4
 * This file is part of cloak.
5
 *
6
 * (c) Noritaka Horio <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace cloak\analyzer;
13
14
use cloak\analyzer\adapter\AdapterNotFoundException;
15
use cloak\analyzer\adapter\AdapterNotAvailableException;
16
17
18
/**
19
 * Class AdapterResolver
20
 * @package cloak\analyzer
21
 */
22
class AdapterResolver implements AdapterResolvable
23
{
24
25
    /**
26
     * @var array
27
     */
28
    private $adapters;
29
30
31
    /**
32
     * @param array $adapters
33
     */
34
    public function __construct(array $adapters)
35
    {
36
        $this->adapters = $adapters;
37
    }
38
39
    /**
40
     * @return \cloak\analyzer\AnalyzeAdapter
41
     * @throws AdapterNotFoundException
42
     */
43
    public function resolve()
44
    {
45
        $result = null;
46
        $exceptions = [];
47
48
        foreach ($this->adapters as $adapter) {
49
            try {
50
                $result = new $adapter();
51
                break;
52
            } catch (AdapterNotAvailableException $exception) {
53
                $exceptions[] = $exception->getMessage();
54
            }
55
        }
56
57
        if (count($exceptions) === count($this->adapters)) {
58
            throw new AdapterNotFoundException($exceptions);
59
        }
60
61
        return $result;
62
    }
63
64
}
65