Passed
Branch v3 (6ce356)
by Andrew
11:37 queued 02:32
created

HomeLink::prepForRender()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 18
ccs 0
cts 10
cp 0
crap 20
rs 9.9666
1
<?php
2
/**
3
 * SEOmatic plugin for Craft CMS 3.x
4
 *
5
 * A turnkey SEO implementation for Craft CMS that is comprehensive, powerful,
6
 * and flexible
7
 *
8
 * @link      https://nystudio107.com
9
 * @copyright Copyright (c) 2020 nystudio107
10
 */
11
12
namespace nystudio107\seomatic\models\metalink;
13
14
use nystudio107\seomatic\Seomatic;
15
use nystudio107\seomatic\models\MetaLink;
16
use nystudio107\seomatic\helpers\UrlHelper;
17
18
use craft\helpers\StringHelper;
19
20
/**
21
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
22
 * @package   Seomatic
23
 * @since     3.3.14
24
 */
25
class HomeLink extends MetaLink
26
{
27
    // Constants
28
    // =========================================================================
29
30
    const ITEM_TYPE = 'HomeLink';
31
32
    // Static Methods
33
    // =========================================================================
34
35
    // Public Properties
36
    // =========================================================================
37
38
    // Public Methods
39
    // =========================================================================
40
41
    /**
42
     * @inheritdoc
43
     */
44
    public function init()
45
    {
46
        parent::init();
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function rules()
53
    {
54
        $rules = parent::rules();
55
        $rules = array_merge($rules, [
56
        ]);
57
58
        return $rules;
59
    }
60
61
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $data should have a doc-comment as per coding-style.
Loading history...
62
     * @inheritdoc
63
     */
64
    public function prepForRender(&$data): bool
65
    {
66
        $shouldRender = parent::prepForRender($data);
67
        if ($shouldRender) {
68
            // Ensure the href is a full url
69
            if (!empty($data['href'])) {
70
                if (Seomatic::$settings->lowercaseCanonicalUrl) {
71
                    $data['href'] = StringHelper::toLowerCase($data['href']);
72
                }
73
                $url = UrlHelper::absoluteUrlWithProtocol($data['href']);
74
                // The URL should be stripped of its query string already, but because
75
                // Craft adds the `token` URL param back in via UrlHelper, strip it again
76
                $url = preg_replace('/\?.*/', '', $url);
77
                $data['href'] = $url;
78
            }
79
        }
80
81
        return $shouldRender;
82
    }
83
}
84