ObjectCollection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 32
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
objectsClassName() 0 1 ?
A __clone() 0 7 2
A validateType() 0 7 3
1
<?php
2
3
  namespace Fiv\Collection;
4
5
  abstract class ObjectCollection extends TypedCollection {
6
7
    /**
8
     * Used for validation
9
     * Return class name
10
     *
11
     * @codeCoverageIgnore
12
     * @return string
13
     */
14
    public abstract function objectsClassName();
15
16
    /**
17
     * Clone each item
18
     */
19
    public function __clone() {
20
      $items = array();
21
      foreach ($this->items as $item) {
22
        $items[] = clone $item;
23
      }
24
      $this->setItems($items);
25
    }
26
27
28
    public function validateType($item) {
29
      $itemClass = $this->objectsClassName();
30
      if (($item instanceof $itemClass) == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
31
        $className = ($item === null) ? null : get_class($item);
32
        throw new \Exception('Invalid object type. Expect ' . $this->objectsClassName() . ' given ' . $className);
33
      }
34
    }
35
36
  }
37