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 (#370)
by
unknown
35:16
created

EnvDirectoryLocator::locateFiles()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 25
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 6
nc 4
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\IsAServiceTrait;
16
use Symfony\Component\Finder\Finder as SymfonyFinder;
17
18
final class EnvDirectoryLocator implements FixtureLocatorInterface
19
{
20
    use IsAServiceTrait;
21
22
    private $fixturesPath;
23
    private $kernelDir;
24
    private $projectDir;
25
26
    /**
27
     * @param string      $fixturePath Path to which to look for fixtures relative to the bundle path.
28
     * @param string      $kernelDir   Path of the kernel directory.
29
     * @param string|null $projectDir  Path of the project directory.
30
     */
31
    public function __construct(string $fixturePath, string $kernelDir, string $projectDir = null)
32
    {
33
        $this->fixturesPath = $fixturePath;
34
        $this->kernelDir = $kernelDir;
35
        $this->projectDir = $projectDir;
36
    }
37
38
    /**
39
     * Locate fixture files found inside a folder matching the environment name.
40
     *
41
     * For example, if the given fixture path is 'Resources/fixtures', it will try to locate
42
     * the files in the 'Resources/fixtures/dev' for each bundle passed ('dev' being the
43
     * environment).
44
     *
45
     * {@inheritdoc}
46
     */
47
    public function locateFiles(array $bundles, string $environment): array
48
    {
49
        $fixtureFiles = null === $this->projectDir ? [] : $this->doLocateFiles($this->projectDir, $environment);
50
51
        $fixtureFiles = array_merge($fixtureFiles, $this->doLocateFiles($this->kernelDir, $environment));
52
53
        foreach ($bundles as $bundle) {
54
            //// ---$fixtureFiles = $fixtureFiles + $this->doLocateFiles($bundle->getPath(), $environment);---
55
            // do not use "plus" operator:
56
            //    "... for keys that exist in both arrays, the elements from the left-hand array will be used,
57
            //    and the matching elements from the right-hand array will be IGNORED."
58
            //
59
            //        $bundle1Files = ['bundle1/001-A.php', 'bundle1/001-B.php', 'bundle1/001-C.php'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
60
            //        $bundle2Files = ['bundle2/001-A.php', 'bundle2/001-B.php', 'bundle2/001-C.php', 'bundle2/001-D.php'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
61
            //        ----------
62
            //        var_dump($bundle1Files + $bundle2Files);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
63
            //        > 4 elements: 3 from bundle1 + 1 from bundle2
64
            //
65
            //        var_dump(array_merge($bundle1Files, $bundle2Files));
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
66
            //        > 7 elements: 3 from bundle1 + 4 from bundle2
67
            $fixtureFiles = array_merge($fixtureFiles, $this->doLocateFiles($bundle->getPath(), $environment));
68
        }
69
70
        return $fixtureFiles;
71
    }
72
73
    private function doLocateFiles(string $path, string $environment): array
74
    {
75
        $path = '' !== $environment
76
            ? sprintf('%s/%s/%s', $path, $this->fixturesPath, $environment)
77
            : sprintf('%s/%s', $path, $this->fixturesPath)
78
        ;
79
        $path = realpath($path);
80
        if (false === $path || false === file_exists($path)) {
81
            return [];
82
        }
83
84
        $files = SymfonyFinder::create()->files()->in($path)->depth(0)->name('/.*\.(ya?ml|php)$/i');
85
86
        // this sort helps to set an order with filename ( "001-root-level-fixtures.yml", "002-another-level-fixtures.yml", ... )
87
        $files = $files->sort(function ($a, $b) {
88
            return strcasecmp($a, $b);
89
        });
90
91
        $fixtureFiles = [];
92
        foreach ($files as $file) {
93
            $fixtureFiles[$file->getRealPath()] = true;
94
        }
95
96
        return array_keys($fixtureFiles);
97
    }
98
}
99