Email   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 126
ccs 0
cts 69
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A displayName() 0 4 1
A getText() 0 8 4
A getUrl() 0 4 2
A settings() 0 10 1
A attributes() 0 9 1
A rules() 0 35 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://raw.githubusercontent.com/flipboxfactory/craft-link/master/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-link
7
 */
8
9
namespace flipbox\craft\link\types;
10
11
use flipbox\craft\link\Link;
12
13
/**
14
 * @author Flipbox Factory <[email protected]>
15
 * @since 1.1.0
16
 */
17
class Email extends AbstractType
18
{
19
    /**
20
     * The base template path to the field type templates
21
     */
22
    const BASE_TEMPLATE_PATH = AbstractType::BASE_TEMPLATE_PATH . '/email';
23
24
    /**
25
     * The settings template path
26
     */
27
    const SETTINGS_TEMPLATE_PATH = self::BASE_TEMPLATE_PATH . '/settings';
28
29
    /**
30
     * The input template path
31
     */
32
    const INPUT_TEMPLATE_PATH = self::BASE_TEMPLATE_PATH . '/input';
33
34
    /**
35
     * @var bool
36
     */
37
    public $useEmailAsDefaultText = true;
38
39
    /**
40
     * @var string
41
     */
42
    public $email;
43
44
    /**
45
     * @var string|null The input’s placeholder text
46
     */
47
    public $placeholder;
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public static function displayName(): string
53
    {
54
        return Link::t('Email');
55
    }
56
57
    /**
58
     * @return string|null
59
     */
60
    public function getText()
61
    {
62
        if ($this->allowText && $this->overrideText !== null) {
63
            return $this->overrideText;
64
        }
65
66
        return $this->useEmailAsDefaultText ? $this->email : null;
67
    }
68
69
    /**
70
     * @return string
71
     */
72
    public function getUrl(): string
73
    {
74
        return $this->email ? ('mailto:' . $this->email) :  '';
75
    }
76
77
    /**
78
     * @inheritdoc
79
     */
80
    public function settings(): array
81
    {
82
        return array_merge(
83
            parent::settings(),
84
            [
85
                'placeholder',
86
                'useEmailAsDefaultText'
87
            ]
88
        );
89
    }
90
91
    /**
92
     * @inheritdoc
93
     */
94
    public function attributes()
95
    {
96
        return array_merge(
97
            parent::attributes(),
98
            [
99
                'email'
100
            ]
101
        );
102
    }
103
104
    /**
105
     * @inheritdoc
106
     */
107
    public function rules()
108
    {
109
        return array_merge(
110
            parent::rules(),
111
            [
112
                [
113
                    [
114
                        'email'
115
                    ],
116
                    'email',
117
                    'on' => [
118
                        self::SCENARIO_INPUT
119
                    ]
120
                ],
121
                [
122
                    [
123
                        'email'
124
                    ],
125
                    'required',
126
                    'on' => [
127
                        self::SCENARIO_INPUT
128
                    ]
129
                ],
130
                [
131
                    [
132
                        'email'
133
                    ],
134
                    'safe',
135
                    'on' => [
136
                        self::SCENARIO_DEFAULT
137
                    ]
138
                ]
139
            ]
140
        );
141
    }
142
}
143