Issues (16)

src/Loader/DirectoryLoader.php (6 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of DivineNii opensource projects.
7
 *
8
 * PHP version 7.4 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2021 DivineNii (https://divinenii.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Rade\DI\Loader;
19
20
use Rade\DI\ContainerBuilder;
21
use Symfony\Component\Config\Resource\FileExistenceResource;
22
use Symfony\Component\Config\Resource\GlobResource;
23
24
/**
25
 * DirectoryLoader is a recursive loader to go through directories.
26
 *
27
 * @author Divine Niiquaye Ibok <[email protected]>
28
 */
29
class DirectoryLoader extends FileLoader
30
{
31
    /**
32
     * {@inheritdoc}
33
     */
34 3
    public function load($file, string $type = null): void
35
    {
36 3
        $file = \rtrim($file, '/');
37 3
        $path = $this->locator->locate($file);
38
39 2
        if ($this->container instanceof ContainerBuilder) {
40 2
            $this->container->addResource(new FileExistenceResource($file));
0 ignored issues
show
The method addResource() does not exist on Rade\DI\AbstractContainer. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

40
            $this->container->/** @scrutinizer ignore-call */ 
41
                              addResource(new FileExistenceResource($file));
Loading history...
41 2
            $this->container->addResource(new GlobResource($path, '/*', false));
0 ignored issues
show
It seems like $path can also be of type array; however, parameter $prefix of Symfony\Component\Config...Resource::__construct() 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

41
            $this->container->addResource(new GlobResource(/** @scrutinizer ignore-type */ $path, '/*', false));
Loading history...
42
        }
43
44 2
        foreach (\scandir($path) as $dir) {
0 ignored issues
show
It seems like $path can also be of type array; however, parameter $directory of scandir() 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

44
        foreach (\scandir(/** @scrutinizer ignore-type */ $path) as $dir) {
Loading history...
45 2
            if ('.' !== $dir[0]) {
46 2
                if (\is_dir($path . '/' . $dir)) {
0 ignored issues
show
Are you sure $path of type array|string can be used in concatenation? ( Ignorable by Annotation )

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

46
                if (\is_dir(/** @scrutinizer ignore-type */ $path . '/' . $dir)) {
Loading history...
47 1
                    $dir .= '/'; // append / to allow recursion
48
                }
49
50 2
                $this->setCurrentDir($path);
0 ignored issues
show
It seems like $path can also be of type array; however, parameter $dir of Symfony\Component\Config...Loader::setCurrentDir() 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

50
                $this->setCurrentDir(/** @scrutinizer ignore-type */ $path);
Loading history...
51 2
                $this->import($dir, null, false, $path);
0 ignored issues
show
It seems like $path can also be of type array; however, parameter $sourceResource of Symfony\Component\Config...er\FileLoader::import() does only seem to accept null|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

51
                $this->import($dir, null, false, /** @scrutinizer ignore-type */ $path);
Loading history...
52
            }
53
        }
54 2
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 4
    public function supports($resource, string $type = null)
60
    {
61 4
        if ('directory' === $type) {
62 2
            return true;
63
        }
64
65 4
        return null === $type && \is_string($resource) && '/' === \substr($resource, -1);
66
    }
67
}
68