SlugEvent   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 12.82 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 5
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 11 4
A getEntity() 0 4 1
A getProperty() 0 4 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 Alpixel\Bundle\CMSBundle\Event;
4
5
use Symfony\Component\EventDispatcher\Event;
6
7
/**
8
 * @author Alexis BUSSIERES <[email protected]>
9
 *
10
 * The SlugEvent class is used for an entity which have a slug
11
 * shared between different entities.
12
 */
13
class SlugEvent extends Event
14
{
15
    private $entity;
16
    private $property;
17
18
    /**
19
     * SlugEvent constructor.
20
     *
21
     * @param $entity object
22
     * @param $property string
23
     */
24
    public function __construct($entity, $property)
25
    {
26 View Code Duplication
        if (!is_object($entity)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
27
            throw new \InvalidArgumentException('The "$entity" parameter must be an object.');
28
        } elseif (!empty($property) && is_string($property)) {
29
            throw new \InvalidArgumentException('The "$property" parameter must be a non empty string.');
30
        }
31
32
        $this->entity = $entity;
33
        $this->property = $property;
34
    }
35
36
    /**
37
     * @return object
38
     */
39
    public function getEntity()
40
    {
41
        return $this->entity;
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getProperty()
48
    {
49
        return $this->property;
50
    }
51
}
52