Fields   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 71
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 71
loc 71
ccs 15
cts 20
cp 0.75
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A addMapping() 4 4 1
A find() 10 10 3
A findByName() 12 12 3
A findById() 3 3 1

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
/*
4
 * A php library for using the Emarsys API.
5
 *
6
 * @link      https://github.com/quitoque/emarsys-php-client
7
 * @package   emarsys-php-client
8
 * @license   MIT
9
 * @copyright Copyright (c) 2017 Quitoque <[email protected]>
10
 */
11
12
namespace Emarsys\Mapping;
13
14
use Emarsys\Exception\Mapping\NotFoundFieldException;
15
16
/**
17
 * Class Fields.
18
 *
19
 * @author Claude Khedhiri <[email protected]>
20
 */
21 View Code Duplication
class Fields
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
{
23
    /**
24
     * @var array
25
     */
26
    private $mapping = array();
27
28
    /**
29
     * @var array
30
     */
31
    private $systemFields = array();
32
33
    /**
34
     * Fields constructor.
35
     */
36 4
    public function __construct()
37
    {
38 4
        $this->systemFields = require __DIR__.'/../../config/fields.php';
39 4
    }
40
41
    /**
42
     * @param array $mapping
43
     */
44 1
    public function addMapping(array $mapping)
45
    {
46 1
        $this->mapping = array_merge($this->mapping, $mapping);
47 1
    }
48
49
    /**
50
     * @param $nameOrId
51
     *
52
     * @return string|int
53
     */
54 4
    public function find($nameOrId)
55
    {
56 4
        if (is_string($nameOrId)) {
57 4
            return $this->findByName($nameOrId);
58
        }
59
60
        if (is_int($nameOrId)) {
61
            return $this->findById($nameOrId);
62
        }
63
    }
64
65
    /**
66
     * @param $name
67
     *
68
     * @return int
69
     */
70 4
    public function findByName($name)
71
    {
72 4
        if (array_key_exists($name, $this->systemFields)) {
73 2
            return $this->systemFields[$name];
74
        }
75
76 2
        if (array_key_exists($name, $this->mapping)) {
77 1
            return $this->mapping[$name];
78
        }
79
80 1
        throw new NotFoundFieldException($name);
81
    }
82
83
    /**
84
     * @param int $id
85
     *
86
     * @return string
87
     */
88
    public function findById($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
89
    {
90
    }
91
}
92