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

ContactNameFormatter::format()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 8
rs 9.4285
cc 3
eloc 4
nc 3
nop 2
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