VersionExtension::getFunctions()   A
last analyzed

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
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/* Copyright (C) 2016 Michael Giesler
3
 *
4
 * This file is part of Dembelo.
5
 *
6
 * Dembelo is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * Dembelo is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Affero General Public License 3 for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License 3
17
 * along with Dembelo. If not, see <http://www.gnu.org/licenses/>.
18
 */
19
namespace DembeloMain\Twig;
20
21
use Twig_Extension;
22
use Twig_Function;
23
24
/**
25
 * Class VersionExtension
26
 * This twig extensions adds a function "version()" to twig that reads the dembelo version number
27
 */
28
class VersionExtension extends Twig_Extension
29
{
30
    /**
31
     * @var string
32
     */
33
    private $versionFile;
34
35
    /**
36
     * @param string $versionFile
37
     */
38
    public function __construct(string $versionFile)
39
    {
40
        $this->versionFile = $versionFile;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getFunctions(): array
47
    {
48
        return array(
49
            new Twig_Function('dembeloversion', array($this, 'version')),
50
        );
51
    }
52
53
    /**
54
     * reads the version from filesystem and returns it
55
     * @return string
56
     */
57
    public function version(): string
58
    {
59
        return file_get_contents($this->versionFile);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function getName(): string
66
    {
67
        return 'dembelo_version';
68
    }
69
}
70