Completed
Branch FET/Gutenberg/11426/event-atte... (b97e58)
by
unknown
59:18 queued 44:03
created

BlockCollection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 23.64 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
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
defined('EVENT_ESPRESSO_VERSION') || exit;
9
10
11
12
/**
13
 * Class BlockCollection
14
 * a Collection of Block objects
15
 *
16
 * @package EventEspresso\core\services\editor
17
 * @author  Brent Christensen
18
 * @since   $VID:$
19
 */
20
class BlockCollection extends Collection
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: offsetExists, offsetGet, offsetSet, offsetUnset
Loading history...
21
{
22
23
    /**
24
     * Collection constructor
25
     *
26
     * @throws InvalidInterfaceException
27
     */
28
    public function __construct()
29
    {
30
        parent::__construct('EventEspresso\core\domain\entities\editor\BlockInterface');
31
    }
32
33
34
    /**
35
     * unRegisterBlock
36
     * finds block in the Collection based on the identifier that was set using addObject()
37
     * and calls unRegisterBlock() on it. Returns block if successful and false if block was not found.
38
     * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
39
     *
40
     * @param mixed $identifier
41
     * @return boolean
42
     */
43 View Code Duplication
    public function unRegisterBlock($identifier)
44
    {
45
        $this->rewind();
46
        while ($this->valid()) {
47
            if ($identifier === $this->getInfo()) {
48
                $object = $this->current();
49
                $this->rewind();
50
                return $object->unRegisterBlock();
51
            }
52
            $this->next();
53
        }
54
        return false;
55
    }
56
57
58
    /**
59
     * unRegisterAllBlocks
60
     * calls unRegisterBlock() on all blocks in Collection.
61
     * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
62
     *
63
     * @return void
64
     */
65
    public function unRegisterAllBlocks()
66
    {
67
        $this->rewind();
68
        while ($this->valid()) {
69
            $this->current()->unRegisterBlock();
70
            $this->next();
71
        }
72
        $this->rewind();
73
    }
74
}
75