|
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 BadMethodCallException; |
|
13
|
|
|
|
|
14
|
|
|
use Countable; |
|
15
|
|
|
use Noz\Contracts\Structure\Listable; |
|
16
|
|
|
use Traversable; |
|
17
|
|
|
use SplDoublyLinkedList; |
|
18
|
|
|
|
|
19
|
|
|
use Noz\Contracts\Structure\Sequenceable; |
|
20
|
|
|
use Noz\Contracts\Immutable; |
|
21
|
|
|
use Noz\Contracts\Arrayable; |
|
22
|
|
|
use Noz\Contracts\Invokable; |
|
23
|
|
|
|
|
24
|
|
|
use Noz\Traits\IsImmutable; |
|
25
|
|
|
|
|
26
|
|
|
use function Noz\to_array; |
|
27
|
|
|
use function Noz\is_traversable; |
|
28
|
|
|
|
|
29
|
|
|
class Lst implements |
|
30
|
|
|
Listable, |
|
31
|
|
|
Immutable, |
|
32
|
|
|
Countable, |
|
33
|
|
|
Arrayable, |
|
34
|
|
|
Invokable |
|
35
|
|
|
{ |
|
36
|
|
|
use IsImmutable; |
|
37
|
|
|
|
|
38
|
|
|
private $data; |
|
39
|
|
|
|
|
40
|
|
|
public function __construct($data) |
|
41
|
|
|
{ |
|
42
|
|
|
$data = array_values(to_array($data)); |
|
43
|
|
|
$this->data = new SplDoublyLinkedList(); |
|
44
|
|
|
$this->data->setIteratorMode(SplDoublyLinkedList::IT_MODE_KEEP); |
|
45
|
|
|
foreach ($data as $key => $val) { |
|
46
|
|
|
$this->data->add($key, $val); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* To array. |
|
52
|
|
|
* |
|
53
|
|
|
* @return array |
|
54
|
|
|
*/ |
|
55
|
|
|
public function toArray() |
|
56
|
|
|
{ |
|
57
|
|
|
return to_array($this->data); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Invoke set. |
|
62
|
|
|
* |
|
63
|
|
|
* @return mixed |
|
64
|
|
|
*/ |
|
65
|
|
|
public function __invoke() |
|
66
|
|
|
{ |
|
67
|
|
|
// TODO: Implement __invoke() method. |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Count elements of an object |
|
72
|
|
|
* @link http://php.net/manual/en/countable.count.php |
|
73
|
|
|
* @return int The custom count as an integer. |
|
|
|
|
|
|
74
|
|
|
* </p> |
|
75
|
|
|
* <p> |
|
76
|
|
|
* The return value is cast to an integer. |
|
77
|
|
|
* @since 5.1.0 |
|
78
|
|
|
*/ |
|
79
|
|
|
public function count() |
|
80
|
|
|
{ |
|
81
|
|
|
// TODO: Implement count() method. |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
} |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.