Completed
Push — master ( 22e19d...e5f34e )
by Claude
07:09
created

Events::addMapping()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * A php library for using the Emarsys API.
5
 *
6
 * @link      https://github.com/ck-developer/emarsys-php-client
7
 * @package   authy
8
 * @license   MIT
9
 * @copyright Copyright (c) 2017 Claude Khedhiri <[email protected]>
10
 */
11
12
namespace Emarsys\Mapping;
13
14
use Emarsys\Exception\Mapping\NotFoundFieldException;
15
16 View Code Duplication
class Events
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...
17
{
18
    private $mapping = array();
19
20
    private $systemFields = array();
21
22
    /**
23
     * @param array $mapping
24
     */
25
    public function addMapping(array $mapping)
26
    {
27
        $this->mapping = array_merge($this->mapping, $mapping);
28
    }
29
30
    /**
31
     * @param $nameOrId
32
     *
33
     * @return string|int
34
     */
35
    public function find($nameOrId)
36
    {
37
        if (is_string($nameOrId)) {
38
            return $this->findByName($nameOrId);
39
        }
40
41
        if (is_int($nameOrId)) {
42
            return $this->findById($nameOrId);
43
        }
44
    }
45
46
    public function findByName($name)
47
    {
48
        if (array_key_exists($name, $this->systemFields)) {
49
            return $this->systemFields[$name];
50
        }
51
52
        if (array_key_exists($name, $this->mapping)) {
53
            return $this->mapping[$name];
54
        }
55
56
        throw new NotFoundFieldException($name);
57
    }
58
59
    /**
60
     * @param int $id
61
     *
62
     * @return string
63
     */
64
    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...
65
    {
66
    }
67
}
68