GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

MapMethods   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 91
ccs 36
cts 36
cp 1
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A mergeCommonData() 0 11 4
A getSetterMethodFromKey() 0 4 1
A fillNull() 0 19 4
A prepareMethodHandler() 0 19 3
1
<?php
2
3
namespace SmsaSDK\Concerns;
4
5
use SmsaSDK\Config;
6
7
trait MapMethods
8
{
9
    /**
10
     * mergeCommonData
11
     * Insert description here.
12
     *
13
     * @param $methodHandler
14
     * @param $arguments
15
     *
16
     * @return
17
     */
18 3
    private function mergeCommonData($methodHandler, $arguments = [])
19
    {
20 3
        foreach (Config::getCommonData() as $key => $value) {
21 3
            $setterMethod = $this->getSetterMethodFromKey($key);
22 3
            if (method_exists($methodHandler, $setterMethod) && !array_key_exists($key, $arguments)) {
23 3
                $methodHandler->$setterMethod($value);
24 3
            }
25 3
        }
26
27 3
        return $methodHandler;
28
    }
29
30
    /**
31
     * getSetterMethodFromKey
32
     * Insert description here.
33
     *
34
     * @param $key
35
     *
36
     * @return
37
     */
38 4
    private function getSetterMethodFromKey($key)
39
    {
40 4
        return 'set'.ucfirst($key);
41
    }
42
43
    /**
44
     * fillNull
45
     * Insert description here.
46
     *
47
     * @param $arguments
48
     * @param $value
49
     *
50
     * @return
51
     */
52 1
    private function fillNull($arguments, $value)
53
    {
54 1
        $missingArguments = [];
55 1
        $keys = array_keys($arguments);
56 1
        $commonKeys = array_keys(Config::getCommonData());
0 ignored issues
show
Unused Code introduced by
$commonKeys 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...
57 1
        $properties = $this->getReflectionProperties($this->reflection);
0 ignored issues
show
Bug introduced by
The property reflection does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
It seems like getReflectionProperties() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
58
59 1
        foreach ($properties as $key) {
60 1
            if (!in_array($key, $keys)) {
61 1
                $missingArguments[] = $key;
62 1
            }
63 1
        }
64
65 1
        foreach ($missingArguments as $key) {
66 1
            $arguments[$key] = $value;
67 1
        }
68
69 1
        return $arguments;
70
    }
71
72
    /**
73
     * @param $arguments
74
     * @param $class
75
     *
76
     * @return mixed
77
     */
78 6
    private function prepareMethodHandler($arguments, $class)
79
    {
80 6
        $this->validate($arguments, $class);
0 ignored issues
show
Bug introduced by
It seems like validate() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
81
82 3
        if ($this->nullValues !== null) {
83 1
            $arguments = $this->fillNull($arguments, $this->nullValues);
0 ignored issues
show
Bug introduced by
The property nullValues does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
84 1
        }
85
86 3
        $methodHandler = new $class();
87
88 3
        foreach ($arguments as $key => $value) {
89 3
            $setterMethod = $this->getSetterMethodFromKey($key);
90 3
            $methodHandler->$setterMethod($value);
91 3
        }
92
93 3
        $methodHandler = $this->mergeCommonData($methodHandler, $arguments);
94
95 3
        return $methodHandler;
96
    }
97
}
98