Completed
Push — master ( 2850eb...7f616c )
by Chauncey
10:27
created

CategorizableMultipleTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 69
loc 69
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setCategoryType() 12 12 2
A setCategories() 6 6 1
A getCategoryType() 4 4 1
A getCategories() 4 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 Charcoal\Object;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Defines objects that can be associated to one or more categories.
9
 *
10
 * Basic implementation of {@see \Charcoal\Object\CategorizableMultipleInterface}.
11
 *
12
 * @see \Charcoal\Object\CategoryInterface Accepted interface.
13
 */
14 View Code Duplication
trait CategorizableMultipleTrait
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...
15
{
16
    /**
17
     * The type of category the object can belong to.
18
     *
19
     * @var string
20
     */
21
    private $categoryType;
22
23
    /**
24
     * One or more categories the object belongs to.
25
     *
26
     * @var (mixed|CategoryInterface)[]|Traversable
27
     */
28
    protected $categories;
29
30
    /**
31
     * Set the type of category the object can belong to.
32
     *
33
     * @param string $type The category type.
34
     * @throws InvalidArgumentException If the type argument is not a string.
35
     * @return CategorizableMultipleInterface Chainable
36
     */
37
    public function setCategoryType($type)
38
    {
39
        if (!is_string($type)) {
40
            throw new InvalidArgumentException(
41
                'Category type must be a string.'
42
            );
43
        }
44
45
        $this->categoryType = $type;
46
47
        return $this;
48
    }
49
50
    /**
51
     * Retrieve the type of category the object can belong to.
52
     *
53
     * @return string
54
     */
55
    public function getCategoryType()
56
    {
57
        return $this->categoryType;
58
    }
59
60
    /**
61
     * Set the categories the object belongs to.
62
     *
63
     * @param array|Traversable $categories The object's categories.
64
     * @return CategorizableMultipleInterface Chainable
65
     */
66
    public function setCategories($categories)
67
    {
68
        $this->categories = $categories;
69
70
        return $this;
71
    }
72
73
    /**
74
     * Retrieve the categories the object belongs to.
75
     *
76
     * @return array|Traversable
77
     */
78
    public function getCategories()
79
    {
80
        return $this->categories;
81
    }
82
}
83