Completed
Push — master ( 3e4d42...ec481a )
by Amine
10s
created

object.php ➔ clone_()   C

Complexity

Conditions 15
Paths 2

Size

Total Lines 28
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 15
eloc 24
nc 2
nop 0
dl 0
loc 28
rs 5.0504
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php namespace Tarsana\Functional;
2
/**
3
 * Useful functions to handle objects (associative arrays are considered objects).
4
 * @file
5
 */
6
7
/**
8
 * Returns a deep copy of the given value.
9
 *
10
 * `Callable`s are not copied but returned by reference.
11
 * ```php
12
 * $data = (object) [
13
 *     'content' => (object) ['name' => 'foo'],
14
 *     'other' => 'value'
15
 * ];
16
 *
17
 * $clonedData = F\clone_($data);
18
 * $clonedData->content->name = 'bar';
19
 *
20
 * $clonedData; //=> (object) ['content' => (object) ['name' => 'bar'], 'other' => 'value']
21
 * $data; //=> (object) ['content' => (object) ['name' => 'foo'], 'other' => 'value']
22
 * ```
23
 *
24
 * @signature a -> a
25
 * @param  mixed $value
0 ignored issues
show
Bug introduced by
There is no parameter named $value. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
26
 * @return mixed
27
 */
28
function clone_() {
29
    static $clone = false;
30
    $clone = $clone ?: curry(function($value) {
31
        switch (type($value)) {
32
            case 'Null':
33
            case 'Boolean':
34
            case 'String':
35
            case 'Function':
36
            case 'Resource':
37
            case 'Number':
38
                return $value;
39
            case 'ArrayObject':
40
            case 'Array':
41
            case 'List':
42
                return map(clone_(), $value);
43
            case 'Error':
44
            case 'Stream':
45
            case 'Object':
46
                $result = clone $value;
47
                foreach (keys($value) as $key) {
48
                    $result->{$key} = clone_($result->{$key});
49
                }
50
                return $result;
51
        }
52
        return $value;
53
    });
54
    return _apply($clone, func_get_args());
55
}
56
57
/**
58
 * Converts an object to an associative array containing public non-static attributes.
59
 *
60
 * If `$object` is not an object, it is returned unchanged.
61
 * ```php
62
 * class AttributesTestClass {
63
 *     private $a;
64
 *     public $b = 1;
65
 *     public $c;
66
 *     private $d;
67
 *     static $e;
68
 * }
69
 *
70
 * $test = new AttributesTestClass;
71
 * F\attributes($test); //=> ['b' => 1, 'c' => null]
72
 * ```
73
 *
74
 * @stream
75
 * @signature {k: v} -> {k: v}
76
 * @param  object|array $object
0 ignored issues
show
Bug introduced by
There is no parameter named $object. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
77
 * @return array
78
 */
79
function attributes() {
80
    static $attrs = false;
81
    $attrs = $attrs ?: curry(function($object) {
82
        if (is_object($object))
83
            return get_object_vars($object);
84
        return $object;
85
    });
86
    return _apply($attrs, func_get_args());
87
}
88
89
/**
90
 * Returns a list of array's keys or object's public attributes names.
91
 *
92
 * ```php
93
 * F\keys([1, 2, 3]); //=> [0, 1, 2]
94
 * F\keys(['name' => 'foo', 'age' => 11]); //=> ['name', 'age']
95
 * F\keys((object)['name' => 'foo', 'age' => 11]); //=> ['name', 'age']
96
 * ```
97
 *
98
 * @stream
99
 * @signature [*] -> [Number]
100
 * @signature {k: v} -> [k]
101
 * @param object|array $object
0 ignored issues
show
Bug introduced by
There is no parameter named $object. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
102
 * @return array
103
 */
104 View Code Duplication
function keys() {
0 ignored issues
show
Duplication introduced by
This function 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...
105
    static $keys = false;
106
    $keys = $keys ?: curry(function($object) {
107
        return array_keys(attributes($object));
108
    });
109
    return _apply($keys, func_get_args());
110
}
111
112
/**
113
 * Returns a list of array's values or object's public attributes values.
114
 *
115
 * ```php
116
 * F\values([1, 2, 3]); //=> [1, 2, 3]
117
 * F\values(['name' => 'foo', 'age' => 11]); //=> ['foo', 11]
118
 * F\values((object)['name' => 'foo', 'age' => 11]); //=> ['foo', 11]
119
 * ```
120
 *
121
 * @stream
122
 * @signature [a] -> [a]
123
 * @signature {k: v} -> [v]
124
 * @param object|array $object
0 ignored issues
show
Bug introduced by
There is no parameter named $object. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
125
 * @return array
126
 */
