Passed
Pull Request — master (#64)
by
unknown
02:49
created

Extension::getGlobals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 10
ccs 4
cts 4
cp 1
crap 1
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Zicht Online <http://zicht.nl>
4
 */
5
6
namespace Zicht\Itertools\twig;
7
8
use Twig\Extension\GlobalsInterface;
9
use Zicht\Itertools;
10
11
/**
12
 * Twig extension.
13
 */
14
class Extension extends \Twig_Extension implements GlobalsInterface
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Extension has been deprecated with message: since Twig 2.7, use "Twig\Extension\AbstractExtension" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
15
{
16
    /**
17
     * {@inheritDoc}
18
     */
19 1
    public function getGlobals()
20
    {
21
        return [
22
            'it' => (object)[
23 1
                'filters' => new Itertools\util\Filters(),
24 1
                'mappings' => new Itertools\util\Mappings(),
25 1
                'reductions' => new Itertools\util\Reductions(),
26
            ],
27
        ];
28
    }
29
30
    /**
31
     * {@inheritDoc}
32
     */
33 1
    public function getFilters()
34
    {
35
        return [
36 1
            new \Twig_SimpleFilter('it', [$this, 'it']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
37
38
            // deprecated filters (because 'it' was introduced)
39 1
            new \Twig_SimpleFilter('all', '\Zicht\Itertools\all', ['deprecated' => true, 'alternative' => '|it.all']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
40 1
            new \Twig_SimpleFilter('any', '\Zicht\Itertools\any', ['deprecated' => true, 'alternative' => '|it.any']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
41 1
            new \Twig_SimpleFilter('chain', '\Zicht\Itertools\chain', ['deprecated' => true, 'alternative' => '|it.chain']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
42 1
            new \Twig_SimpleFilter('collapse', '\Zicht\Itertools\collapse', ['deprecated' => true, 'alternative' => '|it.collapse']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
43 1
            new \Twig_SimpleFilter('filter', [$this, 'filter'], ['deprecated' => true, 'alternative' => '|it.filter']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
44 1
            new \Twig_SimpleFilter('first', '\Zicht\Itertools\first', ['deprecated' => true, 'alternative' => '|it.first']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
45 1
            new \Twig_SimpleFilter('group_by', [$this, 'groupBy'], ['deprecated' => true, 'alternative' => '|it.groupBy']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
46 1
            new \Twig_SimpleFilter('last', '\Zicht\Itertools\last', ['deprecated' => true, 'alternative' => '|it.last']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
47 1
            new \Twig_SimpleFilter('map', [$this, 'map'], ['deprecated' => true, 'alternative' => '|it.map']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
48 1
            new \Twig_SimpleFilter('map_by', [$this, 'mapBy'], ['deprecated' => true, 'alternative' => '|it.mapBy']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
49 1
            new \Twig_SimpleFilter('reduce', '\Zicht\Itertools\reduce', ['deprecated' => true, 'alternative' => '|it.reduce']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
50 1
            new \Twig_SimpleFilter('reversed', '\Zicht\Itertools\reversed', ['deprecated' => true, 'alternative' => '|it.reversed']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
51 1
            new \Twig_SimpleFilter('sorted', [$this, 'sorted'], ['deprecated' => true, 'alternative' => '|it.sorted']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
52 1
            new \Twig_SimpleFilter('unique', [$this, 'unique'], ['deprecated' => true, 'alternative' => '|it.unique']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
53 1
            new \Twig_SimpleFilter('zip', '\Zicht\Itertools\zip', ['deprecated' => true, 'alternative' => '|it.zip']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
54
55
            // deprecated filters
56 1
            new \Twig_SimpleFilter('filterby', [$this, 'deprecatedFilterBy'], ['deprecated' => true, 'alternative' => '|it.filter']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
57 1
            new \Twig_SimpleFilter('groupBy', [$this, 'deprecatedGroupBy'], ['deprecated' => true, 'alternative' => '|it.groupBy']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
58 1
            new \Twig_SimpleFilter('groupby', [$this, 'deprecatedGroupBy'], ['deprecated' => true, 'alternative' => '|it.groupBy']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
59 1
            new \Twig_SimpleFilter('mapBy', [$this, 'deprecatedMapBy'], ['deprecated' => true, 'alternative' => '|it.mapBy']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
60 1
            new \Twig_SimpleFilter('mapby', [$this, 'deprecatedMapBy'], ['deprecated' => true, 'alternative' => '|it.mapBy']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
61 1
            new \Twig_SimpleFilter('sum', [$this, 'deprecatedSum'], ['deprecated' => true, 'alternative' => '|it.reduce']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
62 1
            new \Twig_SimpleFilter('uniqueby', [$this, 'deprecatedUniqueBy'], ['deprecated' => true, 'alternative' => '|it.unique']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
63
        ];
64
    }
65
66
    /**
67
     * {@inheritDoc}
68
     */
69 1
    public function getFunctions()
70
    {
71
        return [
72 1
            new \Twig_SimpleFunction('it', [$this, 'it']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
73
74
            // deprecated functions (because 'it' was introduced)
75 1
            new \Twig_SimpleFunction('chain', '\Zicht\Itertools\chain', ['deprecated' => true, 'alternative' => '|it.chain']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
76 1
            new \Twig_SimpleFunction('first', '\Zicht\Itertools\first', ['deprecated' => true, 'alternative' => '|it.first']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
77 1
            new \Twig_SimpleFunction('last', '\Zicht\Itertools\last', ['deprecated' => true, 'alternative' => '|it.last']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
78
79
            // deprecated functions (because 'it' was introduced)
80 1
            new \Twig_SimpleFunction('reducing', [$this, 'reducing'], ['deprecated' => true, 'alternative' => 'it.reductions']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
81 1
            new \Twig_SimpleFunction('mapping', [$this, 'mapping'], ['deprecated' => true, 'alternative' => 'it.mappings']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
82 1
            new \Twig_SimpleFunction('filtering', [$this, 'filtering'], ['deprecated' => true, 'alternative' => 'it.filters']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
83
84
            // deprecated functions
85 1
            new \Twig_SimpleFunction('reduction', [$this, 'deprecatedGetReduction'], ['deprecated' => true, 'alternative' => 'reducing']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
86
        ];
87
    }
88
89
    /**
90
     * Takes an iterable and returns an object that allow mapping, sorting, etc.
91
     *
92
     * @param $iterable
93
     * @return Itertools\lib\Interfaces\FiniteIterableInterface|Itertools\lib\IterableIterator
94
     */
95 1
    public function it($iterable)
96
    {
97 1
        return Itertools\iterable($iterable);
98
    }
99
100
    /**
101
     * Takes an iterable and returns another iterable that is unique.
102
     *
103
     * @param array|string|\Iterator $iterable
104
     * @param mixed $strategy
105
     * @return Itertools\lib\UniqueIterator
106
     * @deprecated
107
     */
108
    public function unique($iterable, $strategy = null)
109
    {
110
        return Itertools\unique($strategy, $iterable);
0 ignored issues
show
Deprecated Code introduced by
The function Zicht\Itertools\unique() has been deprecated with message: Use iterable($iterable)->unique($strategy), will be removed in version 3.0

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
111
    }
112
113
    /**
114
     * Reduce an iterable to a single value
115
     *
116
     * Simple examples:
117
     * {{ [1,2,3]|reduce }} --> 6
118
     * {{ [1,2,3]|reduce('max') }} --> 3
119
     *
120
     * Sro example to get the prices for all items in the basket:
121
     * {{ transaction_snapshot.Basket.Items|map('TotalPrice.Amount')|reduce }}
122
     *
123
     * @param array|string|\Iterator $iterable
124
     * @param string|\Closure $closure
125
     * @param mixed $initializer
126
     * @return mixed
127
     * @deprecated
128
     */
129
    public function reduce($iterable, $closure = 'add', $initializer = null)
130
    {
131
        return Itertools\reduce($iterable, $closure, $initializer);
0 ignored issues
show
Deprecated Code introduced by
The function Zicht\Itertools\reduce() has been deprecated with message: Use iterable($iterable)->reduce($closure, $initializer), will be removed in version 3.0

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
132
    }
133
134
    /**
135
     * Make an iterator that returns consecutive groups from the
136
     * $iterable.  Generally, the $iterable needs to already be sorted on
137
     * the same key function.
138
     *
139
     * @param array|string|\Iterator $iterable
140
     * @param string|\Closure $strategy
141
     * @param boolean $sort
142
     * @return Itertools\lib\GroupbyIterator
143
     * @deprecated
144
     */
145
    public function groupBy($iterable, $strategy, $sort = true)
146
    {
147
        return Itertools\group_by($strategy, $iterable, $sort);
0 ignored issues
show
Deprecated Code introduced by
The function Zicht\Itertools\group_by() has been deprecated with message: Use iterable($iterable)->groupBy($strategy, $sort), will be removed in version 3.0

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
148
    }
149
150
    /**
151
     * Make an iterator that returns values from $iterable where the
152
     * $strategy determines that the values are not empty.
153
     *
154
     * @param array|string|\Iterator $iterable
155
     * @param null $strategy
156
     * @return Itertools\lib\FilterIterator
157
     * @deprecated
158
     */
159
    public function filter($iterable, $strategy = null)
160
    {
161
        return Itertools\filter($strategy, $iterable);
0 ignored issues
show
Deprecated Code introduced by
The function Zicht\Itertools\filter() has been deprecated with message: Use iterable($iterable)->filter($strategy), will be removed in version 3.0

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
162
    }
163
164
    /**
165
     * Make an iterator that returns the values from $iterable sorted by
166
     * $strategy.
167
     *
168
     * @param array|string|\Iterator $iterable
169
     * @param string|\Closure $strategy
170
     * @param bool $reverse
171
     * @return Itertools\lib\SortedIterator
172
     * @deprecated
173
     */
174
    public function sorted($iterable, $strategy = null, $reverse = false)
175
    {
176
        return Itertools\sorted($strategy, $iterable, $reverse);
0 ignored issues
show
Deprecated Code introduced by
The function Zicht\Itertools\sorted() has been deprecated with message: Use iterable($iterable)->sorted($strategy, $reverse), will be removed in version 3.0

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
177
    }
178
179
    /**
180
     * Make an iterator that applies $func to every entry in the $iterables.
181
     *
182
     * @param array|string|\Iterator $iterable
183
     * @param string|\Closure $strategy
184
     * @return Itertools\lib\MapIterator
185
     * @deprecated
186
     */
187
    public function map($iterable, $strategy)
188
    {
189
        return Itertools\map($strategy, $iterable);
0 ignored issues
show
Deprecated Code introduced by
The function Zicht\Itertools\map() has been deprecated with message: Use iterable($iterable)->map($strategy, [$iterable2, ...]), will be removed in version 3.0

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
190
    }
191
192
    /**
193
     * Make an iterator returning values from $iterable and keys from
194
     * $strategy.
195
     *
196
     * @param array|string|\Iterator $iterable
197
     * @param string|\Closure $strategy
198
     * @return Itertools\lib\MapByIterator
199
     * @deprecated
200
     */
201
    public function mapBy($iterable, $strategy)
202
    {
203
        return Itertools\map_by($strategy, $iterable);
0 ignored issues
show
Deprecated Code introduced by
The function Zicht\Itertools\map_by() has been deprecated with message: Use iterable($iterable)->mapBy($strategy), will be removed in version 3.0

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
204
    }
205
206
207
    /**
208
     * Returns a reduction closure
209
     *
210
     * Any parameters provided, beyond $name, are passed directly to the underlying
211
     * reduction.  This can be used to, for example, provide a $glue when using join.
212
     *
213
     * @param string $name
214
     * @return \Closure
215
     * @throws \InvalidArgumentException
216
     */
217 4 View Code Duplication
    public function reducing($name)
0 ignored issues
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...
218
    {
219
        // note, once we stop supporting php 5.5, we can rewrite the code below
220
        // to the reducing($name, ...$args) structure.
221
        // http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list
222 4
        $method = sprintf('\Zicht\Itertools\util\Reductions::%s', $name);
223 4
        if (!is_callable($method)) {
224 2
            throw new \InvalidArgumentException(sprintf('$name "%s" is not a valid reduction.', $name));
225
        }
226 2
        return call_user_func_array($method, array_slice(func_get_args(), 1));
227
    }
228
229
    /**
230
     * Returns a mapping closure
231
     *
232
     * Any parameters provided, beyond $name, are passed directly to the underlying
233
     * mapping.  This can be used to, for example, provide a $glue when using join.
234
     *
235
     * @param string $name
236
     * @return \Closure
237
     * @throws \InvalidArgumentException
238
     */
239 2 View Code Duplication
    public function mapping($name)
0 ignored issues
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...
240
    {
241
        // note, once we stop supporting php 5.5, we can rewrite the code below
242
        // to the reducing($name, ...$args) structure.
243
        // http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list
244 2
        $method = sprintf('\Zicht\Itertools\util\Mappings::%s', $name);
245 2
        if (!is_callable($method)) {
246 1
            throw new \InvalidArgumentException(sprintf('$name "%s" is not a valid mapping.', $name));
247
        }
248 1
        return call_user_func_array($method, array_slice(func_get_args(), 1));
249
    }
250
251
    /**
252
     * Returns a filter closure
253
     *
254
     * Any parameters provided, beyond $name, are passed directly to the underlying
255
     * filter.  This can be used to, for example, provide a $glue when using join.
256
     *
257
     * @param string $name
258
     * @return \Closure
259
     * @throws \InvalidArgumentException
260
     */
261 2 View Code Duplication
    public function filtering($name)
0 ignored issues
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...
262
    {
263
        // note, once we stop supporting php 5.5, we can rewrite the code below
264
        // to the reducing($name, ...$args) structure.
265
        // http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list
266 2
        $method = sprintf('\Zicht\Itertools\util\Filters::%s', $name);
267 2
        if (!is_callable($method)) {
268 1
            throw new \InvalidArgumentException(sprintf('$name "%s" is not a valid filter.', $name));
269
        }
270 1
        return call_user_func_array($method, array_slice(func_get_args(), 1));
271
    }
272
273
    /**
274
     * Make an iterator that returns values from $iterable where the
275
     * $strategy determines that the values are not empty.
276
     *
277
     * @param array|string|\Iterator $iterable
278
     * @param string|\Closure $strategy
279
     * @return Itertools\lib\FilterIterator
280
     * @deprecated Use filter instead!
281
     */
282
    public function deprecatedFilterBy($iterable, $strategy)
283
    {
284
        return Itertools\filter($strategy, $iterable);
0 ignored issues
show
Deprecated Code introduced by
The function Zicht\Itertools\filter() has been deprecated with message: Use iterable($iterable)->filter($strategy), will be removed in version 3.0

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
285
    }
286
287
    /**
288
     * Make an iterator that returns consecutive groups from the
289
     * $iterable.  Generally, the $iterable needs to already be sorted on
290
     * the same key function.
291
     *
292
     * @param array|string|\Iterator $iterable
293
     * @param string|\Closure $strategy
294
     * @return Itertools\lib\GroupbyIterator
295
     * @deprecated Use group_by instead!
296
     */
297
    public function deprecatedGroupBy($iterable, $strategy)
298
    {
299
        return Itertools\group_by($strategy, $iterable);
0 ignored issues
show
Deprecated Code introduced by
The function Zicht\Itertools\group_by() has been deprecated with message: Use iterable($iterable)->groupBy($strategy, $sort), will be removed in version 3.0

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
300
    }
301
302
    /**
303
     * Make an iterator returning values from $iterable and keys from
304
     * $strategy.
305
     *
306
     * @param array|string|\Iterator $iterable
307
     * @param string|\Closure $strategy
308
     * @return Itertools\lib\MapByIterator
309
     * @deprecated Use map_by instead!
310
     */
311
    public function deprecatedMapBy($iterable, $strategy)
312
    {
313
        return Itertools\mapBy($strategy, $iterable);
0 ignored issues
show
Deprecated Code introduced by
The function Zicht\Itertools\mapBy() has been deprecated with message: Please use map_by, will be removed in version 3.0 Use iterable($iterable)->mapBy($strategy), will be removed in version 3.0

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
314
    }
315
316
    /**
317
     * Create a reduction
318
     *
319
     * @param array|string|\Iterator $iterable
320
     * @param int $default
321
     * @return int
322
     * @deprecated Use reduce instead!
323
     */
324
    public function deprecatedSum($iterable, $default = 0)
325
    {
326
        $result = $default;
327
        foreach (Itertools\accumulate($iterable) as $result) {
0 ignored issues
show
Deprecated Code introduced by
The function Zicht\Itertools\accumulate() has been deprecated with message: Use iterable($iterable)->accumulate($closure), will be removed in version 3.0

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
328
        };
329
        return $result;
330
    }
331
332
    /**
333
     * Takes an iterable and returns another iterable that is unique.
334
     *
335
     * @param array|string|\Iterator $iterable
336
     * @param mixed $strategy
337
     * @return Itertools\lib\UniqueIterator
338
     * @deprecated Use unique instead!
339
     */
340
    public function deprecatedUniqueBy($iterable, $strategy = null)
341
    {
342
        return Itertools\unique($strategy, $iterable);
0 ignored issues
show
Deprecated Code introduced by
The function Zicht\Itertools\unique() has been deprecated with message: Use iterable($iterable)->unique($strategy), will be removed in version 3.0

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
343
    }
344
345
    /**
346
     * Returns a reduction closure
347
     *
348
     * @param string $name
349
     * @return \Closure
350
     * @throws \InvalidArgumentException
351
     * @deprecated Use reducing instead!
352
     */
353
    public function deprecatedGetReduction($name)
0 ignored issues
show
Unused Code introduced by
The parameter $name 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...
354
    {
355
        return call_user_func_array([$this, 'reducing'], func_get_args());
356
    }
357
358
    /**
359
     * {@inheritDoc}
360
     */
361 1
    public function getName()
362
    {
363 1
        return 'zicht_itertools';
364
    }
365
}
366