Completed
Pull Request — master (#3)
by Aymen
02:02
created

Events   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 36
loc 36
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addEvent() 6 6 1
A removeEvent() 4 4 1
A fromArray() 10 10 2

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
 * This file is part of the fnayou/instapush-php project.
4
 *
5
 * Copyright (c) 2017. Aymen FNAYOU <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Fnayou\InstapushPHP\Model;
12
13
use Doctrine\Common\Collections\ArrayCollection;
14
use Fnayou\InstapushPHP\Model\FromArrayInterface;
15
16
/**
17
 * Model Events.
18
 */
19 View Code Duplication
class Events extends ArrayCollection implements FromArrayInterface
20
{
21
    /**
22
     * @param Event $event
23
     *
24
     * @return $this
25
     */
26
    public function addEvent(Event $event)
27
    {
28
        $this->add($event);
29
30
        return $this;
31
    }
32
33
    /**
34
     * @param Event $event
35
     */
36
    public function removeEvent(Event $event)
37
    {
38
        $this->removeElement($event);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public static function fromArray(array $data)
45
    {
46
        $events = [];
47
48
        foreach ($data as $datum) {
49
            $events[] = Event::fromArray($datum);
50
        }
51
52
        return new static($events);
53
    }
54
}
55