CompanyService   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 2
cbo 3
dl 37
loc 37
ccs 11
cts 11
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parseArrayToEntity() 7 7 1
A getLink() 4 4 1
A add() 6 6 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace linkprofit\AmoCRM\services;
4
5
use linkprofit\AmoCRM\entities\Company;
6
use linkprofit\AmoCRM\entities\EntityInterface;
7
8
/**
9
 * Class CompanyService
10
 * @package linkprofit\AmoCRM\services
11
 */
12 View Code Duplication
class CompanyService extends BaseService
13
{
14
    /**
15
     * @var Company[]
16
     */
17
    protected $entities = [];
18
19
    /**
20
     * @param Company $company
21
     */
22 4
    public function add(EntityInterface $company)
23
    {
24 4
        if ($company instanceof Company) {
25 4
            $this->entities[] = $company;
26 4
        }
27 4
    }
28
29
    /**
30
     * @param $array
31
     * @return Company
32
     */
33 4
    public function parseArrayToEntity($array)
34
    {
35 4
        $company = new Company();
36 4
        $company->set($array);
37
38 4
        return $company;
39
    }
40
41
    /**
42
     * @return string
43
     */
44 4
    protected function getLink()
45
    {
46 4
        return 'https://' . $this->request->getSubdomain() . '.amocrm.ru/api/v2/companies';
47
    }
48
}