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

SitemapHome::getSitemapLastmod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 4
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace app\models\sitemap;
4
5
use yii\helpers\Url;
6
use dreamjobs\sitemap\interfaces\Basic;
7
use app\models\Home;
8
9
/**
10
 * Class SitemapHome
11
 *
12
 * @package app\commands\models\sitemap
13
 */
14 View Code Duplication
class SitemapHome extends Home 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 Home
26
     */
27
    private $model;
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function getSitemapItems($lang = null)
33
    {
34
        $this->model = Home::getDefaultHome();
0 ignored issues
show
Documentation Bug introduced by
It seems like \app\models\Home::getDefaultHome() can also be of type object<yii\db\ActiveRecord> or array. However, the property $model is declared as type object<app\models\Home>. 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('/', 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('/', 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