GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#249)
by Théo
31:32
created

EnvFilesLocator::locateBundleFiles()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 3
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Hautelook\AliceBundle package.
5
 *
6
 * (c) Baldur Rensch <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Hautelook\AliceBundle\Locator;
13
14
use Hautelook\AliceBundle\FixtureLocatorInterface;
15
use Nelmio\Alice\NotClonableTrait;
16
use Symfony\Component\Finder\Finder as SymfonyFinder;
17
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
18
19
/**
20
 * @author Théo FIDRY <[email protected]>
21
 */
22 View Code Duplication
final class EnvFilesLocator implements FixtureLocatorInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
{
24
    use NotClonableTrait;
25
26
    /**
27
     * @var string
28
     */
29
    private $fixturesPath;
30
31
    /**
32
     * @param string $fixturePath Path to which to look for fixtures relative to the bundle path.
33
     */
34
    public function __construct(string $fixturePath)
35
    {
36
        $this->fixturesPath = $fixturePath;
37
    }
38
39
    /**
40
     * Locate fixture files found matching the environment name.
41
     *
42
     * For example, if the given fixture path is 'Resources/fixtures', it will try to locate
43
     * the files in the 'Resources/fixtures/*.dev.yml' for each bundle passed ('dev' being the
44
     * environment).
45
     *
46
     * {@inheritdoc}
47
     */
48
    public function locateFiles(array $bundles, string $environment): array
49
    {
50
        $fixtureFiles = [];
51
        foreach ($bundles as $bundle) {
52
            $fixtureFiles = $fixtureFiles + $this->locateBundleFiles($bundle, $environment);
53
        }
54
55
        return $fixtureFiles;
56
    }
57
58
    private function locateBundleFiles(BundleInterface $bundle, string $environment): array
59
    {
60
        $path = sprintf('%s/%s', $bundle->getPath(), $this->fixturesPath);
61
        if (false === file_exists($path)) {
62
            return [];
63
        }
64
65
        $pattern = sprintf('/.*\.%s(\..+)?\.(ya?ml|php)$/i', $environment);
66
        $files = SymfonyFinder::create()->files()->in($path)->name($pattern);
67
        $fixtureFiles = [];
68
        foreach ($files as $file) {
69
            $fixtureFiles[$file->getRealPath()] = true;
70
        }
71
72
        return array_keys($fixtureFiles);
73
    }
74
}
75