Issues (16)

src/Json/Loader/YamlLoader.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the OpenapiBundle package.
7
 *
8
 * (c) Niels Nijens <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Nijens\OpenapiBundle\Json\Loader;
15
16
use Nijens\OpenapiBundle\Json\Exception\LoaderLoadException;
17
use stdClass;
18
use Symfony\Component\Yaml\Exception\ParseException;
19
use Symfony\Component\Yaml\Yaml;
20
21
/**
22
 * Loads JSON schema files in YAML format.
23
 *
24
 * @author Niels Nijens <[email protected]>
25
 */
26
final class YamlLoader implements LoaderInterface
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function supports(string $file): bool
32
    {
33
        return in_array(pathinfo($file, PATHINFO_EXTENSION), ['yaml', 'yml']);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function load(string $file): stdClass
40
    {
41
        try {
42
            return Yaml::parseFile($file, Yaml::PARSE_OBJECT_FOR_MAP | Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Symfony\Component...EPTION_ON_INVALID_TYPE) also could return the type Symfony\Component\Yaml\Tag\TaggedValue|null|string which is incompatible with the return type mandated by Nijens\OpenapiBundle\Jso...LoaderInterface::load() of stdClass.
Loading history...
43
        } catch (ParseException $exception) {
44
            throw new LoaderLoadException($exception->getMessage(), 0, $exception);
45
        }
46
    }
47
}
48