Test Failed
Push — master ( 147d4d...670e11 )
by Alain
03:28
created

BaseEngineFinder::getNullObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php declare(strict_types=1);
2
/**
3
 * Bright Nucleus View Component.
4
 *
5
 * @package   BrightNucleus\View
6
 * @author    Alain Schlesser <[email protected]>
7
 * @license   MIT
8
 * @link      http://www.brightnucleus.com/
9
 * @copyright 2016-2017 Alain Schlesser, Bright Nucleus
10
 */
11
12
namespace BrightNucleus\View\Engine;
13
14
use BrightNucleus\View\Exception\FailedToInstantiateFindable;
15
use BrightNucleus\View\Support\AbstractFinder;
16
17
/**
18
 * Class BaseEngineFinder.
19
 *
20
 * @since   0.1.0
21
 *
22
 * @package BrightNucleus\View\Engine
23
 * @author  Alain Schlesser <[email protected]>
24
 */
25
class BaseEngineFinder extends AbstractFinder implements EngineFinder
26
{
27
28
    /**
29
     * Find a result based on a specific criteria.
30
     *
31
     * @since 0.1.0
32
     *
33
     * @param array $criteria Criteria to search for.
34
     *
35
     * @return Engine Result of the search.
36 30
     * @throws FailedToInstantiateFindable If the Findable could not be instantiated.
37
     */
38 30
    public function find(array $criteria): Engine
39
    {
40 30
        $this->findables = $this->initializeFindables();
41 30
42 30
        foreach ($criteria as $entry) {
43 30
            foreach ($this->findables as $engine) {
44
                if ($engine->canHandle($entry)) {
45
                    return $engine;
46
                }
47
            }
48 1
        }
49
50
        return $this->getNullObject();
51
    }
52
53
    /**
54
     * Get the config key for the Findables definitions.
55
     *
56
     * @since 0.1.0
57
     *
58 16
     * @return string Config key use to define the Findables.
59
     */
60 16
    protected function getFindablesConfigKey(): string
61
    {
62
        return 'Engines';
63
    }
64
65
    /**
66
     * Get the NullObject.
67
     *
68
     * @since 0.1.1
69
     *
70
     * @return NullEngine NullObject for the current Finder.
71
     * @throws FailedToInstantiateFindable If the Findable could not be instantiated.
72
     */
73
    public function getNullObject(): NullEngine
74
    {
75
        return parent::getNullObject();
76
    }
77
}
78