Fields::find()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 4.125

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 3
cts 6
cp 0.5
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
crap 4.125
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