Completed
Branch 5.3-dev (e55dab)
by Rémi
10:37
created
oldtests/AnalogueTest/App/Image.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -6,6 +6,9 @@
 block discarded – undo
6 6
 
7 7
 class Image extends Entity
8 8
 {
9
+    /**
10
+     * @param string $path
11
+     */
9 12
     public function __construct($path)
10 13
     {
11 14
         $this->path = $path;
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@
 block discarded – undo
6 6
 
7 7
 class Image extends Entity
8 8
 {
9
-    public function __construct($path)
10
-    {
11
-        $this->path = $path;
12
-    }
9
+	public function __construct($path)
10
+	{
11
+		$this->path = $path;
12
+	}
13 13
 
14
-    public function setPath($path)
15
-    {
16
-        $this->path = $path;
17
-    }
14
+	public function setPath($path)
15
+	{
16
+		$this->path = $path;
17
+	}
18 18
 }
Please login to merge, or discard this patch.
oldtests/AnalogueTest/App/Resource.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -8,6 +8,9 @@
 block discarded – undo
8 8
 {
9 9
     protected $hidden = ['name', 'v_field_1'];
10 10
 
11
+    /**
12
+     * @param string $name
13
+     */
11 14
     public function __construct($name, V $value = null)
12 15
     {
13 16
         $this->name = $name;
Please login to merge, or discard this patch.
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -6,26 +6,26 @@
 block discarded – undo
6 6
 
7 7
 class Resource extends Entity
8 8
 {
9
-    protected $hidden = ['name', 'v_field_1'];
9
+	protected $hidden = ['name', 'v_field_1'];
10 10
 
11
-    public function __construct($name, V $value = null)
12
-    {
13
-        $this->name = $name;
14
-        // Instantiate value map
15
-        if (! $value) {
16
-            $this->value = new V('a', 'b');
17
-        } else {
18
-            $this->value = $value;
19
-        }
20
-    }
11
+	public function __construct($name, V $value = null)
12
+	{
13
+		$this->name = $name;
14
+		// Instantiate value map
15
+		if (! $value) {
16
+			$this->value = new V('a', 'b');
17
+		} else {
18
+			$this->value = $value;
19
+		}
20
+	}
21 21
 
22
-    public function setStringAttribute($value)
23
-    {
24
-        $this->attributes['string'] = $value.'_mutated';
25
-    }
22
+	public function setStringAttribute($value)
23
+	{
24
+		$this->attributes['string'] = $value.'_mutated';
25
+	}
26 26
 
27
-    public function getStringAttribute($value)
28
-    {
29
-        return 'mutated_'.$value;
30
-    }
27
+	public function getStringAttribute($value)
28
+	{
29
+		return 'mutated_'.$value;
30
+	}
31 31
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
     {
13 13
         $this->name = $name;
14 14
         // Instantiate value map
15
-        if (! $value) {
15
+        if (!$value) {
16 16
             $this->value = new V('a', 'b');
17 17
         } else {
18 18
             $this->value = $value;
Please login to merge, or discard this patch.
oldtests/AnalogueTest/App/Role.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -7,6 +7,9 @@
 block discarded – undo
7 7
 
8 8
 class Role extends Entity
9 9
 {
10
+    /**
11
+     * @param string $label
12
+     */
10 13
     public function __construct($label)
11 14
     {
12 15
         $this->label = $label;
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -7,9 +7,9 @@
 block discarded – undo
7 7
 
8 8
 class Role extends Entity
9 9
 {
10
-    public function __construct($label)
11
-    {
12
-        $this->label = $label;
13
-        $this->permissions = new EntityCollection;
14
-    }
10
+	public function __construct($label)
11
+	{
12
+		$this->label = $label;
13
+		$this->permissions = new EntityCollection;
14
+	}
15 15
 }
Please login to merge, or discard this patch.
oldtests/AnalogueTest/App/User.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -6,6 +6,9 @@
 block discarded – undo
6 6
 
7 7
 class User extends Entity
8 8
 {
9
+    /**
10
+     * @param string $email
11
+     */
9 12
     public function __construct($email, Role $role)
10 13
     {
11 14
         $this->email = $email;
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -6,10 +6,10 @@
 block discarded – undo
6 6
 
7 7
 class User extends Entity
8 8
 {
9
-    public function __construct($email, Role $role)
10
-    {
11
-        $this->email = $email;
12
-        $this->role = $role;
13
-        $this->metas = new Meta;
14
-    }
9
+	public function __construct($email, Role $role)
10
+	{
11
+		$this->email = $email;
12
+		$this->role = $role;
13
+		$this->metas = new Meta;
14
+	}
15 15
 }
Please login to merge, or discard this patch.
oldtests/AnalogueTest/App/Uuid.php 2 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -6,6 +6,10 @@
 block discarded – undo
6 6
 
7 7
 class Uuid extends Entity
8 8
 {
9
+    /**
10
+     * @param string $uuid
11
+     * @param string $label
12
+     */
9 13
     public function __construct($uuid, $label)
10 14
     {
11 15
         $this->uuid = $uuid;
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -6,9 +6,9 @@
 block discarded – undo
6 6
 
7 7
 class Uuid extends Entity
8 8
 {
9
-    public function __construct($uuid, $label)
10
-    {
11
-        $this->uuid = $uuid;
12
-        $this->label = $label;
13
-    }
9
+	public function __construct($uuid, $label)
10
+	{
11
+		$this->uuid = $uuid;
12
+		$this->label = $label;
13
+	}
14 14
 }
Please login to merge, or discard this patch.
oldtests/AnalogueTest/App/V.php 2 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -6,6 +6,10 @@
 block discarded – undo
6 6
 
7 7
 class V extends ValueObject
8 8
 {
9
+    /**
10
+     * @param string $a
11
+     * @param string $b
12
+     */
9 13
     public function __construct($a, $b)
10 14
     {
11 15
         $this->field_1 = $a;
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -6,9 +6,9 @@
 block discarded – undo
6 6
 
7 7
 class V extends ValueObject
8 8
 {
9
-    public function __construct($a, $b)
10
-    {
11
-        $this->field_1 = $a;
12
-        $this->field_2 = $b;
13
-    }
9
+	public function __construct($a, $b)
10
+	{
11
+		$this->field_1 = $a;
12
+		$this->field_2 = $b;
13
+	}
14 14
 }
Please login to merge, or discard this patch.
src/EntityCollection.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      * Find an entity in the collection by key.
33 33
      *
34 34
      * @param  mixed $key
35
-     * @param  mixed $default
35
+     * @param  string $default
36 36
      * @throws MappingException
37 37
      * @return \Analogue\ORM\Entity
38 38
      */
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
     /**
79 79
      * Push an item onto the end of the collection.
80 80
      *
81
-     * @param  mixed $value
81
+     * @param  Mappable $value
82 82
      * @return void
83 83
      */
84 84
     public function push($value)
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
     /**
118 118
      * Determine if a key exists in the collection.
119 119
      *
120
-     * @param  mixed      $key
120
+     * @param  Entity      $key
121 121
      * @param  mixed|null $value
122 122
      * @return bool
123 123
      */
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
     /**
195 195
      * Merge the collection with the given items.
196 196
      *
197
-     * @param  array $items
197
+     * @param  EntityCollection $items
198 198
      * @throws MappingException
199 199
      * @return self
200 200
      */
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
     /**
213 213
      * Diff the collection with the given items.
214 214
      *
215
-     * @param  \ArrayAccess|array $items
215
+     * @param  EntityCollection $items
216 216
      * @return self
217 217
      */
218 218
     public function diff($items)
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
     /**
234 234
      * Intersect the collection with the given items.
235 235
      *
236
-     * @param  \ArrayAccess|array $items
236
+     * @param  EntityCollection $items
237 237
      * @throws MappingException
238 238
      * @return self
239 239
      */
Please login to merge, or discard this patch.
Indentation   +393 added lines, -393 removed lines patch added patch discarded remove patch
@@ -10,397 +10,397 @@
 block discarded – undo
10 10
 
11 11
 class EntityCollection extends Collection
12 12
 {
13
-    /**
14
-     * Wrapper Factory
15
-     *
16
-     * @var \Analogue\ORM\System\Wrappers\Factory
17
-     */
18
-    protected $factory;
19
-
20
-    /**
21
-     * EntityCollection constructor.
22
-     * @param array|null $entities
23
-     */
24
-    public function __construct(array $entities = null)
25
-    {
26
-        $this->factory = new Factory;
27
-
28
-        parent::__construct($entities);
29
-    }
30
-
31
-    /**
32
-     * Find an entity in the collection by key.
33
-     *
34
-     * @param  mixed $key
35
-     * @param  mixed $default
36
-     * @throws MappingException
37
-     * @return \Analogue\ORM\Entity
38
-     */
39
-    public function find($key, $default = null)
40
-    {
41
-        if ($key instanceof Mappable) {
42
-            $key = $this->getEntityKey($key);
43
-        }
44
-
45
-        return array_first($this->items, function ($entity, $itemKey) use ($key) {
46
-
47
-            return $this->getEntityKey($entity) == $key;
48
-        }, $default);
49
-    }
50
-
51
-    /**
52
-     * Add an entity to the collection.
53
-     *
54
-     * @param  Mappable $entity
55
-     * @return $this
56
-     */
57
-    public function add($entity)
58
-    {
59
-        $this->push($entity);
60
-
61
-        return $this;
62
-    }
63
-
64
-    /**
65
-     * Remove an entity from the collection
66
-     *
67
-     * @param $entity
68
-     * @throws MappingException
69
-     * @return mixed
70
-     */
71
-    public function remove($entity)
72
-    {
73
-        $key = $this->getEntityKey($entity);
74
-
75
-        return $this->pull($key);
76
-    }
77
-
78
-    /**
79
-     * Push an item onto the end of the collection.
80
-     *
81
-     * @param  mixed $value
82
-     * @return void
83
-     */
84
-    public function push($value)
85
-    {
86
-        $this->offsetSet(null, $value);
87
-    }
88
-
89
-    /**
90
-     * Put an item in the collection by key.
91
-     *
92
-     * @param  mixed $key
93
-     * @param  mixed $value
94
-     * @return void
95
-     */
96
-    public function put($key, $value)
97
-    {
98
-        $this->offsetSet($key, $value);
99
-    }
100
-
101
-    /**
102
-     * Set the item at a given offset.
103
-     *
104
-     * @param  mixed $key
105
-     * @param  mixed $value
106
-     * @return void
107
-     */
108
-    public function offsetSet($key, $value)
109
-    {
110
-        if (is_null($key)) {
111
-            $this->items[] = $value;
112
-        } else {
113
-            $this->items[$key] = $value;
114
-        }
115
-    }
116
-
117
-    /**
118
-     * Determine if a key exists in the collection.
119
-     *
120
-     * @param  mixed      $key
121
-     * @param  mixed|null $value
122
-     * @return bool
123
-     */
124
-    public function contains($key, $value = null)
125
-    {
126
-        if (func_num_args() == 2) {
127
-            return !$this->where($key, $value)->isEmpty();
128
-        }
129
-
130
-        if ($this->useAsCallable($key)) {
131
-            return !is_null($this->first($key));
132
-        }
133
-
134
-        return !is_null($this->find($key));
135
-    }
136
-
137
-    /**
138
-     * Fetch a nested element of the collection.
139
-     *
140
-     * @param  string $key
141
-     * @return self
142
-     */
143
-    public function fetch($key)
144
-    {
145
-        return new static(array_fetch($this->toArray(), $key));
146
-    }
147
-
148
-    /**
149
-     * Generic function for returning class.key value pairs
150
-     *
151
-     * @throws MappingException
152
-     * @return string
153
-     */
154
-    public function getEntityHashes()
155
-    {
156
-        return array_map(function ($entity) {
157
-            $class = get_class($entity);
158
-
159
-            $mapper = Manager::getMapper($class);
160
-
161
-            $keyName = $mapper->getEntityMap()->getKeyName();
162
-
163
-            return $class . '.' . $entity->getEntityAttribute($keyName);
164
-        },
165
-        $this->items);
166
-    }
167
-
168
-    /**
169
-     * Get a subset of the collection from entity hashes
170
-     *
171
-     * @param  array $hashes
172
-     * @throws MappingException
173
-     * @return array
174
-     */
175
-    public function getSubsetByHashes(array $hashes)
176
-    {
177
-        $subset = [];
178
-
179
-        foreach ($this->items as $item) {
180
-            $class = get_class($item);
181
-
182
-            $mapper = Manager::getMapper($class);
183
-
184
-            $keyName = $mapper->getEntityMap()->getKeyName();
185
-
186
-            if (in_array($class . '.' . $item->$keyName, $hashes)) {
187
-                $subset[] = $item;
188
-            }
189
-        }
190
-
191
-        return $subset;
192
-    }
193
-
194
-    /**
195
-     * Merge the collection with the given items.
196
-     *
197
-     * @param  array $items
198
-     * @throws MappingException
199
-     * @return self
200
-     */
201
-    public function merge($items)
202
-    {
203
-        $dictionary = $this->getDictionary();
204
-
205
-        foreach ($items as $item) {
206
-            $dictionary[$this->getEntityKey($item)] = $item;
207
-        }
208
-
209
-        return new static(array_values($dictionary));
210
-    }
211
-
212
-    /**
213
-     * Diff the collection with the given items.
214
-     *
215
-     * @param  \ArrayAccess|array $items
216
-     * @return self
217
-     */
218
-    public function diff($items)
219
-    {
220
-        $diff = new static;
221
-
222
-        $dictionary = $this->getDictionary($items);
223
-
224
-        foreach ($this->items as $item) {
225
-            if (!isset($dictionary[$this->getEntityKey($item)])) {
226
-                $diff->add($item);
227
-            }
228
-        }
229
-
230
-        return $diff;
231
-    }
232
-
233
-    /**
234
-     * Intersect the collection with the given items.
235
-     *
236
-     * @param  \ArrayAccess|array $items
237
-     * @throws MappingException
238
-     * @return self
239
-     */
240
-    public function intersect($items)
241
-    {
242
-        $intersect = new static;
243
-
244
-        $dictionary = $this->getDictionary($items);
245
-
246
-        foreach ($this->items as $item) {
247
-            if (isset($dictionary[$this->getEntityKey($item)])) {
248
-                $intersect->add($item);
249
-            }
250
-        }
251
-
252
-        return $intersect;
253
-    }
254
-
255
-    /**
256
-     * Returns only the models from the collection with the specified keys.
257
-     *
258
-     * @param  mixed $keys
259
-     * @return self
260
-     */
261
-    public function only($keys)
262
-    {
263
-        $dictionary = array_only($this->getDictionary(), $keys);
264
-
265
-        return new static(array_values($dictionary));
266
-    }
267
-
268
-    /**
269
-     * Returns all models in the collection except the models with specified keys.
270
-     *
271
-     * @param  mixed $keys
272
-     * @return self
273
-     */
274
-    public function except($keys)
275
-    {
276
-        $dictionary = array_except($this->getDictionary(), $keys);
277
-
278
-        return new static(array_values($dictionary));
279
-    }
280
-
281
-    /**
282
-     * Get a dictionary keyed by primary keys.
283
-     *
284
-     * @param  \ArrayAccess|array $items
285
-     * @throws MappingException
286
-     * @return array
287
-     */
288
-    public function getDictionary($items = null)
289
-    {
290
-        $items = is_null($items) ? $this->items : $items;
291
-
292
-        $dictionary = [];
293
-
294
-        foreach ($items as $value) {
295
-            $dictionary[$this->getEntityKey($value)] = $value;
296
-        }
297
-
298
-        return $dictionary;
299
-    }
300
-
301
-    /**
302
-     * @throws MappingException
303
-     * @return array
304
-     */
305
-    public function getEntityKeys()
306
-    {
307
-        return array_keys($this->getDictionary());
308
-    }
309
-
310
-    /**
311
-     * @param $entity
312
-     * @throws MappingException
313
-     * @return mixed
314
-     */
315
-    protected function getEntityKey($entity)
316
-    {
317
-        $keyName = Manager::getMapper($entity)->getEntityMap()->getKeyName();
318
-
319
-        $wrapper = $this->factory->make($entity);
320
-
321
-        return $wrapper->getEntityAttribute($keyName);
322
-    }
323
-
324
-    /**
325
-     * Get the max value of a given key.
326
-     *
327
-     * @param  string|null $key
328
-     * @throws MappingException
329
-     * @return mixed
330
-     */
331
-    public function max($key = null)
332
-    {
333
-        return $this->reduce(function ($result, $item) use ($key) {
334
-            $wrapper = $this->factory->make($item);
335
-
336
-            return (is_null($result) || $wrapper->getEntityAttribute($key) > $result) ?
337
-                $wrapper->getEntityAttribute($key) : $result;
338
-        });
339
-    }
340
-
341
-    /**
342
-     * Get the min value of a given key.
343
-     *
344
-     * @param  string|null $key
345
-     * @throws MappingException
346
-     * @return mixed
347
-     */
348
-    public function min($key = null)
349
-    {
350
-        return $this->reduce(function ($result, $item) use ($key) {
351
-            $wrapper = $this->factory->make($item);
352
-
353
-            return (is_null($result) || $wrapper->getEntityAttribute($key) < $result)
354
-                ? $wrapper->getEntityAttribute($key) : $result;
355
-        });
356
-    }
357
-
358
-    /**
359
-     * Get an array with the values of a given key.
360
-     *
361
-     * @param  string $value
362
-     * @param  string|null $key
363
-     * @return self
364
-     */
365
-    public function pluck($value, $key = null)
366
-    {
367
-        return new Collection(Arr::pluck($this->items, $value, $key));
368
-    }
369
-
370
-    /**
371
-     * Alias for the "pluck" method.
372
-     *
373
-     * @param  string $value
374
-     * @param  string|null $key
375
-     * @return self
376
-     */
377
-    public function lists($value, $key = null)
378
-    {
379
-        return $this->pluck($value, $key);
380
-    }
381
-
382
-    /**
383
-     * Return only unique items from the collection.
384
-     *
385
-     * @param  string|null $key
386
-     * @param  bool $strict
387
-     * @throws MappingException
388
-     * @return self
389
-     */
390
-    public function unique($key = null, $strict = false)
391
-    {
392
-        $dictionary = $this->getDictionary();
393
-
394
-        return new static(array_values($dictionary));
395
-    }
396
-
397
-    /**
398
-     * Get a base Support collection instance from this collection.
399
-     *
400
-     * @return \Illuminate\Support\Collection
401
-     */
402
-    public function toBase()
403
-    {
404
-        return new Collection($this->items);
405
-    }
13
+	/**
14
+	 * Wrapper Factory
15
+	 *
16
+	 * @var \Analogue\ORM\System\Wrappers\Factory
17
+	 */
18
+	protected $factory;
19
+
20
+	/**
21
+	 * EntityCollection constructor.
22
+	 * @param array|null $entities
23
+	 */
24
+	public function __construct(array $entities = null)
25
+	{
26
+		$this->factory = new Factory;
27
+
28
+		parent::__construct($entities);
29
+	}
30
+
31
+	/**
32
+	 * Find an entity in the collection by key.
33
+	 *
34
+	 * @param  mixed $key
35
+	 * @param  mixed $default
36
+	 * @throws MappingException
37
+	 * @return \Analogue\ORM\Entity
38
+	 */
39
+	public function find($key, $default = null)
40
+	{
41
+		if ($key instanceof Mappable) {
42
+			$key = $this->getEntityKey($key);
43
+		}
44
+
45
+		return array_first($this->items, function ($entity, $itemKey) use ($key) {
46
+
47
+			return $this->getEntityKey($entity) == $key;
48
+		}, $default);
49
+	}
50
+
51
+	/**
52
+	 * Add an entity to the collection.
53
+	 *
54
+	 * @param  Mappable $entity
55
+	 * @return $this
56
+	 */
57
+	public function add($entity)
58
+	{
59
+		$this->push($entity);
60
+
61
+		return $this;
62
+	}
63
+
64
+	/**
65
+	 * Remove an entity from the collection
66
+	 *
67
+	 * @param $entity
68
+	 * @throws MappingException
69
+	 * @return mixed
70
+	 */
71
+	public function remove($entity)
72
+	{
73
+		$key = $this->getEntityKey($entity);
74
+
75
+		return $this->pull($key);
76
+	}
77
+
78
+	/**
79
+	 * Push an item onto the end of the collection.
80
+	 *
81
+	 * @param  mixed $value
82
+	 * @return void
83
+	 */
84
+	public function push($value)
85
+	{
86
+		$this->offsetSet(null, $value);
87
+	}
88
+
89
+	/**
90
+	 * Put an item in the collection by key.
91
+	 *
92
+	 * @param  mixed $key
93
+	 * @param  mixed $value
94
+	 * @return void
95
+	 */
96
+	public function put($key, $value)
97
+	{
98
+		$this->offsetSet($key, $value);
99
+	}
100
+
101
+	/**
102
+	 * Set the item at a given offset.
103
+	 *
104
+	 * @param  mixed $key
105
+	 * @param  mixed $value
106
+	 * @return void
107
+	 */
108
+	public function offsetSet($key, $value)
109
+	{
110
+		if (is_null($key)) {
111
+			$this->items[] = $value;
112
+		} else {
113
+			$this->items[$key] = $value;
114
+		}
115
+	}
116
+
117
+	/**
118
+	 * Determine if a key exists in the collection.
119
+	 *
120
+	 * @param  mixed      $key
121
+	 * @param  mixed|null $value
122
+	 * @return bool
123
+	 */
124
+	public function contains($key, $value = null)
125
+	{
126
+		if (func_num_args() == 2) {
127
+			return !$this->where($key, $value)->isEmpty();
128
+		}
129
+
130
+		if ($this->useAsCallable($key)) {
131
+			return !is_null($this->first($key));
132
+		}
133
+
134
+		return !is_null($this->find($key));
135
+	}
136
+
137
+	/**
138
+	 * Fetch a nested element of the collection.
139
+	 *
140
+	 * @param  string $key
141
+	 * @return self
142
+	 */
143
+	public function fetch($key)
144
+	{
145
+		return new static(array_fetch($this->toArray(), $key));
146
+	}
147
+
148
+	/**
149
+	 * Generic function for returning class.key value pairs
150
+	 *
151
+	 * @throws MappingException
152
+	 * @return string
153
+	 */
154
+	public function getEntityHashes()
155
+	{
156
+		return array_map(function ($entity) {
157
+			$class = get_class($entity);
158
+
159
+			$mapper = Manager::getMapper($class);
160
+
161
+			$keyName = $mapper->getEntityMap()->getKeyName();
162
+
163
+			return $class . '.' . $entity->getEntityAttribute($keyName);
164
+		},
165
+		$this->items);
166
+	}
167
+
168
+	/**
169
+	 * Get a subset of the collection from entity hashes
170
+	 *
171
+	 * @param  array $hashes
172
+	 * @throws MappingException
173
+	 * @return array
174
+	 */
175
+	public function getSubsetByHashes(array $hashes)
176
+	{
177
+		$subset = [];
178
+
179
+		foreach ($this->items as $item) {
180
+			$class = get_class($item);
181
+
182
+			$mapper = Manager::getMapper($class);
183
+
184
+			$keyName = $mapper->getEntityMap()->getKeyName();
185
+
186
+			if (in_array($class . '.' . $item->$keyName, $hashes)) {
187
+				$subset[] = $item;
188
+			}
189
+		}
190
+
191
+		return $subset;
192
+	}
193
+
194
+	/**
195
+	 * Merge the collection with the given items.
196
+	 *
197
+	 * @param  array $items
198
+	 * @throws MappingException
199
+	 * @return self
200
+	 */
201
+	public function merge($items)
202
+	{
203
+		$dictionary = $this->getDictionary();
204
+
205
+		foreach ($items as $item) {
206
+			$dictionary[$this->getEntityKey($item)] = $item;
207
+		}
208
+
209
+		return new static(array_values($dictionary));
210
+	}
211
+
212
+	/**
213
+	 * Diff the collection with the given items.
214
+	 *
215
+	 * @param  \ArrayAccess|array $items
216
+	 * @return self
217
+	 */
218
+	public function diff($items)
219
+	{
220
+		$diff = new static;
221
+
222
+		$dictionary = $this->getDictionary($items);
223
+
224
+		foreach ($this->items as $item) {
225
+			if (!isset($dictionary[$this->getEntityKey($item)])) {
226
+				$diff->add($item);
227
+			}
228
+		}
229
+
230
+		return $diff;
231
+	}
232
+
233
+	/**
234
+	 * Intersect the collection with the given items.
235
+	 *
236
+	 * @param  \ArrayAccess|array $items
237
+	 * @throws MappingException
238
+	 * @return self
239
+	 */
240
+	public function intersect($items)
241
+	{
242
+		$intersect = new static;
243
+
244
+		$dictionary = $this->getDictionary($items);
245
+
246
+		foreach ($this->items as $item) {
247
+			if (isset($dictionary[$this->getEntityKey($item)])) {
248
+				$intersect->add($item);
249
+			}
250
+		}
251
+
252
+		return $intersect;
253
+	}
254
+
255
+	/**
256
+	 * Returns only the models from the collection with the specified keys.
257
+	 *
258
+	 * @param  mixed $keys
259
+	 * @return self
260
+	 */
261
+	public function only($keys)
262
+	{
263
+		$dictionary = array_only($this->getDictionary(), $keys);
264
+
265
+		return new static(array_values($dictionary));
266
+	}
267
+
268
+	/**
269
+	 * Returns all models in the collection except the models with specified keys.
270
+	 *
271
+	 * @param  mixed $keys
272
+	 * @return self
273
+	 */
274
+	public function except($keys)
275
+	{
276
+		$dictionary = array_except($this->getDictionary(), $keys);
277
+
278
+		return new static(array_values($dictionary));
279
+	}
280
+
281
+	/**
282
+	 * Get a dictionary keyed by primary keys.
283
+	 *
284
+	 * @param  \ArrayAccess|array $items
285
+	 * @throws MappingException
286
+	 * @return array
287
+	 */
288
+	public function getDictionary($items = null)
289
+	{
290
+		$items = is_null($items) ? $this->items : $items;
291
+
292
+		$dictionary = [];
293
+
294
+		foreach ($items as $value) {
295
+			$dictionary[$this->getEntityKey($value)] = $value;
296
+		}
297
+
298
+		return $dictionary;
299
+	}
300
+
301
+	/**
302
+	 * @throws MappingException
303
+	 * @return array
304
+	 */
305
+	public function getEntityKeys()
306
+	{
307
+		return array_keys($this->getDictionary());
308
+	}
309
+
310
+	/**
311
+	 * @param $entity
312
+	 * @throws MappingException
313
+	 * @return mixed
314
+	 */
315
+	protected function getEntityKey($entity)
316
+	{
317
+		$keyName = Manager::getMapper($entity)->getEntityMap()->getKeyName();
318
+
319
+		$wrapper = $this->factory->make($entity);
320
+
321
+		return $wrapper->getEntityAttribute($keyName);
322
+	}
323
+
324
+	/**
325
+	 * Get the max value of a given key.
326
+	 *
327
+	 * @param  string|null $key
328
+	 * @throws MappingException
329
+	 * @return mixed
330
+	 */
331
+	public function max($key = null)
332
+	{
333
+		return $this->reduce(function ($result, $item) use ($key) {
334
+			$wrapper = $this->factory->make($item);
335
+
336
+			return (is_null($result) || $wrapper->getEntityAttribute($key) > $result) ?
337
+				$wrapper->getEntityAttribute($key) : $result;
338
+		});
339
+	}
340
+
341
+	/**
342
+	 * Get the min value of a given key.
343
+	 *
344
+	 * @param  string|null $key
345
+	 * @throws MappingException
346
+	 * @return mixed
347
+	 */
348
+	public function min($key = null)
349
+	{
350
+		return $this->reduce(function ($result, $item) use ($key) {
351
+			$wrapper = $this->factory->make($item);
352
+
353
+			return (is_null($result) || $wrapper->getEntityAttribute($key) < $result)
354
+				? $wrapper->getEntityAttribute($key) : $result;
355
+		});
356
+	}
357
+
358
+	/**
359
+	 * Get an array with the values of a given key.
360
+	 *
361
+	 * @param  string $value
362
+	 * @param  string|null $key
363
+	 * @return self
364
+	 */
365
+	public function pluck($value, $key = null)
366
+	{
367
+		return new Collection(Arr::pluck($this->items, $value, $key));
368
+	}
369
+
370
+	/**
371
+	 * Alias for the "pluck" method.
372
+	 *
373
+	 * @param  string $value
374
+	 * @param  string|null $key
375
+	 * @return self
376
+	 */
377
+	public function lists($value, $key = null)
378
+	{
379
+		return $this->pluck($value, $key);
380
+	}
381
+
382
+	/**
383
+	 * Return only unique items from the collection.
384
+	 *
385
+	 * @param  string|null $key
386
+	 * @param  bool $strict
387
+	 * @throws MappingException
388
+	 * @return self
389
+	 */
390
+	public function unique($key = null, $strict = false)
391
+	{
392
+		$dictionary = $this->getDictionary();
393
+
394
+		return new static(array_values($dictionary));
395
+	}
396
+
397
+	/**
398
+	 * Get a base Support collection instance from this collection.
399
+	 *
400
+	 * @return \Illuminate\Support\Collection
401
+	 */
402
+	public function toBase()
403
+	{
404
+		return new Collection($this->items);
405
+	}
406 406
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
             $key = $this->getEntityKey($key);
43 43
         }
44 44
 
45
-        return array_first($this->items, function ($entity, $itemKey) use ($key) {
45
+        return array_first($this->items, function($entity, $itemKey) use ($key) {
46 46
 
47 47
             return $this->getEntityKey($entity) == $key;
48 48
         }, $default);
@@ -153,14 +153,14 @@  discard block
 block discarded – undo
153 153
      */
154 154
     public function getEntityHashes()
155 155
     {
156
-        return array_map(function ($entity) {
156
+        return array_map(function($entity) {
157 157
             $class = get_class($entity);
158 158
 
159 159
             $mapper = Manager::getMapper($class);
160 160
 
161 161
             $keyName = $mapper->getEntityMap()->getKeyName();
162 162
 
163
-            return $class . '.' . $entity->getEntityAttribute($keyName);
163
+            return $class.'.'.$entity->getEntityAttribute($keyName);
164 164
         },
165 165
         $this->items);
166 166
     }
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 
184 184
             $keyName = $mapper->getEntityMap()->getKeyName();
185 185
 
186
-            if (in_array($class . '.' . $item->$keyName, $hashes)) {
186
+            if (in_array($class.'.'.$item->$keyName, $hashes)) {
187 187
                 $subset[] = $item;
188 188
             }
189 189
         }
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
      */
331 331
     public function max($key = null)
332 332
     {
333
-        return $this->reduce(function ($result, $item) use ($key) {
333
+        return $this->reduce(function($result, $item) use ($key) {
334 334
             $wrapper = $this->factory->make($item);
335 335
 
336 336
             return (is_null($result) || $wrapper->getEntityAttribute($key) > $result) ?
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
      */
348 348
     public function min($key = null)
349 349
     {
350
-        return $this->reduce(function ($result, $item) use ($key) {
350
+        return $this->reduce(function($result, $item) use ($key) {
351 351
             $wrapper = $this->factory->make($item);
352 352
 
353 353
             return (is_null($result) || $wrapper->getEntityAttribute($key) < $result)
Please login to merge, or discard this patch.
src/System/Manager.php 5 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      * Create a mapper for a given entity
142 142
      *
143 143
      * @param  \Analogue\ORM\Mappable|string|array|\Traversable $entity
144
-     * @param  mixed                                            $entityMap
144
+     * @param  null|EntityMap                                            $entityMap
145 145
      * @throws MappingException
146 146
      * @throws \InvalidArgumentException
147 147
      * @return Mapper
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
     /**
244 244
      * Check if the entity is already registered
245 245
      *
246
-     * @param  string|Entity $entity
246
+     * @param  string $entity
247 247
      * @return boolean
248 248
      */
249 249
     public function isRegisteredEntity($entity)
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
     /**
313 313
      * Register an entity
314 314
      *
315
-     * @param  string|\Analogue\ORM\Mappable $entity    entity's class name
315
+     * @param  string $entity    entity's class name
316 316
      * @param  string|EntityMap              $entityMap map's class name
317 317
      * @throws MappingException
318 318
      * @return void
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,6 @@
 block discarded – undo
5 5
 use Analogue\ORM\Entity;
6 6
 use Analogue\ORM\Plugins\AnaloguePluginInterface;
7 7
 use Analogue\ORM\ValueMap;
8
-use Exception;
9 8
 use Analogue\ORM\EntityMap;
10 9
 use Analogue\ORM\Repository;
11 10
 use Illuminate\Support\Collection;
Please login to merge, or discard this patch.
Indentation   +638 added lines, -638 removed lines patch added patch discarded remove patch
@@ -21,648 +21,648 @@
 block discarded – undo
21 21
  */
22 22
 class Manager
23 23
 {
24
-    /**
25
-     * Manager instance
26
-     *
27
-     * @var Manager
28
-     */
29
-    protected static $instance;
30
-
31
-    /**
32
-     * Driver Manager
33
-     *
34
-     * @var \Analogue\ORM\Drivers\Manager
35
-     */
36
-    protected $drivers;
37
-
38
-    /**
39
-     * Registered entity classes and corresponding map objects.
40
-     *
41
-     * @var array
42
-     */
43
-    protected $entityClasses = [];
44
-
45
-    /**
46
-     * Key value store of ValueObject Classes and corresponding map classes
47
-     *
48
-     * @var array|ValueMap[]
49
-     */
50
-    protected $valueClasses = [];
51
-
52
-    /**
53
-     * Morph map
54
-     */
55
-    protected $morphMap = [];
56
-
57
-    /**
58
-     * Loaded Mappers
59
-     *
60
-     * @var array
61
-     */
62
-    protected $mappers = [];
63
-
64
-    /**
65
-     * Loaded Repositories
66
-     *
67
-     * @var array
68
-     */
69
-    protected $repositories = [];
70
-
71
-    /**
72
-     * Event dispatcher instance
73
-     *
74
-     * @var \Illuminate\Contracts\Events\Dispatcher
75
-     */
76
-    protected $eventDispatcher;
77
-
78
-    /**
79
-     * Available Analogue Events
80
-     *
81
-     * @var array
82
-     */
83
-    protected $events = [
84
-        'initializing',
85
-        'initialized',
86
-        'store',
87
-        'stored',
88
-        'creating',
89
-        'created',
90
-        'updating',
91
-        'updated',
92
-        'deleting',
93
-        'deleted',
94
-    ];
95
-
96
-    /**
97
-     * If strictMode is set to true, Manager will throw
98
-     * an exception if no entityMap class are registered
99
-     * for a given entity class.
100
-     * 
101
-     * @var boolean
102
-     */
103
-    protected $strictMode = true;
104
-
105
-    /**
106
-     * We can add namespaces in this array where the manager
107
-     * will look for when auto registering entityMaps.
108
-     * 
109
-     * @var array
110
-     */
111
-    protected $customMapNamespaces = [];
112
-
113
-    /**
114
-     * @param \Analogue\ORM\Drivers\Manager $driverManager
115
-     * @param Dispatcher                    $event
116
-     */
117
-    public function __construct(DriverManager $driverManager, Dispatcher $event)
118
-    {
119
-        $this->drivers = $driverManager;
120
-
121
-        $this->eventDispatcher = $event;
122
-
123
-        static::$instance = $this;
124
-    }
125
-
126
-    /**
127
-     * Create a mapper for a given entity (static alias)
128
-     *
129
-     * @param  \Analogue\ORM\Mappable|string $entity
130
-     * @param  null|EntityMap                $entityMap
131
-     * @throws MappingException
132
-     * @return Mapper
133
-     * @throws \InvalidArgumentException
134
-     */
135
-    public static function getMapper($entity, $entityMap = null)
136
-    {
137
-        return static::$instance->mapper($entity, $entityMap);
138
-    }
139
-
140
-    /**
141
-     * Create a mapper for a given entity
142
-     *
143
-     * @param  \Analogue\ORM\Mappable|string|array|\Traversable $entity
144
-     * @param  mixed                                            $entityMap
145
-     * @throws MappingException
146
-     * @throws \InvalidArgumentException
147
-     * @return Mapper
148
-     */
149
-    public function mapper($entity, $entityMap = null)
150
-    {
151
-        if ($entity instanceof Wrapper) {
152
-            throw new MappingException('Tried to instantiate mapper on wrapped Entity');
153
-        }
154
-
155
-        $entity = $this->resolveEntityClass($entity);
156
-
157
-        $entity = $this->getInverseMorphMap($entity);
158
-
159
-        // Return existing mapper instance if exists.
160
-        if (array_key_exists($entity, $this->mappers)) {
161
-            return $this->mappers[$entity];
162
-        } else {
163
-            return $this->buildMapper($entity, $entityMap);
164
-        }
165
-    }
166
-
167
-    /**
168
-     * This method resolve entity class from mappable instances or iterators
169
-     *
170
-     * @param \Analogue\ORM\Mappable|string|array|\Traversable $entity
171
-     * @return string
172
-     *
173
-     * @throws \InvalidArgumentException
174
-     */
175
-    protected function resolveEntityClass($entity)
176
-    {
177
-        // We first check if the entity is traversable and we'll resolve
178
-        // the entity based on the first item of the object.   
179
-        if ($this->isTraversable($entity)) {
180
-            if (! count($entity)) {
181
-                throw new \InvalidArgumentException('Length of Entity collection must be greater than 0');
182
-            }
183
-
184
-            $firstEntityItem = ($entity instanceof \Iterator)
185
-                ? $entity->current()
186
-                : current($entity);
187
-
188
-            return $this->resolveEntityClass($firstEntityItem);
189
-        }
24
+	/**
25
+	 * Manager instance
26
+	 *
27
+	 * @var Manager
28
+	 */
29
+	protected static $instance;
30
+
31
+	/**
32
+	 * Driver Manager
33
+	 *
34
+	 * @var \Analogue\ORM\Drivers\Manager
35
+	 */
36
+	protected $drivers;
37
+
38
+	/**
39
+	 * Registered entity classes and corresponding map objects.
40
+	 *
41
+	 * @var array
42
+	 */
43
+	protected $entityClasses = [];
44
+
45
+	/**
46
+	 * Key value store of ValueObject Classes and corresponding map classes
47
+	 *
48
+	 * @var array|ValueMap[]
49
+	 */
50
+	protected $valueClasses = [];
51
+
52
+	/**
53
+	 * Morph map
54
+	 */
55
+	protected $morphMap = [];
56
+
57
+	/**
58
+	 * Loaded Mappers
59
+	 *
60
+	 * @var array
61
+	 */
62
+	protected $mappers = [];
63
+
64
+	/**
65
+	 * Loaded Repositories
66
+	 *
67
+	 * @var array
68
+	 */
69
+	protected $repositories = [];
70
+
71
+	/**
72
+	 * Event dispatcher instance
73
+	 *
74
+	 * @var \Illuminate\Contracts\Events\Dispatcher
75
+	 */
76
+	protected $eventDispatcher;
77
+
78
+	/**
79
+	 * Available Analogue Events
80
+	 *
81
+	 * @var array
82
+	 */
83
+	protected $events = [
84
+		'initializing',
85
+		'initialized',
86
+		'store',
87
+		'stored',
88
+		'creating',
89
+		'created',
90
+		'updating',
91
+		'updated',
92
+		'deleting',
93
+		'deleted',
94
+	];
95
+
96
+	/**
97
+	 * If strictMode is set to true, Manager will throw
98
+	 * an exception if no entityMap class are registered
99
+	 * for a given entity class.
100
+	 * 
101
+	 * @var boolean
102
+	 */
103
+	protected $strictMode = true;
104
+
105
+	/**
106
+	 * We can add namespaces in this array where the manager
107
+	 * will look for when auto registering entityMaps.
108
+	 * 
109
+	 * @var array
110
+	 */
111
+	protected $customMapNamespaces = [];
112
+
113
+	/**
114
+	 * @param \Analogue\ORM\Drivers\Manager $driverManager
115
+	 * @param Dispatcher                    $event
116
+	 */
117
+	public function __construct(DriverManager $driverManager, Dispatcher $event)
118
+	{
119
+		$this->drivers = $driverManager;
120
+
121
+		$this->eventDispatcher = $event;
122
+
123
+		static::$instance = $this;
124
+	}
125
+
126
+	/**
127
+	 * Create a mapper for a given entity (static alias)
128
+	 *
129
+	 * @param  \Analogue\ORM\Mappable|string $entity
130
+	 * @param  null|EntityMap                $entityMap
131
+	 * @throws MappingException
132
+	 * @return Mapper
133
+	 * @throws \InvalidArgumentException
134
+	 */
135
+	public static function getMapper($entity, $entityMap = null)
136
+	{
137
+		return static::$instance->mapper($entity, $entityMap);
138
+	}
139
+
140
+	/**
141
+	 * Create a mapper for a given entity
142
+	 *
143
+	 * @param  \Analogue\ORM\Mappable|string|array|\Traversable $entity
144
+	 * @param  mixed                                            $entityMap
145
+	 * @throws MappingException
146
+	 * @throws \InvalidArgumentException
147
+	 * @return Mapper
148
+	 */
149
+	public function mapper($entity, $entityMap = null)
150
+	{
151
+		if ($entity instanceof Wrapper) {
152
+			throw new MappingException('Tried to instantiate mapper on wrapped Entity');
153
+		}
154
+
155
+		$entity = $this->resolveEntityClass($entity);
156
+
157
+		$entity = $this->getInverseMorphMap($entity);
158
+
159
+		// Return existing mapper instance if exists.
160
+		if (array_key_exists($entity, $this->mappers)) {
161
+			return $this->mappers[$entity];
162
+		} else {
163
+			return $this->buildMapper($entity, $entityMap);
164
+		}
165
+	}
166
+
167
+	/**
168
+	 * This method resolve entity class from mappable instances or iterators
169
+	 *
170
+	 * @param \Analogue\ORM\Mappable|string|array|\Traversable $entity
171
+	 * @return string
172
+	 *
173
+	 * @throws \InvalidArgumentException
174
+	 */
175
+	protected function resolveEntityClass($entity)
176
+	{
177
+		// We first check if the entity is traversable and we'll resolve
178
+		// the entity based on the first item of the object.   
179
+		if ($this->isTraversable($entity)) {
180
+			if (! count($entity)) {
181
+				throw new \InvalidArgumentException('Length of Entity collection must be greater than 0');
182
+			}
183
+
184
+			$firstEntityItem = ($entity instanceof \Iterator)
185
+				? $entity->current()
186
+				: current($entity);
187
+
188
+			return $this->resolveEntityClass($firstEntityItem);
189
+		}
190 190
         
191
-        if (is_object($entity)) {
192
-            return get_class($entity);
193
-        }
191
+		if (is_object($entity)) {
192
+			return get_class($entity);
193
+		}
194 194
         
195
-        if (is_string($entity)) {
196
-            return $entity;
197
-        }
195
+		if (is_string($entity)) {
196
+			return $entity;
197
+		}
198 198
      
199
-        throw new \InvalidArgumentException('Invalid entity type');
200
-    }
201
-
202
-    /**
203
-     * @param string $key
204
-     * @return string
205
-     */
206
-    public function getInverseMorphMap($key)
207
-    {
208
-        return array_key_exists($key, $this->morphMap) ? $this->morphMap[$key] : $key;
209
-    }
210
-
211
-    /**
212
-     * Build a new Mapper instance for a given Entity
213
-     *
214
-     * @param  string $entity
215
-     * @param         $entityMap
216
-     * @throws MappingException
217
-     * @return Mapper
218
-     */
219
-    protected function buildMapper($entity, $entityMap)
220
-    {
221
-        // If an EntityMap hasn't been manually registered by the user
222
-        // register it at runtime.
223
-        if (!$this->isRegisteredEntity($entity)) {
224
-            $this->register($entity, $entityMap);
225
-        }
226
-
227
-        $entityMap = $this->entityClasses[$entity];
228
-
229
-        $factory = new MapperFactory($this->drivers, $this->eventDispatcher, $this);
230
-
231
-        $mapper = $factory->make($entity, $entityMap);
232
-
233
-        $this->mappers[$entity] = $mapper;
234
-
235
-        // At this point we can safely call the boot() method on the entityMap as
236
-        // the mapper is now instantiated & registered within the manager.
237
-
238
-        $mapper->getEntityMap()->boot();
239
-
240
-        return $mapper;
241
-    }
242
-
243
-    /**
244
-     * Check if the entity is already registered
245
-     *
246
-     * @param  string|Entity $entity
247
-     * @return boolean
248
-     */
249
-    public function isRegisteredEntity($entity)
250
-    {
251
-        if (!is_string($entity)) {
252
-            $entity = get_class($entity);
253
-        }
254
-
255
-        return array_key_exists($entity, $this->entityClasses);
256
-    }
257
-
258
-    /**
259
-     * Check if a value class is already registered
260
-     *
261
-     * @param string|sdtClass $object
262
-     * @return boolean
263
-     * 
264
-     */
265
-    public function isRegisteredValueObject($object)
266
-    {
267
-        if (!is_string($object)) {
268
-            $object = get_class($object);
269
-        }
270
-
271
-        return array_key_exists($object, $this->valueClasses);
272
-    }
273
-
274
-    /**
275
-     * Return true if an object is an array or iterator
276
-     *
277
-     * @param  mixed $argument
278
-     * @return boolean
279
-     */
280
-    public function isTraversable($argument)
281
-    {
282
-        return $argument instanceof \Traversable || is_array($argument);
283
-    }
284
-
285
-    /**
286
-     * Set strict mode for entityMap instantiation
287
-     * 
288
-     * @param boolean $mode
289
-     */
290
-    public function setStrictMode($mode)
291
-    {
292
-        $this->strictMode = $mode;
293
-    }
294
-
295
-    /**
296
-     * Register a namespace in where Analogue
297
-     * will scan for EntityMaps & ValueMaps
298
-     *
299
-     * @param string $namespace
300
-     * @return void
301
-     */
302
-    public function registerMapNamespace($namespace)
303
-    {
304
-        // Add a trailing antislash to namespace if not present
305
-        if (substr("testers", -1) != "\\") {
306
-            $namespace = $namespace."\\";
307
-        }
308
-
309
-        $this->customMapNamespaces[] = $namespace;
310
-    }
311
-
312
-    /**
313
-     * Register an entity
314
-     *
315
-     * @param  string|\Analogue\ORM\Mappable $entity    entity's class name
316
-     * @param  string|EntityMap              $entityMap map's class name
317
-     * @throws MappingException
318
-     * @return void
319
-     */
320
-    public function register($entity, $entityMap = null)
321
-    {
322
-        // If an object is provider, get the class name from it
323
-        if (!is_string($entity)) {
324
-            $entity = get_class($entity);
325
-        }
326
-
327
-        if ($this->isRegisteredEntity($entity)) {
328
-            throw new MappingException("Entity $entity is already registered.");
329
-        }
330
-
331
-        if (!class_exists($entity)) {
332
-            throw new MappingException("Class $entity does not exists");
333
-        }
334
-
335
-        if ($entityMap === null) {
336
-            $entityMap = $this->getEntityMapInstanceFor($entity);
337
-        }
338
-
339
-        if (is_string($entityMap)) {
340
-            $entityMap = new $entityMap;
341
-        }
342
-
343
-        if (!$entityMap instanceof EntityMap) {
344
-            throw new MappingException(get_class($entityMap) . ' must be an instance of EntityMap.');
345
-        }
346
-
347
-        $entityMap->setClass($entity);
348
-
349
-        $entityMap->setManager($this);
350
-
351
-        $this->entityClasses[$entity] = $entityMap;
352
-    }
353
-
354
-    /**
355
-     * Get the entity map instance for a custom entity
356
-     *
357
-     * @param  string $entity
358
-     * @return \Analogue\ORM\EntityMap
359
-     */
360
-    protected function getEntityMapInstanceFor($entity)
361
-    {
362
-        if (class_exists($entity . 'Map')) {
363
-            $map = $entity . 'Map';
364
-            $map = new $map;
365
-            return $map;
366
-        }
367
-
368
-        if ($map = $this->getMapFromNamespaces($entity)) {
369
-            return $map;
370
-        }
199
+		throw new \InvalidArgumentException('Invalid entity type');
200
+	}
201
+
202
+	/**
203
+	 * @param string $key
204
+	 * @return string
205
+	 */
206
+	public function getInverseMorphMap($key)
207
+	{
208
+		return array_key_exists($key, $this->morphMap) ? $this->morphMap[$key] : $key;
209
+	}
210
+
211
+	/**
212
+	 * Build a new Mapper instance for a given Entity
213
+	 *
214
+	 * @param  string $entity
215
+	 * @param         $entityMap
216
+	 * @throws MappingException
217
+	 * @return Mapper
218
+	 */
219
+	protected function buildMapper($entity, $entityMap)
220
+	{
221
+		// If an EntityMap hasn't been manually registered by the user
222
+		// register it at runtime.
223
+		if (!$this->isRegisteredEntity($entity)) {
224
+			$this->register($entity, $entityMap);
225
+		}
226
+
227
+		$entityMap = $this->entityClasses[$entity];
228
+
229
+		$factory = new MapperFactory($this->drivers, $this->eventDispatcher, $this);
230
+
231
+		$mapper = $factory->make($entity, $entityMap);
232
+
233
+		$this->mappers[$entity] = $mapper;
234
+
235
+		// At this point we can safely call the boot() method on the entityMap as
236
+		// the mapper is now instantiated & registered within the manager.
237
+
238
+		$mapper->getEntityMap()->boot();
239
+
240
+		return $mapper;
241
+	}
242
+
243
+	/**
244
+	 * Check if the entity is already registered
245
+	 *
246
+	 * @param  string|Entity $entity
247
+	 * @return boolean
248
+	 */
249
+	public function isRegisteredEntity($entity)
250
+	{
251
+		if (!is_string($entity)) {
252
+			$entity = get_class($entity);
253
+		}
254
+
255
+		return array_key_exists($entity, $this->entityClasses);
256
+	}
257
+
258
+	/**
259
+	 * Check if a value class is already registered
260
+	 *
261
+	 * @param string|sdtClass $object
262
+	 * @return boolean
263
+	 * 
264
+	 */
265
+	public function isRegisteredValueObject($object)
266
+	{
267
+		if (!is_string($object)) {
268
+			$object = get_class($object);
269
+		}
270
+
271
+		return array_key_exists($object, $this->valueClasses);
272
+	}
273
+
274
+	/**
275
+	 * Return true if an object is an array or iterator
276
+	 *
277
+	 * @param  mixed $argument
278
+	 * @return boolean
279
+	 */
280
+	public function isTraversable($argument)
281
+	{
282
+		return $argument instanceof \Traversable || is_array($argument);
283
+	}
284
+
285
+	/**
286
+	 * Set strict mode for entityMap instantiation
287
+	 * 
288
+	 * @param boolean $mode
289
+	 */
290
+	public function setStrictMode($mode)
291
+	{
292
+		$this->strictMode = $mode;
293
+	}
294
+
295
+	/**
296
+	 * Register a namespace in where Analogue
297
+	 * will scan for EntityMaps & ValueMaps
298
+	 *
299
+	 * @param string $namespace
300
+	 * @return void
301
+	 */
302
+	public function registerMapNamespace($namespace)
303
+	{
304
+		// Add a trailing antislash to namespace if not present
305
+		if (substr("testers", -1) != "\\") {
306
+			$namespace = $namespace."\\";
307
+		}
308
+
309
+		$this->customMapNamespaces[] = $namespace;
310
+	}
311
+
312
+	/**
313
+	 * Register an entity
314
+	 *
315
+	 * @param  string|\Analogue\ORM\Mappable $entity    entity's class name
316
+	 * @param  string|EntityMap              $entityMap map's class name
317
+	 * @throws MappingException
318
+	 * @return void
319
+	 */
320
+	public function register($entity, $entityMap = null)
321
+	{
322
+		// If an object is provider, get the class name from it
323
+		if (!is_string($entity)) {
324
+			$entity = get_class($entity);
325
+		}
326
+
327
+		if ($this->isRegisteredEntity($entity)) {
328
+			throw new MappingException("Entity $entity is already registered.");
329
+		}
330
+
331
+		if (!class_exists($entity)) {
332
+			throw new MappingException("Class $entity does not exists");
333
+		}
334
+
335
+		if ($entityMap === null) {
336
+			$entityMap = $this->getEntityMapInstanceFor($entity);
337
+		}
338
+
339
+		if (is_string($entityMap)) {
340
+			$entityMap = new $entityMap;
341
+		}
342
+
343
+		if (!$entityMap instanceof EntityMap) {
344
+			throw new MappingException(get_class($entityMap) . ' must be an instance of EntityMap.');
345
+		}
346
+
347
+		$entityMap->setClass($entity);
348
+
349
+		$entityMap->setManager($this);
350
+
351
+		$this->entityClasses[$entity] = $entityMap;
352
+	}
353
+
354
+	/**
355
+	 * Get the entity map instance for a custom entity
356
+	 *
357
+	 * @param  string $entity
358
+	 * @return \Analogue\ORM\EntityMap
359
+	 */
360
+	protected function getEntityMapInstanceFor($entity)
361
+	{
362
+		if (class_exists($entity . 'Map')) {
363
+			$map = $entity . 'Map';
364
+			$map = new $map;
365
+			return $map;
366
+		}
367
+
368
+		if ($map = $this->getMapFromNamespaces($entity)) {
369
+			return $map;
370
+		}
371 371
                 
372
-        if ($this->strictMode) {
373
-            throw new EntityMapNotFoundException("No Map registered for $entity");
374
-        }
372
+		if ($this->strictMode) {
373
+			throw new EntityMapNotFoundException("No Map registered for $entity");
374
+		}
375 375
         
376
-        $map = $this->getNewEntityMap();
377
-
378
-        return $map;
379
-    }
380
-
381
-    /**
382
-     * Scan through registered custom namespace
383
-     * for an Entity/ValueMap
384
-     * 
385
-     * @param  string $class
386
-     * @return ValueMap|EntityMap|boolean
387
-     */
388
-    protected function getMapFromNamespaces($class)
389
-    {
390
-        foreach ($this->customMapNamespaces as $namespace) {
391
-            if($map = $this->findMapInNamespace($class, $namespace)) {
392
-                return $map;
393
-            }
394
-        }
395
-
396
-        return false;
397
-    }
398
-
399
-    /**
400
-     * Look in a custom namespace for an Entity/ValueMap
401
-     * 
402
-     * @param  string $class
403
-     * @param  string $namespace
404
-     * @return ValueMap|EntityMap|boolean
405
-     */
406
-    protected function findMapInNamespace($class, $namespace)
407
-    {
408
-        $parts = explode("\\", $class);
376
+		$map = $this->getNewEntityMap();
377
+
378
+		return $map;
379
+	}
380
+
381
+	/**
382
+	 * Scan through registered custom namespace
383
+	 * for an Entity/ValueMap
384
+	 * 
385
+	 * @param  string $class
386
+	 * @return ValueMap|EntityMap|boolean
387
+	 */
388
+	protected function getMapFromNamespaces($class)
389
+	{
390
+		foreach ($this->customMapNamespaces as $namespace) {
391
+			if($map = $this->findMapInNamespace($class, $namespace)) {
392
+				return $map;
393
+			}
394
+		}
395
+
396
+		return false;
397
+	}
398
+
399
+	/**
400
+	 * Look in a custom namespace for an Entity/ValueMap
401
+	 * 
402
+	 * @param  string $class
403
+	 * @param  string $namespace
404
+	 * @return ValueMap|EntityMap|boolean
405
+	 */
406
+	protected function findMapInNamespace($class, $namespace)
407
+	{
408
+		$parts = explode("\\", $class);
409 409
         
410
-        $baseClass = $parts[count($parts) - 1];
411
-
412
-        $expectedClass = $namespace.$baseClass.'Map';
413
-
414
-        if (class_exists($expectedClass)) {
415
-            return new $expectedClass;
416
-        }
417
-
418
-        return false;
419
-    }
420
-
421
-    /**
422
-     * Dynamically create an entity map for a custom entity class
423
-     *
424
-     * @return EntityMap
425
-     */
426
-    protected function getNewEntityMap()
427
-    {
428
-        return new EntityMap;
429
-    }
430
-
431
-    /**
432
-     * Return the Singleton instance of the manager
433
-     *
434
-     * @return Manager
435
-     */
436
-    public static function getInstance()
437
-    {
438
-        return static::$instance;
439
-    }
440
-
441
-    /**
442
-     * Return the Driver Manager's instance
443
-     *
444
-     * @return \Analogue\ORM\Drivers\Manager
445
-     */
446
-    public function getDriverManager()
447
-    {
448
-        return $this->drivers;
449
-    }
450
-
451
-    /**
452
-     * Get the Repository instance for the given Entity
453
-     *
454
-     * @param  \Analogue\ORM\Mappable|string $entity
455
-     * @throws \InvalidArgumentException
456
-     * @throws MappingException
457
-     * @return \Analogue\ORM\Repository
458
-     */
459
-    public function repository($entity)
460
-    {
461
-        if (!is_string($entity)) {
462
-            $entity = get_class($entity);
463
-        }
464
-
465
-        // First we check if the repository is not already created.
466
-        if (array_key_exists($entity, $this->repositories)) {
467
-            return $this->repositories[$entity];
468
-        }
469
-
470
-        $this->repositories[$entity] = new Repository($this->mapper($entity));
471
-
472
-        return $this->repositories[$entity];
473
-    }
474
-
475
-    /**
476
-     * Return true is the object is registered as value object
477
-     *
478
-     * @param  mixed $object
479
-     * @return boolean
480
-     */
481
-    public function isValueObject($object)
482
-    {
483
-        if (!is_string($object)) {
484
-            $object = get_class($object);
485
-        }
486
-
487
-        return array_key_exists($object, $this->valueClasses);
488
-    }
489
-
490
-    /**
491
-     * Get the Value Map for a given Value Object Class
492
-     *
493
-     * @param  string $valueObject
494
-     * @throws MappingException
495
-     * @return \Analogue\ORM\ValueMap
496
-     */
497
-    public function getValueMap($valueObject)
498
-    {
499
-        if (!is_string($valueObject)) {
500
-            $valueObject = get_class($valueObject);
501
-        }
502
-
503
-        if (!array_key_exists($valueObject, $this->valueClasses)) {
504
-            $this->registerValueObject($valueObject);
505
-        }
506
-
507
-        /** @var ValueMap $valueMap */
508
-        $valueMap = new $this->valueClasses[$valueObject];
509
-
510
-        $valueMap->setClass($valueObject);
511
-
512
-        return $valueMap;
513
-    }
514
-
515
-    /**
516
-     * Register a Value Object
517
-     *
518
-     * @param  string $valueObject
519
-     * @param  string $valueMap
520
-     * @throws MappingException
521
-     * @return void
522
-     */
523
-    public function registerValueObject($valueObject, $valueMap = null)
524
-    {
525
-        if (!is_string($valueObject)) {
526
-            $valueObject = get_class($valueObject);
527
-        }
528
-
529
-        if ($valueMap === null) {
530
-
531
-            // First, we'll look into registered namespaces for Entity Maps,
532
-            // if any. Then we'll fallback to the same namespace of the object
533
-            if(! $valueMap = $this->getMapFromNamespaces($valueObject)) {
534
-                $valueMap = $valueObject . 'Map';    
535
-            }
536
-            else {
537
-                $valueMap = get_class($valueMap);
538
-            }
539
-        }
540
-
541
-        if (! class_exists($valueMap)) {
542
-            throw new MappingException("$valueMap doesn't exists");
543
-        }
544
-
545
-        $this->valueClasses[$valueObject] = $valueMap;
546
-    }
547
-
548
-    /**
549
-     * Instantiate a new Value Object instance
550
-     *
551
-     * @param  string $valueObject
552
-     * @return \Analogue\ORM\ValueObject
553
-     */
554
-    public function getValueObjectInstance($valueObject)
555
-    {
556
-        $prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($valueObject), $valueObject));
557
-
558
-        return $prototype;
559
-    }
560
-
561
-    /**
562
-     * Register Analogue Plugin
563
-     *
564
-     * @param  string $plugin class
565
-     * @return void
566
-     */
567
-    public function registerPlugin($plugin)
568
-    {
569
-        /** @var AnaloguePluginInterface $plugin */
570
-        $plugin = new $plugin($this);
571
-
572
-        $this->events = array_merge($this->events, $plugin->getCustomEvents());
573
-
574
-        $plugin->register();
575
-    }
576
-
577
-    /**
578
-     * Register event listeners that will be fired regardless the type
579
-     * of the entity.
580
-     *
581
-     * @param  string   $event
582
-     * @param  \Closure $callback
583
-     * @throws \LogicException
584
-     * @return void
585
-     */
586
-    public function registerGlobalEvent($event, $callback)
587
-    {
588
-        if (!in_array($event, $this->events, false)) {
589
-            throw new \LogicException("Analogue : Event $event doesn't exist");
590
-        }
591
-
592
-        $this->eventDispatcher->listen("analogue.{$event}.*", $callback);
593
-    }
594
-
595
-    /**
596
-     * Shortcut to Mapper store
597
-     *
598
-     * @param  mixed $entity
599
-     * @throws MappingException
600
-     * @return mixed
601
-     * @throws \InvalidArgumentException
602
-     */
603
-    public function store($entity)
604
-    {
605
-        return $this->mapper($entity)->store($entity);
606
-    }
607
-
608
-    /**
609
-     * Shortcut to Mapper delete
610
-     *
611
-     * @param  mixed $entity
612
-     * @throws MappingException
613
-     * @return \Illuminate\Support\Collection|null
614
-     * @throws \InvalidArgumentException
615
-     */
616
-    public function delete($entity)
617
-    {
618
-        return $this->mapper($entity)->delete($entity);
619
-    }
620
-
621
-    /**
622
-     * Shortcut to Mapper query
623
-     *
624
-     * @param  mixed $entity
625
-     * @throws MappingException
626
-     * @return Query
627
-     * @throws \InvalidArgumentException
628
-     */
629
-    public function query($entity)
630
-    {
631
-        return $this->mapper($entity)->query();
632
-    }
633
-
634
-    /**
635
-     * Shortcut to Mapper Global Query
636
-     *
637
-     * @param  mixed $entity
638
-     * @throws MappingException
639
-     * @return Query
640
-     * @throws \InvalidArgumentException
641
-     */
642
-    public function globalQuery($entity)
643
-    {
644
-        return $this->mapper($entity)->globalQuery();
645
-    }
646
-
647
-    /**
648
-     * @param array $morphMap
649
-     * @return $this
650
-     */
651
-    public function morphMap(array $morphMap)
652
-    {
653
-        $this->morphMap = $morphMap;
654
-
655
-        return $this;
656
-    }
657
-
658
-    /**
659
-     * @param string $class
660
-     * @return mixed
661
-     */
662
-    public function getMorphMap($class)
663
-    {
664
-        $key = array_search($class, $this->morphMap, false);
665
-
666
-        return $key !== false ? $key : $class;
667
-    }
410
+		$baseClass = $parts[count($parts) - 1];
411
+
412
+		$expectedClass = $namespace.$baseClass.'Map';
413
+
414
+		if (class_exists($expectedClass)) {
415
+			return new $expectedClass;
416
+		}
417
+
418
+		return false;
419
+	}
420
+
421
+	/**
422
+	 * Dynamically create an entity map for a custom entity class
423
+	 *
424
+	 * @return EntityMap
425
+	 */
426
+	protected function getNewEntityMap()
427
+	{
428
+		return new EntityMap;
429
+	}
430
+
431
+	/**
432
+	 * Return the Singleton instance of the manager
433
+	 *
434
+	 * @return Manager
435
+	 */
436
+	public static function getInstance()
437
+	{
438
+		return static::$instance;
439
+	}
440
+
441
+	/**
442
+	 * Return the Driver Manager's instance
443
+	 *
444
+	 * @return \Analogue\ORM\Drivers\Manager
445
+	 */
446
+	public function getDriverManager()
447
+	{
448
+		return $this->drivers;
449
+	}
450
+
451
+	/**
452
+	 * Get the Repository instance for the given Entity
453
+	 *
454
+	 * @param  \Analogue\ORM\Mappable|string $entity
455
+	 * @throws \InvalidArgumentException
456
+	 * @throws MappingException
457
+	 * @return \Analogue\ORM\Repository
458
+	 */
459
+	public function repository($entity)
460
+	{
461
+		if (!is_string($entity)) {
462
+			$entity = get_class($entity);
463
+		}
464
+
465
+		// First we check if the repository is not already created.
466
+		if (array_key_exists($entity, $this->repositories)) {
467
+			return $this->repositories[$entity];
468
+		}
469
+
470
+		$this->repositories[$entity] = new Repository($this->mapper($entity));
471
+
472
+		return $this->repositories[$entity];
473
+	}
474
+
475
+	/**
476
+	 * Return true is the object is registered as value object
477
+	 *
478
+	 * @param  mixed $object
479
+	 * @return boolean
480
+	 */
481
+	public function isValueObject($object)
482
+	{
483
+		if (!is_string($object)) {
484
+			$object = get_class($object);
485
+		}
486
+
487
+		return array_key_exists($object, $this->valueClasses);
488
+	}
489
+
490
+	/**
491
+	 * Get the Value Map for a given Value Object Class
492
+	 *
493
+	 * @param  string $valueObject
494
+	 * @throws MappingException
495
+	 * @return \Analogue\ORM\ValueMap
496
+	 */
497
+	public function getValueMap($valueObject)
498
+	{
499
+		if (!is_string($valueObject)) {
500
+			$valueObject = get_class($valueObject);
501
+		}
502
+
503
+		if (!array_key_exists($valueObject, $this->valueClasses)) {
504
+			$this->registerValueObject($valueObject);
505
+		}
506
+
507
+		/** @var ValueMap $valueMap */
508
+		$valueMap = new $this->valueClasses[$valueObject];
509
+
510
+		$valueMap->setClass($valueObject);
511
+
512
+		return $valueMap;
513
+	}
514
+
515
+	/**
516
+	 * Register a Value Object
517
+	 *
518
+	 * @param  string $valueObject
519
+	 * @param  string $valueMap
520
+	 * @throws MappingException
521
+	 * @return void
522
+	 */
523
+	public function registerValueObject($valueObject, $valueMap = null)
524
+	{
525
+		if (!is_string($valueObject)) {
526
+			$valueObject = get_class($valueObject);
527
+		}
528
+
529
+		if ($valueMap === null) {
530
+
531
+			// First, we'll look into registered namespaces for Entity Maps,
532
+			// if any. Then we'll fallback to the same namespace of the object
533
+			if(! $valueMap = $this->getMapFromNamespaces($valueObject)) {
534
+				$valueMap = $valueObject . 'Map';    
535
+			}
536
+			else {
537
+				$valueMap = get_class($valueMap);
538
+			}
539
+		}
540
+
541
+		if (! class_exists($valueMap)) {
542
+			throw new MappingException("$valueMap doesn't exists");
543
+		}
544
+
545
+		$this->valueClasses[$valueObject] = $valueMap;
546
+	}
547
+
548
+	/**
549
+	 * Instantiate a new Value Object instance
550
+	 *
551
+	 * @param  string $valueObject
552
+	 * @return \Analogue\ORM\ValueObject
553
+	 */
554
+	public function getValueObjectInstance($valueObject)
555
+	{
556
+		$prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($valueObject), $valueObject));
557
+
558
+		return $prototype;
559
+	}
560
+
561
+	/**
562
+	 * Register Analogue Plugin
563
+	 *
564
+	 * @param  string $plugin class
565
+	 * @return void
566
+	 */
567
+	public function registerPlugin($plugin)
568
+	{
569
+		/** @var AnaloguePluginInterface $plugin */
570
+		$plugin = new $plugin($this);
571
+
572
+		$this->events = array_merge($this->events, $plugin->getCustomEvents());
573
+
574
+		$plugin->register();
575
+	}
576
+
577
+	/**
578
+	 * Register event listeners that will be fired regardless the type
579
+	 * of the entity.
580
+	 *
581
+	 * @param  string   $event
582
+	 * @param  \Closure $callback
583
+	 * @throws \LogicException
584
+	 * @return void
585
+	 */
586
+	public function registerGlobalEvent($event, $callback)
587
+	{
588
+		if (!in_array($event, $this->events, false)) {
589
+			throw new \LogicException("Analogue : Event $event doesn't exist");
590
+		}
591
+
592
+		$this->eventDispatcher->listen("analogue.{$event}.*", $callback);
593
+	}
594
+
595
+	/**
596
+	 * Shortcut to Mapper store
597
+	 *
598
+	 * @param  mixed $entity
599
+	 * @throws MappingException
600
+	 * @return mixed
601
+	 * @throws \InvalidArgumentException
602
+	 */
603
+	public function store($entity)
604
+	{
605
+		return $this->mapper($entity)->store($entity);
606
+	}
607
+
608
+	/**
609
+	 * Shortcut to Mapper delete
610
+	 *
611
+	 * @param  mixed $entity
612
+	 * @throws MappingException
613
+	 * @return \Illuminate\Support\Collection|null
614
+	 * @throws \InvalidArgumentException
615
+	 */
616
+	public function delete($entity)
617
+	{
618
+		return $this->mapper($entity)->delete($entity);
619
+	}
620
+
621
+	/**
622
+	 * Shortcut to Mapper query
623
+	 *
624
+	 * @param  mixed $entity
625
+	 * @throws MappingException
626
+	 * @return Query
627
+	 * @throws \InvalidArgumentException
628
+	 */
629
+	public function query($entity)
630
+	{
631
+		return $this->mapper($entity)->query();
632
+	}
633
+
634
+	/**
635
+	 * Shortcut to Mapper Global Query
636
+	 *
637
+	 * @param  mixed $entity
638
+	 * @throws MappingException
639
+	 * @return Query
640
+	 * @throws \InvalidArgumentException
641
+	 */
642
+	public function globalQuery($entity)
643
+	{
644
+		return $this->mapper($entity)->globalQuery();
645
+	}
646
+
647
+	/**
648
+	 * @param array $morphMap
649
+	 * @return $this
650
+	 */
651
+	public function morphMap(array $morphMap)
652
+	{
653
+		$this->morphMap = $morphMap;
654
+
655
+		return $this;
656
+	}
657
+
658
+	/**
659
+	 * @param string $class
660
+	 * @return mixed
661
+	 */
662
+	public function getMorphMap($class)
663
+	{
664
+		$key = array_search($class, $this->morphMap, false);
665
+
666
+		return $key !== false ? $key : $class;
667
+	}
668 668
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
         // We first check if the entity is traversable and we'll resolve
178 178
         // the entity based on the first item of the object.   
179 179
         if ($this->isTraversable($entity)) {
180
-            if (! count($entity)) {
180
+            if (!count($entity)) {
181 181
                 throw new \InvalidArgumentException('Length of Entity collection must be greater than 0');
182 182
             }
183 183
 
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
         }
342 342
 
343 343
         if (!$entityMap instanceof EntityMap) {
344
-            throw new MappingException(get_class($entityMap) . ' must be an instance of EntityMap.');
344
+            throw new MappingException(get_class($entityMap).' must be an instance of EntityMap.');
345 345
         }
346 346
 
347 347
         $entityMap->setClass($entity);
@@ -359,8 +359,8 @@  discard block
 block discarded – undo
359 359
      */
360 360
     protected function getEntityMapInstanceFor($entity)
361 361
     {
362
-        if (class_exists($entity . 'Map')) {
363
-            $map = $entity . 'Map';
362
+        if (class_exists($entity.'Map')) {
363
+            $map = $entity.'Map';
364 364
             $map = new $map;
365 365
             return $map;
366 366
         }
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
     protected function getMapFromNamespaces($class)
389 389
     {
390 390
         foreach ($this->customMapNamespaces as $namespace) {
391
-            if($map = $this->findMapInNamespace($class, $namespace)) {
391
+            if ($map = $this->findMapInNamespace($class, $namespace)) {
392 392
                 return $map;
393 393
             }
394 394
         }
@@ -530,15 +530,15 @@  discard block
 block discarded – undo
530 530
 
531 531
             // First, we'll look into registered namespaces for Entity Maps,
532 532
             // if any. Then we'll fallback to the same namespace of the object
533
-            if(! $valueMap = $this->getMapFromNamespaces($valueObject)) {
534
-                $valueMap = $valueObject . 'Map';    
533
+            if (!$valueMap = $this->getMapFromNamespaces($valueObject)) {
534
+                $valueMap = $valueObject.'Map';    
535 535
             }
536 536
             else {
537 537
                 $valueMap = get_class($valueMap);
538 538
             }
539 539
         }
540 540
 
541
-        if (! class_exists($valueMap)) {
541
+        if (!class_exists($valueMap)) {
542 542
             throw new MappingException("$valueMap doesn't exists");
543 543
         }
544 544
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -129,8 +129,7 @@
 block discarded – undo
129 129
             if ($this->hasSetMutator($key)) {
130 130
                 $method = 'set' . $this->getMutatorMethod($key);
131 131
                 $this->attributes[$key] = $this->$method($attribute);
132
-            }
133
-            else {
132
+            } else {
134 133
                 $this->attributes[$key] = $attribute;
135 134
             }
136 135
         }
Please login to merge, or discard this patch.
src/System/Wrappers/PlainObjectWrapper.php 3 patches
Indentation   +233 added lines, -233 removed lines patch added patch discarded remove patch
@@ -6,239 +6,239 @@
 block discarded – undo
6 6
 
7 7
 class PlainObjectWrapper extends Wrapper
8 8
 {
9
-    /**
10
-     * The list of attributes for the managed entity
11
-     *
12
-     * @var array
13
-     */
14
-    protected $attributeList;
15
-
16
-    /**
17
-     * The reflection class for the managed entity
18
-     *
19
-     * @var ReflectionClass
20
-     */
21
-    protected $reflection;
22
-
23
-    /**
24
-     * Attributes which have no existence on the actual entity
25
-     * but which exists in DB (eg : foreign key)
26
-     * 
27
-     * @var array
28
-     */
29
-    protected $virtualAttributes = [];
30
-
31
-    /**
32
-     * PlainObjectWrapper constructor.
33
-     * 
34
-     * @param $popoEntity
35
-     * @param $entityMap
36
-     */
37
-    public function __construct($popoEntity, $entityMap)
38
-    {
39
-        $this->reflection = new ReflectionClass($popoEntity);
40
-
41
-        parent::__construct($popoEntity, $entityMap);
42
-
43
-        $this->attributeList = $this->getAttributeList();
44
-    }
45
-
46
-    /**
47
-     * Get Compiled Attributes (key, attributes, embed, relations)
48
-     *
49
-     * @return array
50
-     */
51
-    protected function getAttributeList()
52
-    {
53
-        return  $this->entityMap->getCompiledAttributes();
54
-    }
55
-
56
-    /**
57
-     * Extract Attributes from a Plain Php Object
58
-     *
59
-     * @return array $attributes
60
-     */
61
-    protected function extract()
62
-    {
63
-        $properties = $this->getMappedProperties();
64
-
65
-        $attributes = [];
66
-
67
-        foreach ($properties as $property) {
68
-            $name = $property->getName();
69
-
70
-            if ($property->isPublic()) {
71
-                $attributes[$name] = $this->entity->$name;
72
-            } else {
73
-                $property->setAccessible(true);
9
+	/**
10
+	 * The list of attributes for the managed entity
11
+	 *
12
+	 * @var array
13
+	 */
14
+	protected $attributeList;
15
+
16
+	/**
17
+	 * The reflection class for the managed entity
18
+	 *
19
+	 * @var ReflectionClass
20
+	 */
21
+	protected $reflection;
22
+
23
+	/**
24
+	 * Attributes which have no existence on the actual entity
25
+	 * but which exists in DB (eg : foreign key)
26
+	 * 
27
+	 * @var array
28
+	 */
29
+	protected $virtualAttributes = [];
30
+
31
+	/**
32
+	 * PlainObjectWrapper constructor.
33
+	 * 
34
+	 * @param $popoEntity
35
+	 * @param $entityMap
36
+	 */
37
+	public function __construct($popoEntity, $entityMap)
38
+	{
39
+		$this->reflection = new ReflectionClass($popoEntity);
40
+
41
+		parent::__construct($popoEntity, $entityMap);
42
+
43
+		$this->attributeList = $this->getAttributeList();
44
+	}
45
+
46
+	/**
47
+	 * Get Compiled Attributes (key, attributes, embed, relations)
48
+	 *
49
+	 * @return array
50
+	 */
51
+	protected function getAttributeList()
52
+	{
53
+		return  $this->entityMap->getCompiledAttributes();
54
+	}
55
+
56
+	/**
57
+	 * Extract Attributes from a Plain Php Object
58
+	 *
59
+	 * @return array $attributes
60
+	 */
61
+	protected function extract()
62
+	{
63
+		$properties = $this->getMappedProperties();
64
+
65
+		$attributes = [];
66
+
67
+		foreach ($properties as $property) {
68
+			$name = $property->getName();
69
+
70
+			if ($property->isPublic()) {
71
+				$attributes[$name] = $this->entity->$name;
72
+			} else {
73
+				$property->setAccessible(true);
74 74
     
75
-                $attributes[$name] = $property->getValue($this->entity);
76
-            }
77
-        }
78
-
79
-        return $attributes;
80
-    }
81
-
82
-    /**
83
-     * @return \ReflectionProperty[]
84
-     */
85
-    protected function getMappedProperties()
86
-    {
87
-        $objectProperties = $this->reflection->getProperties();
88
-
89
-        $attributeList = $this->getAttributeList();
90
-
91
-        // We need to filter out properties that could belong to the object
92
-        // and which are not intended to be handled by the ORM
93
-        return array_filter($objectProperties, function (\ReflectionProperty $item) use ($attributeList) {
94
-            if (in_array($item->getName(), $attributeList)) {
95
-                return true;
96
-            }
97
-        });
98
-    }
99
-
100
-    /**
101
-     * Get the property's value from reflection
102
-     * 
103
-     * @param  string $name
104
-     * @return \ReflectionProperty | null
105
-     */
106
-    protected function getMappedProperty($name)
107
-    {
108
-        return $this->reflection->getProperty($name);
109
-    }
110
-
111
-    /**
112
-     * Hydrate Plain PHP Object with wrapped attributes
113
-     *
114
-     * @param  $attributes
115
-     * @return void
116
-     */
117
-    protected function hydrate($attributes)
118
-    {
119
-        $properties = $this->getMappedProperties();
120
-
121
-        foreach ($properties as $property) {
122
-            $name = $property->getName();
123
-
124
-            if ($property->isPublic()) {
125
-                $this->entity->$name = $attributes[$name];
126
-            } else {
127
-                $property->setAccessible(true);
128
-
129
-                $property->setValue($this->entity, $attributes[$name]);
130
-            }
131
-        }
132
-    }
133
-
134
-    /**
135
-     * Method used by the mapper to set the object
136
-     * attribute raw values (hydration)
137
-     *
138
-     * @param array $attributes
139
-     *
140
-     * @return void
141
-     */
142
-    public function setEntityAttributes(array $attributes)
143
-    {
144
-        $this->hydrate($attributes);
145
-    }
146
-
147
-    /**
148
-     * Method used by the mapper to get the
149
-     * raw object's values.
150
-     *
151
-     * @return array
152
-     */
153
-    public function getEntityAttributes()
154
-    {
155
-        $properties = $this->extract();
156
-
157
-        return array_merge($properties, $this->virtualAttributes);
158
-    }
159
-
160
-    /**
161
-     * Method used by the mapper to set raw
162
-     * key-value pair
163
-     *
164
-     * @param string $key
165
-     * @param string $value
166
-     *
167
-     * @return void
168
-     */
169
-    public function setEntityAttribute($key, $value)
170
-    {
171
-        if(! $this->reflection->hasProperty($key)) {
172
-            $this->virtualAttributes[$key] = $value;
173
-            return;
174
-        }
175
-
176
-        $property = $this->getMappedProperty($key);
177
-
178
-        if ($property->isPublic()) {
179
-            $this->entity->$key = $value;
180
-        } else {
181
-            $property->setAccessible(true);
75
+				$attributes[$name] = $property->getValue($this->entity);
76
+			}
77
+		}
78
+
79
+		return $attributes;
80
+	}
81
+
82
+	/**
83
+	 * @return \ReflectionProperty[]
84
+	 */
85
+	protected function getMappedProperties()
86
+	{
87
+		$objectProperties = $this->reflection->getProperties();
88
+
89
+		$attributeList = $this->getAttributeList();
90
+
91
+		// We need to filter out properties that could belong to the object
92
+		// and which are not intended to be handled by the ORM
93
+		return array_filter($objectProperties, function (\ReflectionProperty $item) use ($attributeList) {
94
+			if (in_array($item->getName(), $attributeList)) {
95
+				return true;
96
+			}
97
+		});
98
+	}
99
+
100
+	/**
101
+	 * Get the property's value from reflection
102
+	 * 
103
+	 * @param  string $name
104
+	 * @return \ReflectionProperty | null
105
+	 */
106
+	protected function getMappedProperty($name)
107
+	{
108
+		return $this->reflection->getProperty($name);
109
+	}
110
+
111
+	/**
112
+	 * Hydrate Plain PHP Object with wrapped attributes
113
+	 *
114
+	 * @param  $attributes
115
+	 * @return void
116
+	 */
117
+	protected function hydrate($attributes)
118
+	{
119
+		$properties = $this->getMappedProperties();
120
+
121
+		foreach ($properties as $property) {
122
+			$name = $property->getName();
123
+
124
+			if ($property->isPublic()) {
125
+				$this->entity->$name = $attributes[$name];
126
+			} else {
127
+				$property->setAccessible(true);
128
+
129
+				$property->setValue($this->entity, $attributes[$name]);
130
+			}
131
+		}
132
+	}
133
+
134
+	/**
135
+	 * Method used by the mapper to set the object
136
+	 * attribute raw values (hydration)
137
+	 *
138
+	 * @param array $attributes
139
+	 *
140
+	 * @return void
141
+	 */
142
+	public function setEntityAttributes(array $attributes)
143
+	{
144
+		$this->hydrate($attributes);
145
+	}
146
+
147
+	/**
148
+	 * Method used by the mapper to get the
149
+	 * raw object's values.
150
+	 *
151
+	 * @return array
152
+	 */
153
+	public function getEntityAttributes()
154
+	{
155
+		$properties = $this->extract();
156
+
157
+		return array_merge($properties, $this->virtualAttributes);
158
+	}
159
+
160
+	/**
161
+	 * Method used by the mapper to set raw
162
+	 * key-value pair
163
+	 *
164
+	 * @param string $key
165
+	 * @param string $value
166
+	 *
167
+	 * @return void
168
+	 */
169
+	public function setEntityAttribute($key, $value)
170
+	{
171
+		if(! $this->reflection->hasProperty($key)) {
172
+			$this->virtualAttributes[$key] = $value;
173
+			return;
174
+		}
175
+
176
+		$property = $this->getMappedProperty($key);
177
+
178
+		if ($property->isPublic()) {
179
+			$this->entity->$key = $value;
180
+		} else {
181
+			$property->setAccessible(true);
182 182
     
183
-            $property->setValue($this->entity, $value);
184
-        }
185
-
186
-        $this->attributes[$key] = $value;
187
-    }
188
-
189
-    /**
190
-     * Method used by the mapper to get single
191
-     * key-value pair
192
-     *
193
-     * @param  string $key
194
-     * @return mixed|null
195
-     */
196
-    public function getEntityAttribute($key)
197
-    {
198
-        if(! $this->reflection->hasProperty($key)) {
199
-            return $this->getVirtualAttribute($key);
200
-        }
201
-
202
-        $property = $this->getMappedProperty($key);
203
-
204
-        if ($property->isPublic()) {
205
-            $value = $this->entity->$key;
206
-        } else {
207
-            $property->setAccessible(true);
208
-            $value = $property->getValue($this->entity);
209
-        }
210
-
211
-        return $value;
212
-    }
213
-
214
-    /**
215
-     * Return a virtual attributes
216
-     * 
217
-     * @param  string $key
218
-     * @return mixed
219
-     */
220
-    protected function getVirtualAttribute($key)
221
-    {
222
-        if(array_key_exists($key, $this->virtualAttributes)) {
223
-            return $this->virtualAttributes[$key];
224
-        }
225
-        else {
226
-            return null;
227
-        }
228
-    }
229
-
230
-    /**
231
-     * Test if a given attribute exists
232
-     *
233
-     * @param  string  $key
234
-     * @return boolean
235
-     */
236
-    public function hasAttribute($key)
237
-    {
238
-        if (in_array($key, $this->attributeList)) {
239
-            return true;
240
-        } else {
241
-            return false;
242
-        }
243
-    }
183
+			$property->setValue($this->entity, $value);
184
+		}
185
+
186
+		$this->attributes[$key] = $value;
187
+	}
188
+
189
+	/**
190
+	 * Method used by the mapper to get single
191
+	 * key-value pair
192
+	 *
193
+	 * @param  string $key
194
+	 * @return mixed|null
195
+	 */
196
+	public function getEntityAttribute($key)
197
+	{
198
+		if(! $this->reflection->hasProperty($key)) {
199
+			return $this->getVirtualAttribute($key);
200
+		}
201
+
202
+		$property = $this->getMappedProperty($key);
203
+
204
+		if ($property->isPublic()) {
205
+			$value = $this->entity->$key;
206
+		} else {
207
+			$property->setAccessible(true);
208
+			$value = $property->getValue($this->entity);
209
+		}
210
+
211
+		return $value;
212
+	}
213
+
214
+	/**
215
+	 * Return a virtual attributes
216
+	 * 
217
+	 * @param  string $key
218
+	 * @return mixed
219
+	 */
220
+	protected function getVirtualAttribute($key)
221
+	{
222
+		if(array_key_exists($key, $this->virtualAttributes)) {
223
+			return $this->virtualAttributes[$key];
224
+		}
225
+		else {
226
+			return null;
227
+		}
228
+	}
229
+
230
+	/**
231
+	 * Test if a given attribute exists
232
+	 *
233
+	 * @param  string  $key
234
+	 * @return boolean
235
+	 */
236
+	public function hasAttribute($key)
237
+	{
238
+		if (in_array($key, $this->attributeList)) {
239
+			return true;
240
+		} else {
241
+			return false;
242
+		}
243
+	}
244 244
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 
91 91
         // We need to filter out properties that could belong to the object
92 92
         // and which are not intended to be handled by the ORM
93
-        return array_filter($objectProperties, function (\ReflectionProperty $item) use ($attributeList) {
93
+        return array_filter($objectProperties, function(\ReflectionProperty $item) use ($attributeList) {
94 94
             if (in_array($item->getName(), $attributeList)) {
95 95
                 return true;
96 96
             }
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
      */
169 169
     public function setEntityAttribute($key, $value)
170 170
     {
171
-        if(! $this->reflection->hasProperty($key)) {
171
+        if (!$this->reflection->hasProperty($key)) {
172 172
             $this->virtualAttributes[$key] = $value;
173 173
             return;
174 174
         }
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
      */
196 196
     public function getEntityAttribute($key)
197 197
     {
198
-        if(! $this->reflection->hasProperty($key)) {
198
+        if (!$this->reflection->hasProperty($key)) {
199 199
             return $this->getVirtualAttribute($key);
200 200
         }
201 201
 
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      */
220 220
     protected function getVirtualAttribute($key)
221 221
     {
222
-        if(array_key_exists($key, $this->virtualAttributes)) {
222
+        if (array_key_exists($key, $this->virtualAttributes)) {
223 223
             return $this->virtualAttributes[$key];
224 224
         }
225 225
         else {
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -221,8 +221,7 @@
 block discarded – undo
221 221
     {
222 222
         if(array_key_exists($key, $this->virtualAttributes)) {
223 223
             return $this->virtualAttributes[$key];
224
-        }
225
-        else {
224
+        } else {
226 225
             return null;
227 226
         }
228 227
     }
Please login to merge, or discard this patch.