Passed
Push — master ( ccc9fa...bee35f )
by Gabor
03:14
created

FileExistsHelper::getDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 7.1
6
 *
7
 * @copyright 2012 - 2017 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
declare(strict_types = 1);
13
14
namespace WebHemi\Renderer\Helper;
15
16
use WebHemi\Environment\ServiceInterface as EnvironmentInterface;
17
use WebHemi\Renderer\HelperInterface;
18
19
/**
20
 * Class FileExistsHelper.
21
 */
22
class FileExistsHelper implements HelperInterface
23
{
24
    /** @var string */
25
    private $applicationRoot;
26
27
    /**
28
     * Should return the name of the helper.
29
     *
30
     * @return string
31
     * @codeCoverageIgnore - plain text
32
     */
33
    public static function getName() : string
34
    {
35
        return 'fileExists';
36
    }
37
38
    /**
39
     * Should return the name of the helper.
40
     *
41
     * @return string
42
     * @codeCoverageIgnore - plain text
43
     */
44
    public static function getDefinition() : string
45
    {
46
        return '{% if fileExists("fileName") %}';
47
    }
48
49
    /**
50
     * Should return a description text.
51
     *
52
     * @return string
53
     * @codeCoverageIgnore - plain text
54
     */
55
    public static function getDescription() : string
56
    {
57
        return 'Checks if the given filepath exists under the application root.';
58
    }
59
60
    /**
61
     * Gets helper options for the render.
62
     *
63
     * @return array
64
     * @codeCoverageIgnore - empty array
65
     */
66
    public static function getOptions() : array
67
    {
68
        return [];
69
    }
70
71
    /**
72
     * DefinedHelper constructor.
73
     *
74
     * @param EnvironmentInterface   $environmentManager
75
     */
76 1
    public function __construct(EnvironmentInterface $environmentManager)
77
    {
78 1
        $this->applicationRoot = $environmentManager->getApplicationRoot();
79 1
    }
80
81
    /**
82
     * A renderer helper should be called with its name.
83
     *
84
     * @return bool
85
     */
86 1
    public function __invoke() : bool
87
    {
88 1
        $fileName = trim(func_get_args()[0], '/');
89
90 1
        return file_exists($this->applicationRoot.'/'.$fileName);
91
    }
92
}
93