Passed
Push — master ( 8edd7c...9d0a3d )
by Dawid
03:01
created

DataCollectorExtension::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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