Recipient   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 78
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getRawValue() 0 3 1
A getEmail() 0 3 1
A getIdentifier() 0 3 1
A dataPreProcessor() 0 13 2
A getName() 0 3 2
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * Copyright (C)
6
 * Nathan Boiron <[email protected]>
7
 * Romain Canon <[email protected]>
8
 *
9
 * This file is part of the TYPO3 NotiZ project.
10
 * It is free software; you can redistribute it and/or modify it
11
 * under the terms of the GNU General Public License, either
12
 * version 3 of the License, or any later version.
13
 *
14
 * For the full copyright and license information, see:
15
 * http://www.gnu.org/licenses/gpl-3.0.html
16
 */
17
18
namespace CuyZ\Notiz\Domain\Notification\Email\Application\EntityEmail\Settings\GlobalRecipients;
19
20
use CuyZ\Notiz\Core\Definition\Tree\AbstractDefinitionComponent;
21
use CuyZ\Notiz\Service\StringService;
22
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessor;
23
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessorInterface;
24
use Romm\ConfigurationObject\Traits\ConfigurationObject\StoreArrayIndexTrait;
25
26
class Recipient extends AbstractDefinitionComponent implements DataPreProcessorInterface
27
{
28
    use StoreArrayIndexTrait;
29
30
    const IDENTIFIER_PREFIX = '__NOTIZ_GLOBAL_RECIPIENT_';
31
32
    /**
33
     * @var string
34
     *
35
     * @validate NotEmpty
36
     * @validate EmailAddress
37
     */
38
    protected $email;
39
40
    /**
41
     * @var string
42
     */
43
    protected $name;
44
45
    /**
46
     * @var string
47
     */
48
    protected $rawValue;
49
50
    /**
51
     * @return string
52
     */
53
    public function getEmail(): string
54
    {
55
        return $this->email;
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getName(): string
62
    {
63
        return $this->name ?: $this->email;
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function getRawValue(): string
70
    {
71
        return $this->rawValue;
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getIdentifier(): string
78
    {
79
        return self::IDENTIFIER_PREFIX . $this->getArrayIndex();
80
    }
81
82
    /**
83
     * The given recipient is parsed to extract the name and the email.
84
     * Two format are supported:
85
     *
86
     * `John Smith <[email protected]>`
87
     * `[email protected]`
88
     *
89
     * @param DataPreProcessor $processor
90
     */
91
    public static function dataPreProcessor(DataPreProcessor $processor)
92
    {
93
        $data = $processor->getData();
94
        $data = is_array($data)
95
            ? $data
96
            : [];
97
98
        $formattedEmail = StringService::get()->formatEmailAddress($data['recipient']);
0 ignored issues
show
Bug introduced by
It seems like formatEmailAddress() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

98
        $formattedEmail = StringService::get()->/** @scrutinizer ignore-call */ formatEmailAddress($data['recipient']);
Loading history...
99
100
        $processor->setData([
101
            'email' => $formattedEmail['email'],
102
            'name' => $formattedEmail['name'],
103
            'rawValue' => $data['recipient'],
104
        ]);
105
    }
106
}
107