Completed
Pull Request — master (#49)
by Luke
10:01 queued 06:50
created

LList::setData()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
nc 3
nop 1
dl 0
loc 15
ccs 0
cts 0
cp 0
crap 12
rs 9.4285
c 1
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 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
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: append, bottom, bump, contains, drop, every, isEmpty, none, pipe, prepend, serialize, top, unserialize
Loading history...
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);
0 ignored issues
show
Unused Code introduced by
The call to SplDoublyLinkedList::__construct() has too many arguments starting with $data.

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...
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
95
    }
96
97
    /**
98
     * Count elements of an object
99
     * @link  http://php.net/manual/en/countable.count.php
100
     * @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...
101
     * </p>
102
     * <p>
103
     * The return value is cast to an integer.
104
     * @since 5.1.0
105
     */
106
    public function count()
107
    {
108
        // TODO: Implement count() method.
109
    }
110
111
}
112