ParamBuilder   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 17
c 5
b 0
f 0
dl 0
loc 37
rs 10
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B build() 0 28 7
1
<?php
2
3
namespace Transmission\HttpClient\Message;
4
5
/**
6
 * ParamBuilder.
7
 */
8
final class ParamBuilder
9
{
10
    /**
11
     * Sanitize and build params.
12
     *
13
     * @param array $params
14
     *
15
     * @return array
16
     */
17
    public static function build($params): array
18
    {
19
        return collect($params)
0 ignored issues
show
Bug introduced by
$params of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
        return collect(/** @scrutinizer ignore-type */ $params)
Loading history...
20
            ->reject(function ($value) {
21
                return blank($value);
22
            })->transform(function ($value) {
23
                if (is_object($value)) {
24
                    return $value->toArray();
25
                }
26
27
                if (is_array($value)) {
28
                    return static::build($value);
29
                }
30
31
                if (is_numeric($value)) {
32
                    return $value + 0;
33
                }
34
35
                if (is_bool($value)) {
36
                    return (int) $value;
37
                }
38
39
                if (is_string($value) && mb_detect_encoding($value, 'auto') !== 'UTF-8') {
40
                    return mb_convert_encoding($value, 'UTF-8');
41
                }
42
43
                return $value;
44
            })->toArray();
45
    }
46
}
47