Passed
Push — master ( 9a001d...5206a3 )
by smiley
02:36
created

EnumerableTrait::each()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 *
4
 * @filesource   EnumerableTrait.php
5
 * @created      11.05.2017
6
 * @package      chillerlan\PrototypeDOM\Traits
7
 * @author       Smiley <[email protected]>
8
 * @copyright    2017 Smiley
9
 * @license      MIT
10
 */
11
12
namespace chillerlan\PrototypeDOM\Traits;
13
14
use chillerlan\Traits\Enumerable;
15
16
/**
17
 * Trait EnumerableTrait
18
 */
19
trait EnumerableTrait{
20
	use Enumerable{
21
		__map as map;
22
		__each as each;
23
		__toArray as toArray;
24
	}
25
26
	/**
27
	 * @link http://api.prototypejs.org/language/Array/prototype/first/
28
	 *
29
	 * @return \chillerlan\PrototypeDOM\Node\Element|null
30
	 */
31 3
	public function first(){
32 3
		return $this->item(0);
0 ignored issues
show
Bug introduced by
It seems like item() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
33
	}
34
35
	/**
36
	 * @link http://api.prototypejs.org/language/Array/prototype/last/
37
	 *
38
	 * @return \chillerlan\PrototypeDOM\Node\Element|null
39
	 */
40 1
	public function last(){
41 1
		return $this->item($this->count() - 1);
0 ignored issues
show
Bug introduced by
It seems like count() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Bug introduced by
It seems like item() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
42
	}
43
44
	/**
45
	 * @link http://api.prototypejs.org/language/Enumerable/prototype/pluck/
46
	 *
47
	 * @param string $property
48
	 *
49
	 * @return array
50
	 */
51 3
	public function pluck(string $property):array {
52 3
		return array_column($this->array, $property);
53
	}
54
55
	/**
56
	 * @link http://api.prototypejs.org/language/Array/prototype/reverse/
57
	 *
58
	 * @return $this
59
	 */
60 3
	public function reverse(){
61 3
		$this->array = array_reverse($this->array);
62 3
		$this->rewind();
0 ignored issues
show
Bug introduced by
It seems like rewind() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
63
64 3
		return $this;
65
	}
66
67
	/**
68
	 * @link http://api.prototypejs.org/language/Enumerable/prototype/toArray/
69
	 *
70
	 * @return array
71
	 */
72 1
	public function toArray():array {
73 1
		return $this->array;
74
	}
75
76
}
77