Completed
Push — master ( 651d7b...ccffc6 )
by Dawid
02:51
created

DataCollectorExtension::schemaFileExists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

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