Test Failed
Push — master ( dc68d1...1f5199 )
by Mathieu
02:31
created

Config   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 123
Duplicated Lines 6.5 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 8
loc 123
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 2
A setDefaultMetaTitle() 0 6 1
A setDefaultMetaDescription() 0 6 1
A setDefaultMetaImage() 0 6 1
A setDefaultMetaUrl() 0 6 1
A defaultMetaTitle() 0 4 1
A defaultMetaDescription() 0 4 1
A defaultMetaImage() 0 4 1
A defaultMetaUrl() 0 4 1

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 Charcoal\Cms;
4
5
// dependencies from `charcoal-base`
6
use Charcoal\Object\Content;
7
8
/**
9
 * Class Config
10
 */
11
class Config extends Content
12
{
13
    /**
14
     * @var string $defaultMetaTitle
15
     */
16
    protected $defaultMetaTitle;
17
18
    /**
19
     * @var string $defaultMetaDescription
20
     */
21
    protected $defaultMetaDescription;
22
23
    /**
24
     * @var string $defaultMetaImage
25
     */
26
    protected $defaultMetaImage;
27
28
    /**
29
     * @var string $defaultMetaUrl
30
     */
31
    protected $defaultMetaUrl;
32
33
    // ==========================================================================
34
    // INIT
35
    // ==========================================================================
36
37
    /**
38
     * Section constructor.
39
     * @param array $data The data.
40
     */
41 View Code Duplication
    public function __construct(array $data = null)
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...
42
    {
43
        parent::__construct($data);
44
45
        if (is_callable([$this, 'defaultData'])) {
46
            $this->setData($this->defaultData());
47
        }
48
    }
49
50
    // ==========================================================================
51
    // SETTERS
52
    // ==========================================================================
53
54
    /**
55
     * @param mixed $defaultMetaTitle The default meta title.
56
     * @return self
57
     */
58
    public function setDefaultMetaTitle($defaultMetaTitle)
59
    {
60
        $this->defaultMetaTitle = $this->translator()->translation($defaultMetaTitle);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->translator()->tra...tion($defaultMetaTitle) can also be of type object<Charcoal\Translator\Translation>. However, the property $defaultMetaTitle is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
61
62
        return $this;
63
    }
64
65
    /**
66
     * @param mixed $defaultMetaDescription The default meta description.
67
     * @return self
68
     */
69
    public function setDefaultMetaDescription($defaultMetaDescription)
70
    {
71
        $this->defaultMetaDescription = $this->translator()->translation($defaultMetaDescription);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->translator()->tra...defaultMetaDescription) can also be of type object<Charcoal\Translator\Translation>. However, the property $defaultMetaDescription is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
72
73
        return $this;
74
    }
75
76
    /**
77
     * @param mixed $defaultMetaImage The default meta image.
78
     * @return self
79
     */
80
    public function setDefaultMetaImage($defaultMetaImage)
81
    {
82
        $this->defaultMetaImage = $defaultMetaImage;
83
84
        return $this;
85
    }
86
87
    /**
88
     * @param mixed $defaultMetaUrl The default meta url.
89
     * @return self
90
     */
91
    public function setDefaultMetaUrl($defaultMetaUrl)
92
    {
93
        $this->defaultMetaUrl = $this->translator()->translation($defaultMetaUrl);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->translator()->translation($defaultMetaUrl) can also be of type object<Charcoal\Translator\Translation>. However, the property $defaultMetaUrl is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
94
95
        return $this;
96
    }
97
98
    // ==========================================================================
99
    // GETTERS
100
    // ==========================================================================
101
102
    /**
103
     * @return mixed
104
     */
105
    public function defaultMetaTitle()
106
    {
107
        return $this->defaultMetaTitle;
108
    }
109
110
    /**
111
     * @return mixed
112
     */
113
    public function defaultMetaDescription()
114
    {
115
        return $this->defaultMetaDescription;
116
    }
117
118
    /**
119
     * @return mixed
120
     */
121
    public function defaultMetaImage()
122
    {
123
        return $this->defaultMetaImage;
124
    }
125
126
    /**
127
     * @return mixed
128
     */
129
    public function defaultMetaUrl()
130
    {
131
        return $this->defaultMetaUrl;
132
    }
133
}
134