Completed
Push — master ( 1ea133...692929 )
by recca
07:00
created

Javascript::fill()   C

Complexity

Conditions 8
Paths 48

Size

Total Lines 31
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 8

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 22
cts 22
cp 1
rs 5.3846
c 0
b 0
f 0
cc 8
eloc 17
nc 48
nop 3
crap 8
1
<?php
2
3
namespace Recca0120\Lodash\JArray;
4
5
use Recca0120\Lodash\JString;
6
7
trait Javascript
8
{
9
    /**
10
     * The concat() method is used to merge two or more arrays.
11
     * This method does not change the existing arrays, but instead returns a new array.
12
     *
13
     * @return static
14
     */
15 4
    public function concat()
16
    {
17 4
        $array = $this->getArrayCopy();
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
18 4
        foreach (func_get_args() as $value) {
19 4
            $array = array_merge($array, (array) $value);
20 4
        }
21
22 4
        return new static($array);
1 ignored issue
show
Unused Code introduced by
The call to Javascript::__construct() has too many arguments starting with $array.

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...
23
    }
24
25
    /**
26
     * The copyWithin() method shallow copies part of an array to another location in the same array and returns it,
27
     * without modifying its size.
28
     *
29
     * @param int $target
30
     * @param int $start
31
     * @param int $end
32
     * @return static
33
     */
34
    public function copyWithin($target, $start, $end)
3 ignored issues
show
Unused Code introduced by
The parameter $target is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $start is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $end is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
35
    {
36
    }
37
38
    /**
39
     * The entries() method returns a new Array Iterator object that contains the key/value pairs for each index in the array.
40
     *
41
     * @return ArrayIterator
42
     */
43 3
    public function entries()
44
    {
45 3
        return $this->getIterator();
1 ignored issue
show
Bug introduced by
It seems like getIterator() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
46
    }
47
48
    /**
49
     * The every() method tests whether all elements in the array pass the test implemented by the provided function.
50
     *
51
     * @param callable $callback
52
     * @return bool
53
     */
54 1 View Code Duplication
    public function every(callable $callback)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56 1
        $array = $this->getArrayCopy();
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
57 1
        foreach ($array as $key => $value) {
58 1
            if ($callback($value, $key, $array) === false) {
59 1
                return false;
60
            }
61 1
        }
62
63 1
        return true;
64
    }
65
66
    /**
67
     * The fill() method fills all the elements of an array from a start index to an end index with a static value.
68
     *
69
     * @param  $value
70
     * @param  $start
71
     * @param  $end
72
     * @return static
73
     */
74 1
    public function fill($value, $start = null, $end = null)
75
    {
76 1
        $array = $this->getArrayCopy();
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
77 1
        $length = $this->length();
78
79 1
        if ($end <= 0) {
80 1
            $end = $length - $end;
81 1
        }
82
83 1
        if (is_null($start) === true) {
84 1
            $i = $end ?: $length;
85
86 1
            while ($i--) {
87 1
                $array[$i] = $value;
88 1
            }
89 1
        }
90
91 1
        if ($start <= 0) {
92 1
            $start = $length - $start;
93 1
        }
94
95 1
        $end = $end ?: $length;
96 1
        $i = $start;
97
98 1
        while ($i !== $end) {
99 1
            $array[$i] = $value;
100 1
            ++$i;
101 1
        }
102
103 1
        return new static($array);
1 ignored issue
show
Unused Code introduced by
The call to Javascript::__construct() has too many arguments starting with $array.

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...
104
    }
105
106
    /**
107
     * The filter() method creates a new array with all elements that pass the test implemented by the provided function.
108
     *
109
     * @param callable $callback
110
     * @return static
111
     */
112 1
    public function filter(callable $callback)
113
    {
114 1
        return new static(array_filter($this->getArrayCopy(), $callback));
2 ignored issues
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Unused Code introduced by
The call to Javascript::__construct() has too many arguments starting with array_filter($this->getArrayCopy(), $callback).

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...
115
    }
116
117
    /**
118
     * The find() method returns a value of the first element in the array that satisfies the provided testing function. Otherwise undefined is returned.
119
     *
120
     * @param callable $callback
121
     * @return mix
122
     */
123 1 View Code Duplication
    public function find(callable $callback)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
