OneToOneStrategyPool   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A choose() 0 7 2
1
<?php
2
3
/*
4
 * This file is part of the Veslo project <https://github.com/symfony-doge/veslo>.
5
 *
6
 * (C) 2019 Pavel Petrov <[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
 * @license https://opensource.org/licenses/GPL-3.0 GPL-3.0
12
 */
13
14
declare(strict_types=1);
15
16
namespace Veslo\AnthillBundle\Vacancy\Scanner\StrategyPool;
17
18
use Veslo\AnthillBundle\Exception\Vacancy\Scanner\StrategyNotFoundException;
19
use Veslo\AnthillBundle\Vacancy\Scanner\StrategyInterface;
20
21
/**
22
 * Establishes one-to-one relation between vacancy search strategies and suitable parse strategies
23
 */
24
class OneToOneStrategyPool
25
{
26
    /**
27
     * Array of search to parse strategy mappings
28
     *
29
     * @var array
30
     */
31
    private $strategyMap;
32
33
    /**
34
     * OneToOneStrategyPool constructor.
35
     *
36
     * @param array $strategyMap Roadmap search strategy to parse strategy mappings
37
     */
38
    public function __construct(array $strategyMap)
39
    {
40
        $this->strategyMap = $strategyMap;
41
    }
42
43
    /**
44
     * Returns parse strategy that supports specified search strategy
45
     *
46
     * @param string $searchStrategyName Name of vacancy search algorithm for specific website-provider
47
     *
48
     * @return StrategyInterface Parsing strategy
49
     *
50
     * @throws StrategyNotFoundException
51
     */
52
    public function choose(string $searchStrategyName): StrategyInterface
53
    {
54
        if (!array_key_exists($searchStrategyName, $this->strategyMap)) {
55
            throw StrategyNotFoundException::withSearchStrategyName($searchStrategyName);
56
        }
57
58
        return $this->strategyMap[$searchStrategyName];
59
    }
60
}
61