Completed
Pull Request — master (#49)
by Luke
06:27 queued 04:14
created

Lst::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 9
ccs 0
cts 9
cp 0
crap 6
rs 9.6666
c 0
b 0
f 0
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.
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|null?

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...
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
}