124
    {
125 1
        $array = $this->getArrayCopy();
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
126 1
        foreach ($array as $key => $value) {
127 1
            if ($callback($value, $key, $array) === true) {
128 1
                return $value;
129
            }
130 1
        }
131
    }
132
133
    /**
134
     * The findIndex() method returns an index of the first element in the array that satisfies the provided testing function.
135
     * Otherwise -1 is returned.
136
     *
137
     * @param callable $callback
138
     * @return int|string
139
     */
140 1 View Code Duplication
    public function findIndex(callable $callback)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
141
    {
142 1
        $array = $this->getArrayCopy();
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
143 1
        foreach ($array as $key => $value) {
144 1
            if ($callback($value, $key, $array) === true) {
145 1
                return $key;
146
            }
147 1
        }
148
149 1
        return -1;
150
    }
151
152
    /**
153
     * The forEach() method executes a provided function once for each array element.
154
     * php < 7 not allow forEach.
155
     *
156
     * @param callable $callback
157
     */
158 1
    public function each(callable $callback)
159
    {
160 1
        $array = $this->getArrayCopy();
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
161 1
        foreach ($array as $key => $value) {
162 1
            $callback($value, $key, $array);
163 1
        }
164 1
    }
165
166
    /**
167
     * The includes() method determines whether an array includes a certain element, returning true or false as appropriate.
168
     *
169
     * @param mixed $searchElement
170
     * @param int $fromIndex
171
     * @return bool
172
     */
173 1
    public function includes($searchElement, $fromIndex = 0)
174
    {
175 1
        return in_array($searchElement, $this->slice($fromIndex)->getArrayCopy(), true);
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
176
    }
177
178
    /**
179
     * The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.
180
     *
181
     * @param mixed $searchElement
182
     * @param int $fromIndex
183
     * @return int|string
184
     */
185 1 View Code Duplication
    public function indexOf($searchElement, $fromIndex = 0)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
186
    {
187 1
        $result = array_search($searchElement, $this->getArrayCopy(), true);
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
188
189 1
        return $result === false ? -1 : $result + $fromIndex;
190
191
        // if ($fromIndex < 0) {
1 ignored issue
show
Unused Code Comprehensibility introduced by
50% 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...
192
        //     $fromIndex = $this->length() + $fromIndex;
1 ignored issue
show
Unused Code Comprehensibility introduced by
47% 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...
193
        // }
194
        // $result = array_search($searchElement, $this->slice($fromIndex)->getArrayCopy(), true);
1 ignored issue
show
Unused Code Comprehensibility introduced by
64% 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...
195
196
        // return $result === false ? -1 : $result + $fromIndex;
1 ignored issue
show
Unused Code Comprehensibility introduced by
41% 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...
197
    }
198
199
    /**
200
     * The join() method joins all elements of an array into a string.
201
     *
202
     * @param string $separator
203
     * @return \Recca0120\Lodash\Str;
0 ignored issues
show
Documentation introduced by
The doc-type \Recca0120\Lodash\Str; could not be parsed: Expected "|" or "end of type", but got ";" at position 21. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
204
     */
205 4
    public function join($separator = ',')
206
    {
207 4
        return new JString(implode($separator, $this->getArrayCopy()));
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
208
    }
209
210
    /**
211
     * The keys() method returns a new Array Iterator that contains the keys for each index in the array.
212
     *
213
     * @return \ArrayIterator
214
     */
215 1
    public function keys()
216
    {
217 1
        return (new static(array_keys($this->getArrayCopy())))->entries();
2 ignored issues
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Unused Code introduced by
The call to Javascript::__construct() has too many arguments starting with array_keys($this->getArrayCopy()).

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...
218
    }
219
220
    /**
221
     * The lastIndexOf() method returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards, starting at fromIndex.
222
     *
223
     * @param mixed $searchElement
224
     * @param int $fromIndex
225
     * @return int|string
226
     */
227 1 View Code Duplication
    public function lastIndexOf($searchElement, $fromIndex = 0)
