Completed
Push — master ( 0bc6c0...2c7298 )
by Rudi
02:18
created

Collection::copy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Ds\Traits;
3
4
/**
5
 * Collection
6
 *
7
 * @package Ds\Traits
8
 */
9
trait Collection
10
{
11
    /**
12
     * Returns whether the collection is empty.
13
     *
14
     * This should be equivalent to a count of zero, but is not required.
15
     * Implementations should define what empty means in their own context.
16
     *
17
     * @return bool
18
     */
19
    public function isEmpty(): bool
20
    {
21
        return count($this) === 0;
22
    }
23
24
    /**
25
     * Json Serialize
26
     *
27
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be array? Also, consider making the array more specific, something like array<String>, or String[].

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

If the return type contains the type array, this check recommends the use of a more specific type like String[] or array<String>.

Loading history...
28
     */
29
    public function jsonSerialize()
30
    {
31
        return $this->toArray();
32
    }
33
34
    /**
35
     * Creates a copy of the collection.
36
     *
37
     * @return self
0 ignored issues
show
Documentation introduced by
Should the return type not be \Ds\Collection?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
38
     */
39
    public function copy(): \Ds\Collection
40
    {
41
        return new self($this);
0 ignored issues
show
Unused Code introduced by
The call to Collection::__construct() has too many arguments starting with $this.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
42
    }
43
44
    /**
45
     * Returns an array representation of the collection.
46
     *
47
     * The format of the returned array is implementation-dependent.
48
     * Some implementations may throw an exception if an array representation
49
     * could not be created.
50
     *
51
     * @return array
52
     */
53
    abstract public function toArray(): array;
54
55
    /**
56
     * Debug Info
57
     */
58
    public function __debugInfo()
59
    {
60
        return $this->toArray();
61
    }
62
63
    /**
64
     * To String
65
     */
66
    public function __toString()
67
    {
68
        return 'object(' . get_class($this) . ')';
69
    }
70
}
71