Passed
Pull Request — v2 (#52)
by
unknown
02:29
created

helpers.php ➔ is_iterable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
use Flugg\Responder\Contracts\Responder;
4
use Flugg\Responder\Contracts\Transformer;
5
6
if (! function_exists('is_iterable')) {
7
8
    /**
9
     * A helper to mimic php 7.1 is_iterable
10
     * @see    http://php.net/manual/en/function.is-iterable.php
11
     * @param  mixed $var
12
     * @return boolean
13
     */
14
    function is_iterable($var): bool
15
    {
16
        return is_array($var) || $var instanceof Traversable;
17
    }
18
}
19
20
if (! function_exists('responder')) {
21
22
    /**
23
     * A helper method to resolve the responder service out of the service container.
24
     *
25
     * @return \Flugg\Responder\Contracts\Responder
26
     */
27
    function responder(): Responder
28
    {
29 1
        return app(Responder::class);
30
    }
31
}
32
33
if (! function_exists('transform')) {
34
35
    /**
36
     * A helper method to transform data without serializing.
37
     *
38
     * @param  mixed                                                          $data
39
     * @param  \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer
40
     * @param  string[]                                                       $with
41
     * @param  string[]                                                       $without
42
     * @return array
43
     */
44
    function transform($data = null, $transformer = null, array $with = [], array $without = []): array
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
45
    {
46 1
        return app(Transformer::class)->transform($data, $transformer, $with, $without);
47
    }
48
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
49