Passed
Pull Request — master (#64)
by
unknown
03:08
created

Extension::getFilters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 32
rs 9.408
c 0
b 0
f 0
ccs 24
cts 24
cp 1
crap 1
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 1
            'itf' => new Itertools\util\Filters(),
23 1
            'itm' => new Itertools\util\Mappings(),
24 1
            'itr' => new Itertools\util\Reductions(),
25
        ];
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     */
31 1
    public function getFilters()
32
    {
33
        return [
34 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...
35
36
            // deprecated filters (because 'it' was introduced)
37 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...
38 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...
39 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...
40 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...
41 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...
42 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...
43 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...
44 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...
45 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...
46 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...
47 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...
48 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...
49 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...
50 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...
51 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...
52
53
            // deprecated filters
54 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...
55 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...
56 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...
57 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...
58 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...
59 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...
60 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...
61
        ];
62
    }
63
64
    /**
65
     * {@inheritDoc}
66
     */
67 1
    public function getFunctions()
68
    {
69
        return [
70
            // deprecated functions (because 'it' was introduced)
71 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...
72 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...
73 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...
74
75
            // deprecated functions (because 'itr', 'itm', and 'itf' were introduced)
76 1
            new \Twig_SimpleFunction('reducing', [$this, 'reducing'], ['deprecated' => true, 'alternative' => 'itr']),
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('mapping', [$this, 'mapping'], ['deprecated' => true, 'alternative' => 'itm']),
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 1
            new \Twig_SimpleFunction('filtering', [$this, 'filtering'], ['deprecated' => true, 'alternative' => 'itf']),
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...
79
80
            // deprecated functions
81 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...
82
        ];
83
    }
84
85
    /**
86
     * Takes an iterable and returns an object that allow mapping, sorting, etc.
87
     *
88
     * @param $iterable
89
     * @return Itertools\lib\Interfaces\FiniteIterableInterface|Itertools\lib\IterableIterator
90
     */
91 1
    public function it($iterable)
92
    {
93 1
        return Itertools\iterable($iterable);
94
    }
95
96
    /**
97
     * Takes an iterable and returns another iterable that is unique.
98
     *
99
     * @param array|string|\Iterator $iterable
100
     * @param mixed $strategy
101
     * @return Itertools\lib\UniqueIterator
102
     * @deprecated
103
     */
104
    public function unique($iterable, $strategy = null)
105
    {
106
        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...
107
    }
108
109
    /**
110
     * Reduce an iterable to a single value
111
     *
112
     * Simple examples:
113
     * {{ [1,2,3]|reduce }} --> 6
114
     * {{ [1,2,3]|reduce('max') }} --> 3
115
     *
116
     * Sro example to get the prices for all items in the basket:
117
     * {{ transaction_snapshot.Basket.Items|map('TotalPrice.Amount')|reduce }}
118
     *
119
     * @param array|string|\Iterator $iterable
120
     * @param string|\Closure $closure
121
     * @param mixed $initializer
122
     * @return mixed
123
     * @deprecated
124
     */
125
    public function reduce($iterable, $closure = 'add', $initializer = null)
126
    {
127
        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...
128
    }
129
130
    /**
131
     * Make an iterator that returns consecutive groups from the
132
     * $iterable.  Generally, the $iterable needs to already be sorted on
133
     * the same key function.
134
     *
135
     * @param array|string|\Iterator $iterable
136
     * @param string|\Closure $strategy
137
     * @param boolean $sort
138
     * @return Itertools\lib\GroupbyIterator
139
     * @deprecated
140
     */
141
    public function groupBy($iterable, $strategy, $sort = true)
142
    {
143
        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...
144
    }
145
146
    /**
147
     * Make an iterator that returns values from $iterable where the
148
     * $strategy determines that the values are not empty.
149
     *
150
     * @param array|string|\Iterator $iterable
151
     * @param null $strategy
152
     * @return Itertools\lib\FilterIterator
153
     * @deprecated
154
     */
155
    public function filter($iterable, $strategy = null)
156
    {
157
        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...
158
    }
159
160
    /**
161
     * Make an iterator that returns the values from $iterable sorted by
162
     * $strategy.
163
     *
164
     * @param array|string|\Iterator $iterable
165
     * @param string|\Closure $strategy
166
     * @param bool $reverse
167
     * @return Itertools\lib\SortedIterator
168
     * @deprecated
169
     */
170
    public function sorted($iterable, $strategy = null, $reverse = false)
171
    {
172
        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...
173
    }
174
175
    /**
176
     * Make an iterator that applies $func to every entry in the $iterables.
177
     *
178
     * @param array|string|\Iterator $iterable
179
     * @param string|\Closure $strategy
180
     * @return Itertools\lib\MapIterator
181
     * @deprecated
182
     */
183
    public function map($iterable, $strategy)
184
    {
185
        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...
186
    }
187
188
    /**
189
     * Make an iterator returning values from $iterable and keys from
190
     * $strategy.
191
     *
192
     * @param array|string|\Iterator $iterable
193
     * @param string|\Closure $strategy
194
     * @return Itertools\lib\MapByIterator
195
     * @deprecated
196
     */
197
    public function mapBy($iterable, $strategy)
198
    {
199
        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...
200
    }
