Completed
Branch BUG/reg-status-change-recursio... (2db0c9)
by
unknown
20:03 queued 10:32
created

BlockCollection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 23.64 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A unRegisterBlock() 13 13 3
A unRegisterAllBlocks() 0 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace EventEspresso\core\domain\entities\editor;
4
5
use EventEspresso\core\exceptions\InvalidInterfaceException;
6
use EventEspresso\core\services\collections\Collection;
7
8
/**
9
 * Class BlockCollection
10
 * a Collection of Block objects
11
 *
12
 * @package EventEspresso\core\services\editor
13
 * @author  Brent Christensen
14
 * @since   $VID:$
15
 */
16
class BlockCollection extends Collection
17
{
18
19
    /**
20
     * Collection constructor
21
     *
22
     * @throws InvalidInterfaceException
23
     */
24
    public function __construct()
25
    {
26
        parent::__construct('EventEspresso\core\domain\entities\editor\BlockInterface');
27
    }
28
29
30
    /**
31
     * unRegisterBlock
32
     * finds block in the Collection based on the identifier that was set using addObject()
33
     * and calls unRegisterBlock() on it. Returns block if successful and false if block was not found.
34
     * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
35
     *
36
     * @param mixed $identifier
37
     * @return boolean
38
     */
39 View Code Duplication
    public function unRegisterBlock($identifier)
40
    {
41
        $this->rewind();
42
        while ($this->valid()) {
43
            if ($identifier === $this->getInfo()) {
44
                $object = $this->current();
45
                $this->rewind();
46
                return $object->unRegisterBlock();
47
            }
48
            $this->next();
49
        }
50
        return false;
51
    }
52
53
54
    /**
55
     * unRegisterAllBlocks
56
     * calls unRegisterBlock() on all blocks in Collection.
57
     * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
58
     *
59
     * @return void
60
     */
61
    public function unRegisterAllBlocks()
62
    {
63
        $this->rewind();
64
        while ($this->valid()) {
65
            $this->current()->unRegisterBlock();
66
            $this->next();
67
        }
68
        $this->rewind();
69
    }
70
}
71