Completed
Push — master ( e81e8a...e81e8a )
by Claude
01:05
created

Events   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 52
loc 52
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
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 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