AdapterFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
dl 0
loc 43
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1
ccs 12
cts 13
cp 0.9231
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A forSite() 0 4 1
A forVersion() 0 20 4
1
<?php
2
namespace Buttress\ConcreteClient\Adapter;
3
4
use Buttress\Concrete\Locator\Site;
5
use Buttress\ConcreteClient\Exception\VersionMismatchException;
6
7
class AdapterFactory
8
{
9
10
    /**
11
     * Get an adapter from a site object
12
     *
13
     * @param \Buttress\Concrete\Locator\Site $site
14
     * @return \Buttress\ConcreteClient\Adapter\Adapter
15
     * @throws \Buttress\ConcreteClient\Exception\VersionMismatchException
16
     */
17 4
    public function forSite(Site $site)
18
    {
19 4
        return $this->forVersion($site->getVersion());
20
    }
21
22
    /**
23
     * Get an adapter for a version
24
     *
25
     * @param string $version
26
     * @return \Buttress\ConcreteClient\Adapter\Adapter
27
     * @throws \Buttress\ConcreteClient\Exception\VersionMismatchException
28
     */
29 12
    public function forVersion($version)
30
    {
31 12
        if (version_compare($version, '5.6.0', '<')) {
32 4
            throw VersionMismatchException::expected('> 5.6.0', $version);
33
        }
34
35
        $map = [
36 8
            '5.6.9999' => Version6Adapter::class,
37 4
            '5.7.9999' => Version7Adapter::class,
38
            '8.9999' => Version8Adapter::class
39 4
        ];
40
41 8
        foreach ($map as $lessThan => $class) {
42 8
            if (version_compare($version, $lessThan, '<')) {
43 8
                return new $class;
44
            }
45 4
        }
46
47
        throw new VersionMismatchException('< 9.0.0', $version);
48
    }
49
}
50