2 ignored issues
show
Unused Code introduced by
The parameter $fromIndex is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
228
    {
229 1
        $result = array_search($searchElement, array_reverse($this->getArrayCopy(), true));
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
230
231 1
        return $result === false ? -1 : $result;
232
        // $result = array_search($searchElement, array_reverse($this->slice($fromIndex)->getArrayCopy(), true));
1 ignored issue
show
Unused Code Comprehensibility introduced by
65% 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...
233
234
        // return ($result === false) ? -1 : $result + $fromIndex;
1 ignored issue
show
Unused Code Comprehensibility introduced by
46% 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...
235
    }
236
237
    /**
238
     * The map() method creates a new array with the results of calling a provided function on every element in this array.
239
     *
240
     * @param callable $callback
241
     * @return static
242
     */
243 2
    public function map(callable $callback)
244
    {
245 2
        return new static(array_map($callback, $this->getArrayCopy()));
2 ignored issues
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Unused Code introduced by
The call to Javascript::__construct() has too many arguments starting with array_map($callback, $this->getArrayCopy()).

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...
246
    }
247
248
    /**
249
     * The pop() method removes the last element from an array and returns that element. This method changes the length of the array.
250
     *
251
     * @return static
252
     */
253 1
    public function pop()
254
    {
255 1
        $array = $this->getArrayCopy();
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
256 1
        $pop = array_pop($array);
257 1
        $this->exchangeArray($array);
1 ignored issue
show
Bug introduced by
It seems like exchangeArray() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
258
259 1
        return $pop;
260
    }
261
262
    /**
263
     * The push() method adds one or more elements to the end of an array and returns the new length of the array.
264
     *
265
     * @return int
266
     */
267 1
    public function push()
268
    {
269 1
        $array = $this->getArrayCopy();
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
270 1
        foreach (func_get_args() as $parameter) {
271 1
            array_push($array, $parameter);
272 1
        }
273 1
        $this->exchangeArray($array);
1 ignored issue
show
Bug introduced by
It seems like exchangeArray() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
274
275 1
        return $this->count();
1 ignored issue
show
Bug introduced by
It seems like count() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
276
    }
277
278
    /**
279
     * The reduce() method applies a function against an accumulator and each value of the array (from left-to-right) to reduce it to a single value.
280
     *
281
     * @param callable $callback
282
     * @param mixed $initialValue
283
     * @return mixed
284
     */
285 2
    public function reduce(callable $callback, $initialValue = null)
286
    {
287 2
        return array_reduce($this->getArrayCopy(), $callback, $initialValue);
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
288
    }
289
290
    /**
291
     * The reduceRight() method applies a function against an accumulator and each value of the array (from right-to-left) has to reduce it to a single value.
292
     *
293
     * @param callable $callback
294
     * @param mixed $initialValue
295
     * @return mixed
296
     */
297 1
    public function reduceRight(callable $callback, $initialValue = null)
298
    {
299 1
        return $this->reverse(true)->reduce($callback, $initialValue);
300
    }
301
302
    /**
303
     * The reverse() method reverses an array in place. The first array element becomes the last, and the last array element becomes the first.
304
     *
305
     * @param bool $preservekeys
306
     * @return static
307
     */
308 2
    public function reverse($preservekeys = false)
309
    {
310 2
        $array = $this->getArrayCopy();
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
311 2
        $array = array_reverse($array, $preservekeys);
312 2
        $this->exchangeArray($array);
1 ignored issue
show
Bug introduced by
It seems like exchangeArray() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
313
314 2
        return new static($array);
1 ignored issue
show
Unused Code introduced by
The call to Javascript::__construct() has too many arguments starting with $array.

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...
315
    }
316
317
    /**
318
     * The shift() method removes the first element from an array and returns that element. This method changes the length of the array.
319
     *
320
     * @return mix
321
     */
322 1
    public function shift()
323
    {
324 1
        $array = $this->getArrayCopy();
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
325 1
        $result = array_shift($array);
326 1
        $this->exchangeArray($array);
1 ignored issue
show
Bug introduced by
It seems like exchangeArray() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
327
328 1
        return $result;
329
    }
330
331
    /**
332
     * The slice() method returns a shallow copy of a portion of an array
333
     * into a new array object selected from begin to end (end not included). The original array will not be modified.
334
     *
335
     * @param int $begin
336
     * @param int $end
337
     * @return static
338
     */
339 2
    public function slice($begin, $end = null)
