BaseConfigurableRoadmap::hasNext()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
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\Roadmap;
17
18
use Veslo\AnthillBundle\Vacancy\ConfigurableRoadmapInterface;
19
20
/**
21
 * Base implementation of configurable roadmap
22
 *
23
 * Note: this is just a recommendation how roadmap can be organized, RoadmapInterface can be implemented directly.
24
 * In most cases for new job website you need to configure a similar service with customized strategy and configuration.
25
 * Search algorithm with website-specific code is encapsulated by StrategyInterface
26
 * Configuration storage, format and parameters for search algorithm is encapsulated by ConfigurationInterface
27
 */
28
class BaseConfigurableRoadmap implements ConfigurableRoadmapInterface
29
{
30
    /**
31
     * Vacancy search algorithm with website-specific code
32
     *
33
     * @var StrategyInterface
34
     */
35
    private $_strategy;
36
37
    /**
38
     * Configuration storage, format and parameters for search algorithm
39
     *
40
     * @var ConfigurationInterface
41
     */
42
    private $_configuration;
43
44
    /**
45
     * BaseConfigurableRoadmap constructor.
46
     *
47
     * @param StrategyInterface      $strategy      Vacancy search algorithm with website-specific code
48
     * @param ConfigurationInterface $configuration Configuration storage, format and parameters for search algorithm
49
     */
50
    public function __construct(StrategyInterface $strategy, ConfigurationInterface $configuration)
51
    {
52
        $this->_strategy      = $strategy;
53
        $this->_configuration = $configuration;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getStrategy(): StrategyInterface
60
    {
61
        return $this->_strategy;
62
    }
63
64
    /**
65
     * Returns roadmap configuration
66
     *
67
     * @return ConfigurationInterface
68
     */
69
    public function getConfiguration(): ConfigurationInterface
70
    {
71
        return $this->_configuration;
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function hasNext(): bool
78
    {
79
        $configuration = $this->getConfiguration();
80
81
        $vacancyUrl = $this->_strategy->lookup($configuration);
82
83
        return !empty($vacancyUrl);
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function next(): ?string
90
    {
91
        $configuration = $this->getConfiguration();
92
93
        $vacancyUrl = $this->_strategy->lookup($configuration);
94
95
        if (!empty($vacancyUrl)) {
96
            $this->_strategy->iterate($configuration);
97
        }
98
99
        return $vacancyUrl;
100
    }
101
}
102