TwitterImageTag::prepForRender()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 10
ccs 0
cts 6
cp 0
crap 12
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * SEOmatic plugin for Craft CMS
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) 2017 nystudio107
10
 */
11
12
namespace nystudio107\seomatic\models\metatag;
13
14
use craft\validators\UrlValidator;
15
use nystudio107\seomatic\helpers\UrlHelper;
16
use nystudio107\seomatic\models\MetaTag;
17
18
/**
19
 * @author    nystudio107
20
 * @package   Seomatic
21
 * @since     3.0.0
22
 */
23
class TwitterImageTag extends MetaTag
24
{
25
    // Constants
26
    // =========================================================================
27
28
    public const ITEM_TYPE = 'TwitterImageTag';
29
30
    // Static Methods
31
    // =========================================================================
32
33
    // Public Properties
34
    // =========================================================================
35
36
    // Public Methods
37
    // =========================================================================
38
39
    /**
40
     * @inheritdoc
41
     */
42
    public function init(): void
43
    {
44
        parent::init();
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    public function rules(): array
51
    {
52
        $rules = parent::rules();
53
        $rules = array_merge($rules, [
54
            // content in this case should be a fully qualified URL
55
            [['content'], UrlValidator::class],
56
        ]);
57
58
        return $rules;
59
    }
60
61
    /**
62
     * @inheritdoc
63
     */
64
    public function prepForRender(&$data): bool
65
    {
66
        $shouldRender = parent::prepForRender($data);
67
        if ($shouldRender) {
68
            if (!empty($data['content'])) {
69
                $data['content'] = UrlHelper::absoluteUrlWithProtocol($data['content']);
70
            }
71
        }
72
73
        return $shouldRender;
74
    }
75
}
76