Completed
Push — master ( 547e17...d8178d )
by Siro Díaz
01:37
created

CountTrait::empty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * DataStructures for PHP
4
 *
5
 * @link      https://github.com/SiroDiaz/DataStructures
6
 * @copyright Copyright (c) 2017 Siro Díaz Palazón
7
 * @license   https://github.com/SiroDiaz/DataStructures/blob/master/README.md (MIT License)
8
 */
9
namespace DataStructures\Lists\Traits;
10
11
/**
12
 * CountTrait
13
 *
14
 * CountTrait is a trait that implements the Countable interface methods and
15
 * size method to avoid repeating code in the List hierarchy classes.
16
 *
17
 * @author Siro Diaz Palazon <[email protected]>
18
 */
19
trait CountTrait {
20
    /**
21
     * Binds to count() method. This is equal to make $this->tree->size().
22
     *
23
     * @return integer the tree size. 0 if it is empty.
24
     */
25
    public function count() {
26
        return $this->size;
0 ignored issues
show
Bug introduced by
The property size does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27
    }
28
29
    /**
30
     * Returns the array size.
31
     *
32
     * @return int the length
33
     */
34
    public function size() : int {
35
        return $this->size;
36
    }
37
38
    /**
39
     * Checks if the list is empty.
40
     *
41
     * @return boolean true if is empty, else false.
42
     */
43
    public function empty() : bool {
44
        return $this->size === 0;
45
    }
46
}