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

Sequence   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 195
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 195
ccs 0
cts 65
cp 0
rs 10
c 0
b 0
f 0
wmc 19
lcom 1
cbo 1

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setData() 0 16 2
A getData() 0 4 1
A count() 0 4 1
A toArray() 0 4 1
A __invoke() 0 4 1
A prepend() 0 4 1
A append() 0 4 1
A contains() 0 4 1
A isEmpty() 0 4 1
A pipe() 0 4 1
A every() 0 4 1
A none() 0 4 1
A toSeq() 0 4 1
A toDict() 0 4 1
A toSet() 0 4 1
A toMap() 0 4 1
A toList() 0 4 1
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 Traversable;
16
use SplFixedArray;
17
18
use Noz\Contracts\Structure\Sequenceable;
19
use Noz\Contracts\Immutable;
20
use Noz\Contracts\Arrayable;
21
use Noz\Contracts\Invokable;
22
23
use Noz\Traits\IsImmutable;
24
25
use function Noz\to_array;
26
use function Noz\is_traversable;
27
28
class Sequence implements
29
    Sequenceable,
30
    Immutable,
31
    Countable,
32
    Arrayable,
33
    Invokable
34
{
35
    use IsImmutable;
36
37
    /**
38
     * Fixed-size data storage array.
39
     *
40
     * @var SplFixedArray
41
     */
42
    private $data;
43
44
    /**
45
     * Sequence constructor.
46
     *
47
     * @param array|Traversable $data The data to sequence
48
     */
49
    public function __construct($data)
50
    {
51
        $this->setData($data);
52
    }
53
54
    private function setData($data)
55
    {
56
        if (!is_traversable($data)) {
57
            // @todo Maybe create an ImmutableException for this?
58
            throw new BadMethodCallException(sprintf(
59
                'Cannot %s, %s is immutable.',
60
                __METHOD__,
61
                __CLASS__
62
            ));
63
        }
64
        $data = array_values(to_array($data));
65
        $this->data = SplFixedArray::fromArray($data);
66
//        $size = count($data);
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
67
//        $this->data = new SplFixedArray($size);
68
69
    }
70
71
    protected function getData()
72
    {
73
        return $this->data->toArray();
74
    }
75
76
    /**
77
     * Count elements of an object
78
     * @link  http://php.net/manual/en/countable.count.php
79
     * @return int The custom count as an integer.
80
     * </p>
81
     * <p>
82
     * The return value is cast to an integer.
83
     * @since 5.1.0
84
     */
85
    public function count()
86
    {
87
        return $this->data->count();
88
    }
89
90
    public function toArray()
91
    {
92
        return $this->getData();
93
    }
94
95
    public function __invoke()
96
    {
97
        return $this->toArray();
98
    }
99
100
    /**
101
     * Prepend item to collection.
102
     * Prepend an item to this collection (in place).
103
     * @param mixed $item Item to prepend to collection
0 ignored issues
show
Documentation introduced by
Should the return type not be Sequence|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...
104
     * @return $this
105
     */public function prepend($item)
106
{
107
    // TODO: Implement prepend() method.
108
}
109
110
    /**
111
     * Append item to collection.
112
     * Append an item to this collection (in place).
113
     * @param mixed $item Item to append to collection
114
     * @return $this
0 ignored issues
show
Documentation introduced by
Should the return type not be Sequence|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...
115
     */
116
    public function append($item)
117
    {
118
        // TODO: Implement append() method.
119
    }
120
121
    /**
122
     * Check that collection contains a value.
123
     * You may optionally pass in a callable to provide your own equality test.
124
     * @param mixed|callable $value The value to search for
125
     * @return mixed
126
     */
127
    public function contains($value)
128
    {
129
        // TODO: Implement contains() method.
130
    }
131
132
    /**
133
     * Is collection empty?
134
     * You may optionally pass in a callback which will determine if each of the items within the collection are empty.
135
     * If all items in the collection are empty according to this callback, this method will return true.
136
     * @param callable $callback The callback
0 ignored issues
show
Documentation introduced by
Should the type for parameter $callback not be null|callable? Also, consider making the array more specific, something like array<String>, or String[].

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type array and suggests a stricter type like array<String>.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
137
     * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|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...
138
     */
139
    public function isEmpty(callable $callback = null)
140
    {
141
        // TODO: Implement isEmpty() method.
142
    }
143
144
    /**
145
     * Pipe collection through callback.
146
     * Passes entire collection to provided callback and returns the result.
147
     * @param callable $callback
148
     * @return mixed
149
     */
150
    public function pipe(callable $callback)
151
    {
152
        // TODO: Implement pipe() method.
153
    }
154
155
    /**
156
     * Does every item return true?
157
     * If callback is provided, this method will return true if all items in collection cause callback to return true.
158
     * Otherwise, it will return true if all items in the collection have a truthy value.
159
     * @param callable|null $callback The callback
160
     * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|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...
161
     */
162
    public function every(callable $callback = null)
163
    {
164
        // TODO: Implement every() method.
165
    }
166
167
    /**
168
     * Does every item return false?
169
     * This method is the exact opposite of "all".
170
     * @param callable|null $callback The callback
171
     * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|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...
172
     */
173
    public function none(callable $callback = null)
174
    {
175
        // TODO: Implement none() method.
176
    }
177
178
    /**
179
     * Get collection as a sequence.
180
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null? 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...
181
     */
182
    public function toSeq()
183
    {
184
        // TODO: Implement toSeq() method.
185
    }
186
187
    /**
188
     * Get collection as a dictionary.
189
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null? 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...
190
     */
191
    public function toDict()
192
    {
193
        // TODO: Implement toDict() method.
194
    }
195
196
    /**
197
     * Get collection as a set.
198
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null? 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...
199
     */
200
    public function toSet()
201
    {
202
        // TODO: Implement toSet() method.
203
    }
204
205
    /**
206
     * Get collection as a map.
207
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null? 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...
208
     */
209
    public function toMap()
210
    {
211
        // TODO: Implement toMap() method.
212
    }
213
214
    /**
215
     * Get collection as a list.
216
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null? 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...
217
     */
218
    public function toList()
219
    {
220
        // TODO: Implement toList() method.
221
    }
222
}