Completed
Branch FET/Gutenberg/11426/event-atte... (b97e58)
by
unknown
13:20 queued 15s
created

BlockCollection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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