127 View Code Duplication
function values() {
0 ignored issues
show
Duplication introduced by
This function 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...
128
    static $values = false;
129
    $values = $values ?: curry(function($object) {
130
        return array_values(attributes($object));
131
    });
132
    return _apply($values, func_get_args());
133
}
134
135
/**
136
 * Checks if the given array or object has a specific key or public attribute.
137
 *
138
 * ```php
139
 * class HasTestClass {
140
 *     public $a = 1;
141
 *     private $b = 2;
142
 *     protected $c = 3;
143
 *     public $d;
144
 * }
145
 * $array = [
146
 *     'type' => 'Array',
147
 *     'length' => 78
148
 * ];
149
 * $array[3] = 'three';
150
 * $object = (object) ['name' => 'ok'];
151
 *
152
 * $hasName = F\has('name');
153
 *
154
 * F\has('type', $array); //=> true
155
 * F\has(3, $array); //=> true
156
 * $hasName($array); //=> false
157
 * $hasName($object); //=> true
158
 * F\has('length', $object); //=> false
159
 * F\has('a', new HasTestClass); //=> true
160
 * F\has('b', new HasTestClass); //=> false
161
 * ```
162
 *
163
 * @stream
164
 * @signature k -> {k: v} -> Boolean
165
 * @param  string|int $name
0 ignored issues
show
Bug introduced by
There is no parameter named $name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
166
 * @param  mixed $object
0 ignored issues
show
Bug introduced by
There is no parameter named $object. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
167
 * @return bool
168
 */
169
function has() {
170
    static $has = false;
171
    $has = $has ?: curry(function($name, $object){
172
        return contains($name, keys($object));
173
    });
174
    return _apply($has, func_get_args());
175
}
176
177
/**
178
 * Gets the value of a key from an array or the
179
 * value of an public attribute from an object.
180
 *
181
 * If the key/attribute is missing, `null` is returned.
182
 * ```php
183
 * $data = [
184
 *     ['name' => 'foo', 'type' => 'test'],
185
 *     ['name' => 'bar', 'type' => 'test'],
186
 *     (object) ['name' => 'baz'],
187
 *     [1, 2, 3]
188
 * ];
189
 * $nameOf = F\get('name');
190
 * F\get(0, $data); //=> ['name' => 'foo', 'type' => 'test']
191
 * $nameOf($data[1]); //=> 'bar'
192
 * $nameOf($data[2]); //=> 'baz'
193
 * $nameOf($data[3]); //=> null
194
 * ```
195
 *
196
 * @stream
197
 * @signature k -> {k: v} -> Maybe(v)
198
 * @param  string $name
0 ignored issues
show
Bug introduced by
There is no parameter named $name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
199
 * @param  array $object
0 ignored issues
show
Bug introduced by
There is no parameter named $object. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
200
 * @return mixed
201
 */
202 View Code Duplication
function get() {
0 ignored issues
show
Duplication introduced by
This function 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...
203
    static $get = false;
204
    $get = $get ?: curry(function($name, $object){
205
        $object = attributes($object);
206
        return has($name, $object)
207
            ? $object[$name]
208
            : null;
209
    });
210
    return _apply($get, func_get_args());
211
}
212
213
/**
214
 * Gets a value from an array/object using a path of keys/attributes.
215
 *
216
 * ```php
217
 * $data = [
218
 *     ['name' => 'foo', 'type' => 'test'],
219
 *     ['name' => 'bar', 'type' => 'test'],
220
 *     (object) ['name' => 'baz', 'scores' => [1, 2, 3]]
221
 * ];
222
 * $nameOfFirst = F\getPath([0, 'name']);
223
 * $nameOfFirst($data); //=> 'foo'
224
 * F\getPath([2, 'scores', 1], $data); //=> 2
225
 * F\getPath([2, 'foo', 1], $data); //=> null
226
 * ```
227
 *
228
 * @stream
229
 * @signature [k] -> {k: v} -> v
230
 * @param  array $path
0 ignored issues
show
Bug introduced by
There is no parameter named $path. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
231
 * @param  mixed $object
0 ignored issues
show
Bug introduced by
There is no parameter named $object. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
232
 * @return mixed
233
 */
