Address   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 12
c 2
b 1
f 1
dl 0
loc 31
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 15 5
A create() 0 3 1
A fromString() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nip\Mail\Utility;
6
7
use Symfony\Component\Mime\Address as SymfonyAddress;
8
9
/**
10
 *
11
 */
12
class Address
13
{
14
    public static function fromArray(array $addresses): array
15
    {
16
        $return = [];
17
        foreach ($addresses as $key => $value) {
18
            if (is_int($key)) {
19
                $return[$key] = static::fromString($value);
20
                continue;
21
            }
22
            if (is_string($key) && is_string($value)) {
23
                $return[] = static::create($key, $value);
24
                continue;
25
            }
26
        }
27
28
        return $return;
29
    }
30
31
    public static function fromString(string $string): SymfonyAddress
32
    {
33
        return SymfonyAddress::create($string);
34
    }
35
36
    /**
37
     * @param $email
38
     * @param $name
39
     */
40
    public static function create($email, $name = null): SymfonyAddress
41
    {
42
        return new SymfonyAddress($email, $name);
43
    }
44
}
45