Passed
Push — CONTROLLER_LIB_240925 ( abeb5d )
by Rafael
53:28
created

Dispatcher::processFolder()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 22
rs 9.9
1
<?php
2
3
/* Copyright (C) 2024       Rafael San José             <[email protected]>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
namespace Dolibarr\Core\Base;
20
21
use Alxarafe\Lib\Dispatcher as DispatcherBase;
22
23
class Dispatcher extends DispatcherBase
24
{
25
    /**
26
     * Process controller paths imported from Dolibarr. Try to locate it as a
27
     * modern controller first.
28
     *
29
     * This code is duplicated in Core/Dispatcher.
30
     * It can be refactored by creating an array with the possible "className" and
31
     * "filename", and looping through them all from Core/Dispatcher.
32
     * In that case, Dolibarr/Dispatcher would only have to add the new routes to
33
     * search for your drivers.
34
     *
35
     * @param string $module
36
     * @param string $controller
37
     * @return bool
38
     */
39
    protected static function processFolder(string $module, string $controller): bool
40
    {
41
        if (parent::processFolder($module, $controller)) {
0 ignored issues
show
Bug introduced by
The call to Alxarafe\Lib\Dispatcher::processFolder() has too few arguments starting with module. ( Ignorable by Annotation )

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

41
        if (parent::/** @scrutinizer ignore-call */ processFolder($module, $controller)) {

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
42
            return true;
43
        }
44
45
        $className = 'Dolibarr\\Code\\' . $module . '\\Controller\\' . $controller;
46
        $filename = realpath(constant('BASE_PATH') . '/../Dolibarr/Code/' . $module . '/Controller/' . $controller . '.php');
47
        // Debug::message('Filename: ' . $filename);
48
        // Debug::message('Class: ' . $className);
49
50
        if (!file_exists($filename)) {
51
            return false;
52
        }
53
54
        $controller = new $className();
55
        if ($controller === null) {
56
            return false;
57
        }
58
59
        $controller->index();
60
        return true;
61
    }
62
}
63