234 View Code Duplication
function getPath() {
0 ignored issues
show
Duplication introduced by
This function 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...
235
    static $getPath = false;
236
    $getPath = $getPath ?: curry(function($path, $object){
237
        return reduce(function($result, $name) {
238
            if ($result !== null)
239
                $result = get($name, $result);
240
            return $result;
241
        }, $object, $path);
242
    });
243
    return _apply($getPath, func_get_args());
244
}
245
246
/**
247
 * Returns a new array or object with the value of a key or a public attribute set
248
 * to a specific value.
249
 *
250
 * if the key/attribute is missing and `$object` is an `array`
251
 * or `stdClass`; the key/attribute is added. Otherwise `null` is returned.
252
 * ```php
253
 * $task = ['name' => 'test', 'complete' => false];
254
 * $done = F\set('complete', true);
255
 * $done($task); //=> ['name' => 'test', 'complete' => true]
256
 * $done((object) $task); //=> (object) ['name' => 'test', 'complete' => true]
257
 * F\set('description', 'Some text here', $task); //=> ['name' => 'test', 'complete' => false, 'description' => 'Some text here']
258
 * ```
259
 *
260
 * @stream
261
 * @signature k -> v -> {k: v} -> {k: v}
262
 * @param  string|int $name
0 ignored issues
show
Bug introduced by
There is no parameter named $name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
263
 * @param  mixed $value
0 ignored issues
show
Bug introduced by
There is no parameter named $value. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
264
 * @param  mixed $object
0 ignored issues
show
Bug introduced by
There is no parameter named $object. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
265
 * @return mixed
266
 */
267
function set() {
268
    static $set = false;
269
    $set = $set ?: curry(function($name, $value, $object) {
270
        $object = clone_($object);
271
        if (is_object($object))
272
            $object->{$name} = $value;
273
        else
274
            $object[$name] = $value;
275
        return $object;
276
    });
277
    return _apply($set, func_get_args());
278
}
279
280
/**
281
 * Updates the value of a key or public attribute using a callable.
282
 *
283
 * ```php
284
 * $person = [
285
 *     'name' => 'foo',
286
 *     'age' => 11
287
 * ];
288
 * $growUp = F\update('age', F\plus(1));
289
 * $growUp($person); //=> ['name' => 'foo', 'age' => 12]
290
 * // updating a missing attribute has no effect
291
 * F\update('wow', F\plus(1), $person); //=> ['name' => 'foo', 'age' => 11]
292
 * ```
293
 *
294
 * @stream
295
 * @signature k -> (v -> v) -> {k: v} -> {k: v}
296
 * @param  string|int $name
0 ignored issues
show
Bug introduced by
There is no parameter named $name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
297
 * @param  callable $fn
0 ignored issues
show
Bug introduced by
There is no parameter named $fn. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
298
 * @param  mixed $object
0 ignored issues
show
Bug introduced by
There is no parameter named $object. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
299
 * @return mixed
300
 */
301 View Code Duplication
function update() {
0 ignored issues
show
Duplication introduced by
This function 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...
302
    static $update = false;
303
    $update = $update ?: curry(function($name, $fn, $object) {
304
        $value = get($name, $object);
305
        return (null === $value) ? $object : set($name, $fn($value), $object);
306
    });
307
    return _apply($update, func_get_args());
308
}
309
310
/**
311
 * Checks if an attribute/value of an object/array passes the given predicate.
312
 *
313
 * ```php
314
 * $foo = ['name' => 'foo', 'age' => 11];
315
 * $isAdult = F\satisfies(F\gt(F\__(), 18), 'age');
316
 * F\satisfies(F\startsWith('f'), 'name', $foo); //=> true
317
 * F\satisfies(F\startsWith('g'), 'name', $foo); //=> false
318
 * F\satisfies(F\startsWith('g'), 'friends', $foo); //=> false
319
 * $isAdult($foo); //=> false
320
 * ```
321
 *
322
 * @stream
323
 * @signature (a -> Boolean) -> k -> {k : a} -> Boolean
324
 * @param  callable $predicate
0 ignored issues
show
Bug introduced by
There is no parameter named $predicate. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
325
 * @param  string|int $key
0 ignored issues
show
Bug introduced by
There is no parameter named $key. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
326
 * @param  mixed $object
0 ignored issues
show
Bug introduced by
There is no parameter named $object. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
327
 * @return bool
328
 */