340
    {
341 2
        $array = $this->getArrayCopy();
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
342 2
        $length = $this->length();
343 2
        $begin = $begin < 0 ? $length + $begin : $begin;
344
345 2
        if (is_null($end) === true) {
346 1
            return new static(array_slice($array, $begin, $length - $begin));
1 ignored issue
show
Unused Code introduced by
The call to Javascript::__construct() has too many arguments starting with array_slice($array, $begin, $length - $begin).

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...
347
        }
348
349 1
        $end = $end < 0 ? $length + $end : $end;
350 1
        $end -= $begin;
351
352 1
        return new static(array_slice($array, $begin, $end));
1 ignored issue
show
Unused Code introduced by
The call to Javascript::__construct() has too many arguments starting with array_slice($array, $begin, $end).

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...
353
    }
354
355
    /**
356
     * The some() method tests whether some element in the array passes the test implemented by the provided function.
357
     *
358
     * @param callable $callback
359
     * @return bool
360
     */
361 1 View Code Duplication
    public function some(callable $callback)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
362
    {
363 1
        $array = $this->getArrayCopy();
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
364 1
        foreach ($array as $key => $value) {
365 1
            if ($callback($value, $key, $array) === true) {
366 1
                return true;
367
            }
368 1
        }
369
370 1
        return false;
371
    }
372
373
    /**
374
     * The sort() method sorts the elements of an array in place and returns the array. The sort is not necessarily stable. The default sort order is according to string Unicode code points.
375
     *
376
     * @param  callable|null $compareFunction
377
     * @return static
378
     */
379 1
    public function sort(callable $compareFunction = null)
380
    {
381 1
        if (is_null($compareFunction) === true) {
382 1
            $compareFunction = function ($a, $b) {
383 1
                return $a > $b;
384 1
            };
385 1
        }
386 1
        $array = $this->getArrayCopy();
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
387 1
        usort($array, $compareFunction);
388 1
        $this->exchangeArray($array);
1 ignored issue
show
Bug introduced by
It seems like exchangeArray() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
389
390 1
        return $this;
391
    }
392
393
    /**
394
     * The splice() method changes the content of an array by removing existing elements and/or adding new elements.
395
     *
396
     * @return static
397
     */
398 1 View Code Duplication
    public function splice()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
399
    {
400 1
        $array = $this->getArrayCopy();
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
401 1
        call_user_func_array('array_splice', array_merge([&$array], func_get_args()));
402 1
        $this->exchangeArray($array);
1 ignored issue
show
Bug introduced by
It seems like exchangeArray() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
403
404 1
        return $this;
405
    }
406
407
    public function toLocaleString()
408
    {
409
    }
410
411
    /**
412
     * The toString() method returns a string representing the specified array and its elements.
413
     *
414
     * @return string
415
     */
416 1
    public function toString()
417
    {
418 1
        return (string) $this->join(',');
419
    }
420
421
    /**
422
     * The toString() method returns a string representing the specified array and its elements.
423
     *
424
     * @return string
425
     */
426 1
    public function __toString()
427
    {
428 1
        return $this->toString();
429
    }
430
431
    /**
432
     * The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.
433
     *
434
     * @return static
435
     */
436 1 View Code Duplication
    public function unshift()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
437
    {
438 1
        $array = $this->getArrayCopy();
1 ignored issue
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
439 1
        call_user_func_array('array_unshift', array_merge([&$array], func_get_args()));
440 1
        $this->exchangeArray($array);
1 ignored issue
show
Bug introduced by
It seems like exchangeArray() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
441
442 1
        return $this;
443
    }
444
445
    /**
446
     * The values() method returns a new Array Iterator object that contains the values for each index in the array.
447
     *
448
     * @return \ArrayIterator
449
     */
450 1
    public function values()
451
    {
452 1
        return (new static(array_values($this->getArrayCopy())))->entries();
2 ignored issues
show
Bug introduced by
It seems like getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Unused Code introduced by
The call to Javascript::__construct() has too many arguments starting with array_values($this->getArrayCopy()).

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...
453
    }
454
455
    /**
456
     * length.
457
     *
458
     * @return int
459
     */
460 3
    public function length()
461
    {
462 3
        return $this->count();
1 ignored issue
show
Bug introduced by
It seems like count() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
463
    }
464
}
465