Completed
Pull Request — master (#40)
by
unknown
01:14
created

CompanyMapper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A map() 0 14 4
1
<?php
2
3
namespace TheIconic\NameParser\Mapper;
4
5
use TheIconic\NameParser\Part\Company;
6
7
/**
8
 * Mapper to identify a string as a company name
9
 */
10
11
class CompanyMapper extends AbstractMapper
12
{
13
    protected $companies = [];
14
15
    public function __construct(array $companies)
16
    {
17
        $this->companies = $this->sortArrayDescending($companies);
18
    }
19
20
    /**
21
     * map companies in the full name
22
     *
23
     * @param array $parts = the fullname
24
     * @return array
25
     */
26
    public function map(array $parts): array
27
    {
28
        if (count($parts) <> 1) {
29
            return [];
30
        }
31
32
        foreach ($this->companies as $company) {
33
            if (strpos($parts[0], $company) !== false) {
34
                return [new Company($parts[0])];
35
            }
36
        }
37
38
        return [];
39
    }
40
}
41