Theme   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 18.87 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 10
loc 53
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fill() 10 11 3
A toArray() 0 4 1
A upToDate() 0 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Darkgoldblade01\Wordpress\Models;
4
5
/**
6
 * Class Model.
7
 */
8
class Theme
9
{
10
    /**
11
     * Fill the Model with
12
     * the data from the array.
13
     *
14
     * @param array $data
15
     *
16
     * @return Model
17
     */
18 View Code Duplication
    public function fill(array $data): Model
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
    {
20
        foreach ($data as $key => $value) {
21
            if ($key === 'url') {
22
                continue;
23
            }
24
            $this->{$key} = $value;
25
        }
26
27
        return $this;
28
    }
29
30
    /**
31
     * Convert the Model to an array.
32
     *
33
     * @return array
34
     */
35
    public function toArray(): array
36
    {
37
        return (array) $this;
38
    }
39
40
    /**
41
     * Up to Date.
42
     *
43
     * Checks the version of the current plugin vs. the
44
     * version supplied and returns true or false.
45
     *
46
     * If the plugin is greater than or equal to the current version,
47
     * return true, else return false.
48
     *
49
     * @param $version
50
     * @return bool
51
     */
52
    public function upToDate($version): bool
53
    {
54
        if (version_compare($this->version, $version, '>=')) {
0 ignored issues
show
Bug introduced by
The property version 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...
55
            return true;
56
        } else {
57
            return false;
58
        }
59
    }
60
}
61