RbacConfigLoader   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 11
dl 0
loc 22
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A loadConfigs() 0 17 2
1
<?php
2
3
namespace Potievdev\SlimRbac\Component\Config;
4
5
use Potievdev\SlimRbac\Exception\ConfigNotFoundException;
6
use Symfony\Component\Config\Definition\Processor;
7
use Symfony\Component\Config\FileLocator;
8
use Symfony\Component\Yaml\Yaml;
9
10
class RbacConfigLoader
11
{
12
    /**
13
     * @throws ConfigNotFoundException
14
     */
15
    public static function loadConfigs(): array
16
    {
17
        $configDirectories = [
18
            __DIR__ . '/../../../config',
19
            __DIR__ . '/../../../../../',
20
            __DIR__ . '/../../../../../config',
21
        ];
22
23
        $fileLocator = new FileLocator($configDirectories);
24
        $fileName = $fileLocator->locate('sr_config.yaml');
25
26
        if ($fileName === null) {
0 ignored issues
show
introduced by
The condition $fileName === null is always false.
Loading history...
27
            throw ConfigNotFoundException::configFileNotFound($configDirectories);
28
        }
29
30
        return (new Processor())
31
            ->processConfiguration(new RbacConfigStructure(), Yaml::parseFile($fileName));
0 ignored issues
show
Bug introduced by
It seems like $fileName can also be of type string[]; however, parameter $filename of Symfony\Component\Yaml\Yaml::parseFile() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
            ->processConfiguration(new RbacConfigStructure(), Yaml::parseFile(/** @scrutinizer ignore-type */ $fileName));
Loading history...
32
    }
33
34
}