OgLocaleTag::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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