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

ContactNameFormatter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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