Issues (536)

src/Cli/Commands/Routes/ControllerFinder.php (3 issues)

1
<?php
2
3
/**
4
 * This file is part of Blitz PHP framework.
5
 *
6
 * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace BlitzPHP\Cli\Commands\Routes;
13
14
use BlitzPHP\Contracts\Autoloader\LocatorInterface;
15
16
/**
17
 * Recherche tous les contrôleurs dans un namespace pour la liste des routes automatiques.
18
 */
19
final class ControllerFinder
20
{
21
    private readonly LocatorInterface $locator;
22
23
    /**
24
     * @param string $namespace Namespace dans lequel on recherche
25
     */
26
    public function __construct(private readonly string $namespace)
27
    {
28
        $this->locator = service('locator');
0 ignored issues
show
The property locator is declared read-only in BlitzPHP\Cli\Commands\Routes\ControllerFinder.
Loading history...
29
    }
30
31
    /**
32
     * @return list<string>
0 ignored issues
show
The type BlitzPHP\Cli\Commands\Routes\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
     */
34
    public function find(): array
35
    {
36
        $nsArray = explode('\\', trim($this->namespace, '\\'));
37
        $count   = count($nsArray);
38
        $ns      = '';
39
        $files   = [];
40
41
        for ($i = 0; $i < $count; $i++) {
42
            $ns .= '\\' . array_shift($nsArray);
43
            $path = implode('\\', $nsArray);
44
45
            $files = $this->locator->listNamespaceFiles($ns, $path);
46
47
            if ($files !== []) {
48
                break;
49
            }
50
        }
51
52
        $classes = [];
53
54
        foreach ($files as $file) {
55
            if (is_file($file)) {
56
                $classnameOrEmpty = $this->locator->getClassname($file);
57
58
                if ($classnameOrEmpty !== '') {
59
                    $classname = $classnameOrEmpty;
60
61
                    $classes[] = $classname;
62
                }
63
            }
64
        }
65
66
        return $classes;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $classes returns the type array|string[] which is incompatible with the documented return type BlitzPHP\Cli\Commands\Routes\list.
Loading history...
67
    }
68
}
69