number2()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
use Xmf\Module\Admin;
14
use Xmf\Request;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Request. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
15
16
/**
17
 * @copyright 2019-2021 XOOPS Project (https://xoops.org)
18
 * @license   GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
19
 * @author    Richard Griffith <[email protected]>
20
 */
21
require __DIR__ . '/admin_header.php';
22
23
$moduleAdmin = Admin::getInstance();
24
$moduleAdmin->displayNavigation('index.php');
25
$autoloader = dirname(__DIR__) . '/vendor/autoload.php';
26
if (!file_exists($autoloader)) {
27
    $moduleAdmin->addConfigWarning(_MI_XWHOOPS_NEEDS_COMPOSER);
28
}
29
$moduleAdmin->displayIndex();
30
31
// example - bounces around and into an error
32
// will show xWhoops25 page if user has permission
33
$op = Request::getString('do');
34
if ('example' === $op) {
35
    require_once __DIR__ . '/ExampleClass.php';
36
    number1();
37
}
38
39
function number1(): void
40
{
41
    number3('test message');
42
}
43
44
function number2(ExampleClass $ec): void
45
{
46
    $msg = $ec->flawedMethod();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $msg is correct as $ec->flawedMethod() targeting ExampleClass::flawedMethod() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
The assignment to $msg is dead and can be removed.
Loading history...
47
}
48
49
function number3($msg): void
50
{
51
    number2(new ExampleClass($msg));
52
}
53
54
require __DIR__ . '/admin_footer.php';
55