201
202
203
    /**
204
     * Returns a reduction closure
205
     *
206
     * Any parameters provided, beyond $name, are passed directly to the underlying
207
     * reduction.  This can be used to, for example, provide a $glue when using join.
208
     *
209
     * @param string $name
210
     * @return \Closure
211
     * @throws \InvalidArgumentException
212
     */
213 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...
214
    {
215
        // note, once we stop supporting php 5.5, we can rewrite the code below
216
        // to the reducing($name, ...$args) structure.
217
        // http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list
218 4
        $method = sprintf('\Zicht\Itertools\util\Reductions::%s', $name);
219 4
        if (!is_callable($method)) {
220 2
            throw new \InvalidArgumentException(sprintf('$name "%s" is not a valid reduction.', $name));
221
        }
222 2
        return call_user_func_array($method, array_slice(func_get_args(), 1));
223
    }
224
225
    /**
226
     * Returns a mapping closure
227
     *
228
     * Any parameters provided, beyond $name, are passed directly to the underlying
229
     * mapping.  This can be used to, for example, provide a $glue when using join.
230
     *
231
     * @param string $name
232
     * @return \Closure
233
     * @throws \InvalidArgumentException
234
     */
235 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...
236
    {
237
        // note, once we stop supporting php 5.5, we can rewrite the code below
238
        // to the reducing($name, ...$args) structure.
239
        // http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list
240 2
        $method = sprintf('\Zicht\Itertools\util\Mappings::%s', $name);
241 2
        if (!is_callable($method)) {
242 1
            throw new \InvalidArgumentException(sprintf('$name "%s" is not a valid mapping.', $name));
243
        }
244 1
        return call_user_func_array($method, array_slice(func_get_args(), 1));
245
    }
246
247
    /**
248
     * Returns a filter closure
249
     *
250
     * Any parameters provided, beyond $name, are passed directly to the underlying
251
     * filter.  This can be used to, for example, provide a $glue when using join.
252
     *
253
     * @param string $name
254
     * @return \Closure
255
     * @throws \InvalidArgumentException
256
     */
257 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...
258
    {
259
        // note, once we stop supporting php 5.5, we can rewrite the code below
260
        // to the reducing($name, ...$args) structure.
261
        // http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list
262 2
        $method = sprintf('\Zicht\Itertools\util\Filters::%s', $name);
263 2
        if (!is_callable($method)) {
264 1
            throw new \InvalidArgumentException(sprintf('$name "%s" is not a valid filter.', $name));
265
        }
266 1
        return call_user_func_array($method, array_slice(func_get_args(), 1));
267
268
    }
269
270
    /**
271
     * Make an iterator that returns values from $iterable where the
272
     * $strategy determines that the values are not empty.
273
     *
274
     * @param array|string|\Iterator $iterable
275
     * @param string|\Closure $strategy
276
     * @return Itertools\lib\FilterIterator
277
     * @deprecated Use filter instead!
278
     */
279
    public function deprecatedFilterBy($iterable, $strategy)
280
    {
281
        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...
282
    }
283
284
    /**
285
     * Make an iterator that returns consecutive groups from the
286
     * $iterable.  Generally, the $iterable needs to already be sorted on
287
     * the same key function.
288
     *
289
     * @param array|string|\Iterator $iterable
290
     * @param string|\Closure $strategy
291
     * @return Itertools\lib\GroupbyIterator
292
     * @deprecated Use group_by instead!
293
     */
294
    public function deprecatedGroupBy($iterable, $strategy)
295
    {
296
        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...
297
    }
298
299
    /**
300
     * Make an iterator returning values from $iterable and keys from
301
     * $strategy.
302
     *
303
     * @param array|string|\Iterator $iterable
304
     * @param string|\Closure $strategy
305
     * @return Itertools\lib\MapByIterator
306
     * @deprecated Use map_by instead!
307
     */
308
    public function deprecatedMapBy($iterable, $strategy)
309
    {
310
        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...
311
    }
312
313
    /**
314
     * Create a reduction
315
     *
316
     * @param array|string|\Iterator $iterable
317
     * @param int $default
318
     * @return int
319
     * @deprecated Use reduce instead!
320
     */
321
    public function deprecatedSum($iterable, $default = 0)
322
    {
323
        $result = $default;
324
        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...
325
        };
326
        return $result;
327
    }
328
329
    /**
330
     * Takes an iterable and returns another iterable that is unique.
331
     *
332
     * @param array|string|\Iterator $iterable
333
     * @param mixed $strategy
334
     * @return Itertools\lib\UniqueIterator
335
     * @deprecated Use unique instead!
336
     */
337
    public function deprecatedUniqueBy($iterable, $strategy = null)
338
    {
339
        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...
340
    }
341
342
    /**
343
     * Returns a reduction closure
344
     *
345
     * @param string $name
346
     * @return \Closure
347
     * @throws \InvalidArgumentException
348
     * @deprecated Use reducing instead!
349
     */
350
    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...
351
    {
352
        return call_user_func_array([$this, 'reducing'], func_get_args());
353
    }
354
355
    /**
356
     * {@inheritDoc}
357
     */
358 1
    public function getName()
359
    {
360 1
        return 'zicht_itertools';
361
    }
362
}
363