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

Applications   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 addApplication() 6 6 1
A removeApplication() 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 Applications.
18
 */
19 View Code Duplication
class Applications extends ArrayCollection implements FromArrayInterface
20
{
21
    /**
22
     * @param Application $application
23
     *
24
     * @return $this
25
     */
26
    public function addApplication(Application $application)
27
    {
28
        $this->add($application);
29
30
        return $this;
31
    }
32
33
    /**
34
     * @param Application $application
35
     */
36
    public function removeApplication(Application $application)
37
    {
38
        $this->removeElement($application);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public static function fromArray(array $data)
45
    {
46
        $applications = [];
47
48
        foreach ($data as $datum) {
49
            $applications[] = Application::fromArray($datum);
50
        }
51
52
        return new static($applications);
53
    }
54
}
55