Completed
Push — master ( cd8605...3b7290 )
by
unknown
09:46
created

ContactNameFormatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 4
c 1
b 1
f 0
lcom 1
cbo 2
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A format() 0 8 3
1
<?php
2
3
namespace OroCRM\Bundle\ContactBundle\Formatter;
4
5
use Oro\Bundle\LocaleBundle\Formatter\NameFormatter;
6
7
use OroCRM\Bundle\ContactBundle\Entity\Contact;
8
9
class ContactNameFormatter
10
{
11
    /** @var NameFormatter */
12
    protected $nameFormatter;
13
14
    /**
15
     * @param NameFormatter $nameFormatter
16
     */
17
    public function __construct(NameFormatter $nameFormatter)
18
    {
19
        $this->nameFormatter = $nameFormatter;
20
    }
21
22
    /**
23
     * @param Contact $contact
24
     * @param string|null $locale
25
     *
26
     * @return string
27
     */
28
    public function format(Contact $contact, $locale = null)
29
    {
30
        if ($name = $this->nameFormatter->format($contact, $locale)) {
31
            return $name;
32
        }
33
34
        return (string) ($contact->getPrimaryPhone() ?: $contact->getPrimaryEmail());
35
    }
36
}
37