TransformerMethods::convertBoolean()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Napp\Core\Api\Transformers;
4
5
/**
6
 * Class TransformerMethods.
7
 */
8
class TransformerMethods
9
{
10
    /**
11
     * @param $value
12
     *
13
     * @return mixed
14
     */
15
    public static function convertJson($value)
16
    {
17
        return json_decode($value);
18
    }
19
20
    /**
21
     * @param $value
22
     *
23
     * @return int
24
     */
25 34
    public static function convertInteger($value): int
26
    {
27 34
        return (int) $value;
28
    }
29
30
    /**
31
     * @param $value
32
     *
33
     * @return string
34
     */
35 28
    public static function convertString($value): string
36
    {
37 28
        return (string) $value;
38
    }
39
40
    /**
41
     * @param $value
42
     * @param $parameters
43
     *
44
     * @return float
45
     */
46 14
    public static function convertFloat($value, $parameters): float
47
    {
48 14
        if (isset($parameters[0])) {
49 2
            return round($value, $parameters[0], PHP_ROUND_HALF_UP);
50
        }
51
52 12
        return (float) $value;
53
    }
54
55
    /**
56
     * @param $value
57
     *
58
     * @return bool
59
     */
60 8
    public static function convertBoolean($value): bool
61
    {
62 8
        return (bool) $value;
63
    }
64
65
    /**
66
     * @param $value
67
     *
68
     * @return array
69
     */
70 2
    public static function convertArray($value): array
71
    {
72 2
        if (\method_exists($value, 'toArray')) {
73
            return $value->toArray();
74
        }
75
76 2
        return (array) $value;
77
    }
78
79
    /**
80
     * @param $value
81
     *
82
     * @return mixed|object
83
     */
84
    public static function convertObject($value)
85
    {
86
        if ($value instanceof \JsonSerializable) {
87
            return $value->jsonSerialize();
88
        }
89
90
        return (object) $value;
91
    }
92
93
    /**
94
     * @param $value
95
     *
96
     * @return string
97
     */
98 2
    public static function convertDatetime($value): string
99
    {
100 2
        return strtotime($value) > 0 ? date('c', strtotime($value)) : '';
101
    }
102
}
103