Passed
Push — 1.x ( d4c886...fd692a )
by Ulises Jeremias
02:56
created

Collection::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php namespace Mbh\Collection\Traits;
2
3
/**
4
 * MBHFramework
5
 *
6
 * @link      https://github.com/MBHFramework/mbh-framework
7
 * @copyright Copyright (c) 2017 Ulises Jeremias Cornejo Fandos
8
 * @license   https://github.com/MBHFramework/mbh-framework/blob/master/LICENSE (MIT License)
9
 */
10
11
trait Collection
12
{
13
    /**
14
     * Returns whether the collection is empty.
15
     *
16
     * This should be equivalent to a count of zero, but is not required.
17
     * Implementations should define what empty means in their own context.
18
     *
19
     * @return bool whether the collection is empty.
20
     */
21
    public function isEmpty(): bool
22
    {
23
        return count($this) === 0;
0 ignored issues
show
Bug introduced by
$this of type Mbh\Collection\Traits\Collection is incompatible with the type Countable|array expected by parameter $var of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
        return count(/** @scrutinizer ignore-type */ $this) === 0;
Loading history...
24
    }
25
26
    /**
27
     * Returns a representation that can be natively converted to JSON, which is
28
     * called when invoking json_encode.
29
     *
30
     * @return mixed
31
     *
32
     * @see JsonSerializable
33
     */
34
    public function jsonSerialize(): array
35
    {
36
        return $this->toArray();
37
    }
38
39
40
    /**
41
     * Returns an array representation of the collection.
42
     *
43
     * The format of the returned array is implementation-dependent. Some
44
     * implementations may throw an exception if an array representation
45
     * could not be created (for example when object are used as keys).
46
     *
47
     * @return array
48
     */
49
    abstract public function toArray(): array;
50
51
    /**
52
     * Invoked when calling var_dump.
53
     *
54
     * @return array
55
     */
56
    public function __debugInfo()
57
    {
58
        return $this->toArray();
59
    }
60
61
    /**
62
     * Returns a string representation of the collection, which is invoked when
63
     * the collection is converted to a string.
64
     */
65
    public function __toString()
66
    {
67
        return 'object(' . get_class($this) . ')';
68
    }
69
}
70