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

BaseViewFinder::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\View;
13
14
use BrightNucleus\View\Engine\Engine;
15
use BrightNucleus\View\Exception\FailedToInstantiateFindable;
16
use BrightNucleus\View\Support\AbstractFinder;
17
use BrightNucleus\View\View;
18
19
/**
20
 * Class BaseViewFinder.
21
 *
22
 * @since   0.1.0
23
 *
24
 * @package BrightNucleus\View\View
25
 * @author  Alain Schlesser <[email protected]>
26
 */
27
class BaseViewFinder extends AbstractFinder implements ViewFinder
28
{
29
30
    /**
31
     * Find a result based on a specific criteria.
32
     *
33
     * @since 0.1.0
34
     *
35
     * @param array       $criteria Criteria to search for.
36
     * @param Engine|null $engine   Optional. Engine to use with the view.
37
     *
38
     * @return View View that was found.
39 29
     * @throws FailedToInstantiateFindable If the Findable could not be instantiated.
40
     */
41 29
    public function find(array $criteria, Engine $engine = null): View
42
    {
43 29
        $uri = $criteria[0];
44
45 29
        $views = $this->initializeFindables([$uri, $engine]);
46 29
47 29
        foreach ($criteria as $entry) {
48 29
            foreach ($views as $viewObject) {
49
                if ($viewObject->canHandle($entry)) {
50
                    return $viewObject;
51
                }
52
            }
53
        }
54
55
        return $this->getNullObject();
56
    }
57
58
    /**
59
     * Get the config key for the Findables definitions.
60
     *
61
     * @since 0.1.0
62
     *
63 30
     * @return string Config key use to define the Findables.
64
     */
65 30
    protected function getFindablesConfigKey(): string
66
    {
67
        return 'Views';
68
    }
69
70
    /**
71
     * Get the NullObject.
72
     *
73
     * @since 0.1.1
74
     *
75
     * @return NullView NullObject for the current Finder.
76
     * @throws FailedToInstantiateFindable If the Findable could not be instantiated.
77
     */
78
    public function getNullObject(): NullView
79
    {
80
        return parent::getNullObject();
81
    }
82
}
83