Completed
Pull Request — master (#40)
by
unknown
01:17
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
 * @author Volker Püschel <[email protected]>
10
 * @copyright 2019 Volker Püschel
11
 * @license MIT
12
 */
13
14
class CompanyMapper extends AbstractMapper
15
{
16
    protected $companies = [];
17
18
    public function __construct(array $companies)
19
    {
20
        $this->companies = $this->sortArrayDescending($companies);
21
    }
22
23
    /**
24
     * map companies in the full name
25
     *
26
     * @param array $parts = the fullname
27
     * @return array
28
     */
29
    public function map(array $parts): array
30
    {
31
        if (count($parts) <> 1) {
32
            return [];
33
        }
34
35
        foreach ($this->companies as $company) {
36
            if (strpos($parts[0], $company) !== false) {
37
                return [new Company($parts[0])];
38
            }
39
        }
40
41
        return [];
42
    }
43
}
44