LocatorStrategyFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createStrategy() 0 9 2
A determineStrategy() 0 7 2
1
<?php
2
/**
3
 * Webino (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino/WebinoDraw for the canonical source repository
6
 * @copyright   Copyright (c) 2012-2017 Webino, s. r. o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoDraw\Dom\Factory;
12
13
use WebinoDraw\Exception\OutOfBoundsException;
14
15
/**
16
 *
17
 */
18
class LocatorStrategyFactory
19
{
20
    const DEFAULT_STRATEGY = 'css';
21
22
    /**
23
     * Available strategies
24
     *
25
     * @var array
26
     */
27
    protected static $strategyList = [
28
        'css'   => 'WebinoDraw\Dom\Locator\Strategy\CssStrategy',
29
        'xpath' => 'WebinoDraw\Dom\Locator\Strategy\XpathStrategy',
30
    ];
31
32
    /**
33
     * @param string $type Strategy type
34
     * @return TransformatorInterface
35
     * @throws OutOfBoundsException
36
     */
37
    public function createStrategy($type)
38
    {
39
        $strategy = $this->determineStrategy($type);
40
        if (empty(self::$strategyList[$strategy])) {
41
            throw new OutOfBoundsException('Dont\'t know strategy type ' . $strategy);
42
        }
43
44
        return new self::$strategyList[$strategy];
45
    }
46
47
    /**
48
     * Return provided or default strategy type
49
     *
50
     * @param string $type
51
     * @return string
52
     */
53
    protected function determineStrategy($type)
54
    {
55
        if (empty($type)) {
56
            return self::DEFAULT_STRATEGY;
57
        }
58
        return $type;
59
    }
60
}
61