SegmentCollection::offsetGet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 4
loc 4
rs 10
c 0
b 0
f 0
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