Passed
Push — master ( 785691...679eaf )
by Ross
39:28
created

AdminUserLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 33
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAdminUserDataPath() 0 4 1
A getAdminUserData() 0 11 2
A loadAdminUsers() 0 6 1
A loadAdminUsersRollback() 0 6 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: ross
5
 * Date: 13/05/17
6
 * Time: 23:03
7
 */
8
9
namespace Rossmitchell\Twofactor\Tests\Integration\FixtureLoader\Traits;
10
11
use Rossmitchell\Twofactor\Tests\Integration\FixtureLoader\AdminUser;
12
13
trait AdminUserLoader
14
{
15
    public static function getAdminUserDataPath()
16
    {
17
        return __DIR__.'/../_data/adminUser.php';
18
    }
19
20
    public static function getAdminUserData()
21
    {
22
        $adminData = null;
23
        $dataFile = self::getAdminUserDataPath();
24
        require $dataFile;
0 ignored issues
show
introduced by
"require" statement detected. File manipulations are discouraged. Variables inside are insecure.
Loading history...
25
        if (null === $adminData) {
26
            throw new \Exception("No Admin Data has been set");
0 ignored issues
show
introduced by
Direct throw of Exception is discouraged. Use \Magento\Framework\Exception\LocalizedException instead.
Loading history...
27
        }
28
29
        return $adminData;
30
    }
31
32
    public static function loadAdminUsers()
33
    {
34
        $customerData = self::getAdminUserData();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $customerData is correct as self::getAdminUserData() (which targets Rossmitchell\Twofactor\T...der::getAdminUserData()) 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...
35
        $customerLoader = new AdminUser($customerData);
0 ignored issues
show
introduced by
Direct object instantiation (object of AdminUser) is discouraged in Magento 2.
Loading history...
36
        $customerLoader->loadData();
37
    }
38
39
    public static function loadAdminUsersRollback()
40
    {
41
        $customerData = self::getAdminUserData();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $customerData is correct as self::getAdminUserData() (which targets Rossmitchell\Twofactor\T...der::getAdminUserData()) 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...
42
        $customerLoader = new AdminUser($customerData);
0 ignored issues
show
introduced by
Direct object instantiation (object of AdminUser) is discouraged in Magento 2.
Loading history...
Unused Code introduced by
$customerLoader is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
43
        #$customerLoader->rollBackData();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
44
    }
45
}
46