Completed
Push — master ( e4d5a5...d16560 )
by Dawid
03:05
created

DataCollectorExtension::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiechu\SymfonyCommonsBundle\Twig;
6
7
use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
8
use Symfony\Component\Config\FileLocatorInterface;
9
10
class DataCollectorExtension extends \Twig_Extension
11
{
12
    /**
13
     * @var FileLocatorInterface
14
     */
15
    protected $fileLocator;
16
17
    /**
18
     * @param FileLocatorInterface $fileLocator
19
     */
20 16
    public function __construct(FileLocatorInterface $fileLocator)
21
    {
22 16
        $this->fileLocator = $fileLocator;
23 16
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 1
    public function getFunctions()
29
    {
30
        return [
31 1
            new \Twig_SimpleFunction('schema_file_exists', [$this, 'schemaFileExists']),
32
        ];
33
    }
34
35
    /**
36
     * @param string $schemaLocation
37
     *
38
     * @return bool
39
     */
40 14
    public function schemaFileExists(string $schemaLocation): bool
41
    {
42
        try {
43 14
            $this->fileLocator->locate($schemaLocation);
44
45 14
            return true;
46 1
        } catch (FileLocatorFileNotFoundException $e) {
47 1
            return false;
48
        }
49
    }
50
}
51