SegmentCollection   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 43
loc 43
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetGet() 4 4 1
A add() 11 11 2
A findById() 8 8 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
namespace Mailxpert\Model;
4
5
/**
6
 * Class SegmentCollection
7
 * @package Mailxpert\Model
8
 */
9 View Code Duplication
class SegmentCollection extends ArrayCollection
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...
10
{
11
    /**
12
     * @param mixed $offset
13
     *
14
     * @return Segment|null
15
     */
16
    public function offsetGet($offset)
17
    {
18
        return parent::offsetGet($offset);
19
    }
20
21
    /**
22
     * @param Segment $segment
23
     *
24
     * @return void
25
     */
26
    public function add($segment)
27
    {
28
        if (!$this->exists(
29
            function ($key, Segment $element) use ($segment) {
30
                return $segment->getId() == $element->getId();
31
            }
32
        )
33
        ) {
34
            parent::add($segment);
35
        }
36
    }
37
38
    /**
39
     * @param integer $id
40
     *
41
     * @return Segment|null
42
     */
43
    public function findById($id)
44
    {
45
        $contacts = $this->filter(function (Segment $element) use ($id) {
46
            return $element->getId() == $id;
47
        });
48
49
        return $contacts->first();
50
    }
51
}
52