IndexItem   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 171
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 171
ccs 45
cts 45
cp 1
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A setObjectType() 0 4 1
A getObjectType() 0 4 1
A setOtherId() 0 6 1
A getOtherId() 0 4 1
A setField() 0 6 1
A getField() 0 4 1
A setValue() 0 6 1
A getValue() 0 4 1
B createMultipleObjectsBasedOnProperties() 0 26 5
1
<?php
2
3
namespace SumoCoders\FrameworkSearchBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
7
/**
8
 * IndexItem
9
 *
10
 * @ORM\Table()
11
 * @ORM\Entity(repositoryClass="SumoCoders\FrameworkSearchBundle\Entity\IndexItemRepository")
12
 */
13
class IndexItem
14
{
15
    /**
16
     * @var string
17
     *
18
     * @ORM\Id
19
     * @ORM\Column(name="objectType", type="string", length=255)
20
     */
21
    protected $objectType;
22
23
    /**
24
     * @var string
25
     *
26
     * @ORM\Id
27
     * @ORM\Column(name="otherId", type="string", length=255)
28
     */
29
    protected $otherId;
30
31
    /**
32
     * @var string
33
     *
34
     * @ORM\Id
35
     * @ORM\Column(name="field", type="string", length=255)
36
     */
37
    protected $field;
38
39
    /**
40
     * @var string
41
     *
42
     * @ORM\Column(name="value", type="text")
43
     */
44
    protected $value;
45
46
    /**
47
     * @param string $objectType
48
     * @param mixed  $otherId
49
     * @param string $field
50
     * @param string $value
51
     */
52 4
    public function __construct($objectType, $otherId, $field, $value)
53
    {
54 4
        $this->setObjectType($objectType);
55 4
        $this->setOtherId($otherId);
56 4
        $this->setField($field);
57 4
        $this->setValue($value);
58 4
    }
59
60
    /**
61
     * @param mixed $objectType
62
     */
63 4
    public function setObjectType($objectType)
64
    {
65 4
        $this->objectType = $objectType;
66 4
    }
67
68
    /**
69
     * @return mixed
70
     */
71 1
    public function getObjectType()
72
    {
73 1
        return $this->objectType;
74
    }
75
76
    /**
77
     * Set otherId
78
     *
79
     * @param mixed $otherId
80
     *
81
     * @return IndexItem
82
     */
83 4
    public function setOtherId($otherId)
84
    {
85 4
        $this->otherId = (string) $otherId;
86
87 4
        return $this;
88
    }
89
90
    /**
91
     * Get otherId
92
     *
93
     * @return string
94
     */
95 1
    public function getOtherId()
96
    {
97 1
        return $this->otherId;
98
    }
99
100
    /**
101
     * Set field
102
     *
103
     * @param string $field
104
     *
105
     * @return IndexItem
106
     */
107 4
    public function setField($field)
108
    {
109 4
        $this->field = $field;
110
111 4
        return $this;
112
    }
113
114
    /**
115
     * Get field
116
     *
117
     * @return string
118
     */
119 3
    public function getField()
120
    {
121 3
        return $this->field;
122
    }
123
124
    /**
125
     * Set value
126
     *
127
     * @param string $value
128
     *
129
     * @return IndexItem
130
     */
131 4
    public function setValue($value)
132
    {
133 4
        $this->value = $value;
134
135 4
        return $this;
136
    }
137
138
    /**
139
     * Get value
140
     *
141
     * @return string
142
     */
143 3
    public function getValue()
144
    {
145 3
        return $this->value;
146
    }
147
148
    /**
149
     * Create an array of search index items based on the object
150
     *
151
     * @param string $class
152
     * @param string $id
153
     * @param array  $properties
154
     * @param mixed  $object
155
     * @return array
156
     */
157 2
    public static function createMultipleObjectsBasedOnProperties($class, $id, array $properties, $object)
158
    {
159 2
        $indexItems = array();
160
161 2
        foreach ($properties as $property) {
162 2
            $value = null;
163 2
            $method = array($object, 'get' . ucfirst($property));
164
165 2
            if (is_callable($method)) {
166 1
                $value = call_user_func($method);
167 2
            } elseif (isset($object->$property)) {
168 1
                $value = $object->$property;
169 1
            }
170
171 2
            if ($value !== null) {
172 2
                $indexItems[] = new IndexItem(
173 2
                    $class,
174 2
                    $id,
175 2
                    $property,
176
                    $value
177 2
                );
178 2
            }
179 2
        }
180
181 2
        return $indexItems;
182
    }
183
}
184