Yaml::isValid()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 17
rs 9.6111
cc 5
nc 5
nop 1
1
<?php
2
namespace Health\Checks\File;
3
4
use Health\Checks\HealthCheckInterface;
5
use Symfony\Component\Yaml\Exception\ParseException;
6
use Symfony\Component\Yaml\Parser;
7
8
class Yaml extends Base implements HealthCheckInterface
9
{
10
11
    /**
12
     *
13
     * @param string $file
14
     * @return boolean
15
     */
16
    protected function isValid($file)
17
    {
18
        if (function_exists('yaml_parse_file')) {
19
            return (@yaml_parse_file($file) === false) ? false : true;
20
        }
21
22
        if (class_exists('Symfony\Component\Yaml\Parser')) {
23
            try {
24
                (new Parser())->parse(file_get_contents($file));
25
            } catch (ParseException $e) {
26
                return false;
27
            }
28
29
            return true;
30
        }
31
32
        return false;
33
    }
34
}
35