329
function satisfies() {
330
    static $satisfies = false;
331
    $satisfies = $satisfies ?: curry(function($predicate, $key, $object) {
332
        return has($key, $object) && $predicate(get($key, $object));
333
    });
334
    return _apply($satisfies, func_get_args());
335
}
336
337
/**
338
 * Checks if a list of attribute/value of an object/array passes all the given predicates.
339
 *
340
 * ```php
341
 * $persons = [
342
 *     ['name' => 'foo', 'age' => 11],
343
 *     ['name' => 'bar', 'age' => 9],
344
 *     ['name' => 'baz', 'age' => 16],
345
 *     ['name' => 'zeta', 'age' => 33],
346
 *     ['name' => 'beta', 'age' => 25]
347
 * ];
348
 *
349
 * $isValid = F\satisfiesAll([
350
 *     'name' => F\startsWith('b'),
351
 *     'age' => F\gt(F\__(), 15)
352
 * ]);
353
 *
354
 * F\filter($isValid, $persons); //=> [['name' => 'baz', 'age' => 16], ['name' => 'beta', 'age' => 25]]
355
 * ```
356
 *
357
 * @stream
358
 * @signature {String: (a -> Boolean)} -> {k : a} -> Boolean
359
 * @param  array $predicates
0 ignored issues
show
Bug introduced by
There is no parameter named $predicates. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
360
 * @param  mixed $object
0 ignored issues
show
Bug introduced by
There is no parameter named $object. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
361
 * @return bool
362
 */
363 View Code Duplication
function satisfiesAll() {
0 ignored issues
show
Duplication introduced by
This function 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...
364
    static $satisfiesAll = false;
365
    $satisfiesAll = $satisfiesAll ?: curry(function($predicates, $object) {
366
        $predicates = map(function($pair) {
367
            return satisfies($pair[1], $pair[0]);
368
        }, toPairs($predicates));
369
        $predicates = apply(_f('all'), $predicates);
370
        return $predicates($object);
371
    });
372
    return _apply($satisfiesAll, func_get_args());
373
}
374
375
/**
376
 * Checks if a list of attribute/value of an object/array passes any of the given predicates.
377
 *
378
 * ```php
379
 * $persons = [
380
 *     ['name' => 'foo', 'age' => 11],
381
 *     ['name' => 'bar', 'age' => 9],
382
 *     ['name' => 'baz', 'age' => 16],
383
 *     ['name' => 'zeta', 'age' => 33],
384
 *     ['name' => 'beta', 'age' => 25]
385
 * ];
386
 *
387
 * $isValid = F\satisfiesAny([
388
 *     'name' => F\startsWith('b'),
389
 *     'age' => F\gt(F\__(), 15)
390
 * ]);
391
 *
392
 * F\filter($isValid, $persons); //=> [['name' => 'bar', 'age' => 9], ['name' => 'baz', 'age' => 16], ['name' => 'zeta', 'age' => 33], ['name' => 'beta', 'age' => 25]]
393
 * ```
394
 *
395
 * @stream
396
 * @signature {String: (a -> Boolean)} -> {k : a} -> Boolean
397
 * @param  array $predicates
0 ignored issues
show
Bug introduced by
There is no parameter named $predicates. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
398
 * @param  mixed $object
0 ignored issues
show
Bug introduced by
There is no parameter named $object. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
399
 * @return bool
400
 */
401 View Code Duplication
function satisfiesAny() {
0 ignored issues
show
Duplication introduced by
This function 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...
402
    static $satisfiesAny = false;
403
    $satisfiesAny = $satisfiesAny ?: curry(function($predicates, $object) {
404
        $predicates = map(function($pair) {
405
            return satisfies($pair[1], $pair[0]);
406
        }, toPairs($predicates));
407
        $predicates = apply(_f('any'), $predicates);
408
        return $predicates($object);
409
    });
410
    return _apply($satisfiesAny, func_get_args());
411
}
412
413
/**
414
 * Converts an object or associative array to an array of [key, value] pairs.
415
 *
416
 * ```php
417
 * $list = ['key' => 'value', 'number' => 53, 'foo', 'bar'];
418
 * F\toPairs($list); //=> [['key', 'value'], ['number', 53], [0, 'foo'], [1, 'bar']]
419
 * ```
420
 *
421
 * @stream
422
 * @signature {k: v} -> [(k,v)]
423
 * @param  array $object
0 ignored issues
show
Bug introduced by
There is no parameter named $object. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
424
 * @return array
425
 */
426
function toPairs() {
427
    static $toPairs = false;
428
    $toPairs = $toPairs ?: curry(function($object) {
429
        return map(function($key) use($object) {
430
            return [$key, get($key, $object)];
431
        }, keys($object));
432
    });
433
    return _apply($toPairs, func_get_args());
434
}
435