ContactListCollection::add()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace Mailxpert\Model;
4
5
/**
6
 * Date: 19/08/15
7
 */
8 View Code Duplication
class ContactListCollection 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...
9
{
10
    /**
11
     * @param mixed $offset
12
     *
13
     * @return ContactList|null
14
     */
15
    public function offsetGet($offset)
16
    {
17
        return parent::offsetGet($offset);
18
    }
19
20
    /**
21
     * @param ContactList $contactList
22
     *
23
     * @return void
24
     */
25
    public function add($contactList)
26
    {
27
        if (!$this->exists(
28
            function ($key, ContactList $element) use ($contactList) {
29
                return $contactList->getId() == $element->getId();
30
            }
31
        )
32
        ) {
33
            parent::add($contactList);
34
        }
35
    }
36
37
    /**
38
     * @param string $name
39
     *
40
     * @return self
41
     */
42
    public function findByName($name)
43
    {
44
        return $this->filter(
45
            function (ContactList $element) use ($name) {
46
                return $element->getName() == $name;
47
            }
48
        );
49
    }
50
51
    /**
52
     * @param string $name
53
     *
54
     * @return mixed
55
     */
56
    public function findOneByName($name)
57
    {
58
        $elements = $this->findByName($name);
59
60
        return $elements->first();
61
    }
62
}
63