BaseCollection::isEmpty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of Yolk - Gamer Network's PHP Framework.
4
 *
5
 * Copyright (c) 2015 Gamer Network Ltd.
6
 *
7
 * Distributed under the MIT License, a copy of which is available in the
8
 * LICENSE file that was bundled with this package, or online at:
9
 * https://github.com/gamernetwork/yolk-support
10
 */
11
12
namespace yolk\support\collections;
13
14
use yolk\contracts\support\Arrayable;
15
use yolk\contracts\support\collections\Collection;
16
17
/**
18
 * Basic collection implementation.
19
 * Should not be implemented directly, instead use one of the more specific
20
 * sub-classes, such as BaseSet or BaseDictionary
21
 */
22
class BaseCollection implements \IteratorAggregate, Collection, Arrayable {
23
24
	protected $items;
25
26
	public function __construct( array $items = [] ) {
27
		$this->items = $items;
28
	}
29
30
	public function count() {
31
		return count($this->items);
32
	}
33
34
	public function isEmpty() {
35
		return count($this->items) == 0;
36
	}
37
38
	public function clear() {
39
		$this->items = [];
40
		return $this;
41
	}
42
43
	public function contains( $item ) {
44
		return array_search($item, $this->items) !== false;
45
	}
46
47
	public function toArray() {
48
		return $this->items;
49
	}
50
51
	public function getIterator() {
52
		return new \ArrayIterator($this->items);
53
	}
54
55
}
56
57
// EOF