1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Nozavroni/Collections |
4
|
|
|
* Just another collections library for PHP5.6+. |
5
|
|
|
* @version {version} |
6
|
|
|
* @copyright Copyright (c) 2017 Luke Visinoni <[email protected]> |
7
|
|
|
* @author Luke Visinoni <[email protected]> |
8
|
|
|
* @license https://github.com/deni-zen/csvelte/blob/master/LICENSE The MIT License (MIT) |
9
|
|
|
*/ |
10
|
|
|
namespace Noz\Collection; |
11
|
|
|
|
12
|
|
|
use InvalidArgumentException; |
13
|
|
|
|
14
|
|
|
use Countable; |
15
|
|
|
use Traversable; |
16
|
|
|
use SplDoublyLinkedList; |
17
|
|
|
|
18
|
|
|
use Noz\Contracts\Structure\Listable; |
19
|
|
|
use Noz\Contracts\Immutable; |
20
|
|
|
use Noz\Contracts\Arrayable; |
21
|
|
|
use Noz\Contracts\Invokable; |
22
|
|
|
|
23
|
|
|
use Noz\Traits\IsArrayable; |
24
|
|
|
use Noz\Traits\IsImmutable; |
25
|
|
|
|
26
|
|
|
use function |
27
|
|
|
Noz\to_array, |
28
|
|
|
Noz\is_traversable; |
29
|
|
|
|
30
|
|
|
class LList implements |
31
|
|
|
Listable, |
32
|
|
|
Immutable, |
33
|
|
|
Countable, |
34
|
|
|
Arrayable, |
35
|
|
|
Invokable |
36
|
|
|
{ |
37
|
|
|
use IsImmutable, IsArrayable; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var SplDoublyLinkedList |
41
|
|
|
*/ |
42
|
|
|
private $data; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* LList constructor. |
46
|
|
|
* |
47
|
|
|
* @param array|Traversable $data The list constructor |
48
|
|
|
*/ |
49
|
|
|
public function __construct($data) |
50
|
|
|
{ |
51
|
|
|
$this->setData($data); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Set internal data array. |
56
|
|
|
* |
57
|
|
|
* @param array|Traversable $data The list constructor |
58
|
|
|
*/ |
59
|
|
|
private function setData($data) |
60
|
|
|
{ |
61
|
|
|
if (!is_traversable($data)) { |
62
|
|
|
throw new InvalidArgumentException( |
63
|
|
|
'%s expects traversable data.', |
64
|
|
|
__CLASS__ |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
$dll = new SplDoublyLinkedList($data); |
|
|
|
|
68
|
|
|
$dll->setIteratorMode(SplDoublyLinkedList::IT_MODE_KEEP); |
69
|
|
|
foreach ($data as $key => $val) { |
70
|
|
|
$dll->push($val); |
71
|
|
|
} |
72
|
|
|
$this->data = $dll; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get internal data array. |
77
|
|
|
* |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
|
|
protected function getData() |
81
|
|
|
{ |
82
|
|
|
return to_array($this->data); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Invoke LList. |
87
|
|
|
* |
88
|
|
|
* This method is called when a LList object is invoked (called as if it were a function). |
89
|
|
|
* |
90
|
|
|
* @return mixed |
91
|
|
|
*/ |
92
|
|
|
public function __invoke() |
93
|
|
|
{ |
94
|
|
|
$list = new LList([ |
95
|
|
|
'abc','def','ghi','jkl','mno' |
96
|
|
|
]); |
97
|
|
|
$list(); // equivalent to pop() |
98
|
|
|
$list($val); // equivalent to push() |
|
|
|
|
99
|
|
|
$list($funk); // equivalent to |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Count elements of an object |
104
|
|
|
* @link http://php.net/manual/en/countable.count.php |
105
|
|
|
* @return int The custom count as an integer. |
|
|
|
|
106
|
|
|
* </p> |
107
|
|
|
* <p> |
108
|
|
|
* The return value is cast to an integer. |
109
|
|
|
* @since 5.1.0 |
110
|
|
|
*/ |
111
|
|
|
public function count() |
112
|
|
|
{ |
113
|
|
|
// TODO: Implement count() method. |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
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.