Completed
Push — master ( 537a9c...19161d )
by Andrey
07:32
created

SitemapAbout   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getSitemapItems() 17 17 2
A getSitemapItemsQuery() 4 4 1
A getSitemapLoc() 4 4 1
A getSitemapLastmod() 4 4 1
A getSitemapChangefreq() 4 4 1
A getSitemapPriority() 4 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 app\models\sitemap;
4
5
use yii\helpers\Url;
6
use dreamjobs\sitemap\interfaces\Basic;
7
use app\models\About;
8
9
/**
10
 * Class SitemapAbout
11
 *
12
 * @package app\commands\models\sitemap
13
 */
14 View Code Duplication
class SitemapAbout extends About implements Basic
0 ignored issues
show
Duplication introduced by
This class 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...
15
{
16
    /**
17
     * Handle materials by selecting batch of elements.
18
     * Increase this value and got more handling speed but more memory usage.
19
     *
20
     * @var int
21
     */
22
    public $sitemapBatchSize = 10;
23
24
    /**
25
     * @var About
26
     */
27
    private $model;
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function getSitemapItems($lang = null)
33
    {
34
        $this->model = About::getDefaultAbout();
0 ignored issues
show
Documentation Bug introduced by
It seems like \app\models\About::getDefaultAbout() can also be of type object<yii\db\ActiveRecord> or array. However, the property $model is declared as type object<app\models\About>. 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...
35
36
        if (empty($this->model)) {
37
            return null;
38
        }
39
40
        return [
41
            [
42
                'loc' => Url::to('/about', true),
43
                'lastmod' => $this->getSitemapLastmod(),
44
                'changefreq' => $this->getSitemapChangefreq(),
45
                'priority' => $this->getSitemapPriority(),
46
            ],
47
        ];
48
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53
    public function getSitemapItemsQuery($lang = null)
54
    {
55
        return null;
56
    }
57
58
    /**
59
     * @inheritdoc
60
     */
61
    public function getSitemapLoc($lang = null)
62
    {
63
        return Url::to('/about', true);
64
    }
65
66
    /**
67
     * @inheritdoc
68
     */
69
    public function getSitemapLastmod($lang = null)
70
    {
71
        return (new \DateTime($this->model->updated_at))->getTimestamp();
72
    }
73
74
    /**
75
     * @inheritdoc
76
     */
77
    public function getSitemapChangefreq($lang = null)
78
    {
79
        return static::CHANGEFREQ_MONTHLY;
80
    }
81
82
    /**
83
     * @inheritdoc
84
     */
85
    public function getSitemapPriority($lang = null)
86
    {
87
        return static::PRIORITY_8;
88
    }
89
}
90