GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ValueTransform::toBool()   A
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 8
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 15
rs 9.2222
1
<?php
2
3
namespace Soheilrt\AdobeConnectClient\Client\Helpers;
4
5
use DateTime;
6
use DateTimeImmutable;
7
use DateTimeInterface;
8
use Exception;
9
10
/**
11
 * Converts the value into a type.
12
 */
13
abstract class ValueTransform
14
{
15
    /**
16
     * Converts arbitrary value into string.
17
     *
18
     * @param mixed $value
19
     *
20
     * @return string
21
     */
22
    public static function toString($value)
23
    {
24
        if (is_string($value)) {
25
            return $value;
26
        }
27
28
        if (is_bool($value)) {
29
            return $value ? 'true' : 'false';
30
        }
31
32
        if ($value instanceof DateTimeInterface) {
33
            return $value->format(DateTime::W3C);
34
        }
35
36
        return (string) $value;
37
    }
38
39
    /**
40
     * Converts arbitrary value into DateTimeImmutable.
41
     *
42
     * @param mixed $value
43
     *
44
     * @throws Exception
45
     *
46
     * @return DateTimeImmutable
47
     */
48
    public static function toDateTimeImmutable($value)
49
    {
50
        if ($value instanceof DateTimeImmutable) {
51
            return $value;
52
        }
53
54
        if ($value instanceof DateTime) {
55
            return DateTimeImmutable::createFromMutable($value);
56
        }
57
58
        return new DateTimeImmutable((string) $value);
59
    }
60
61
    /**
62
     * Transform the value into a boolean type.
63
     *
64
     * @param mixed $value The value to transform
65
     *
66
     * @return bool
67
     */
68
    public static function toBool($value)
69
    {
70
        if (!is_string($value)) {
71
            return boolval($value);
72
        }
73
74
        $value = mb_strtolower($value);
75
76
        if ($value === 'false' or $value === 'off') {
77
            return false;
78
        } elseif ($value === 'true' or $value === 'on') {
79
            return true;
80
        }
81
82
        return boolval($value);
83
    }
84
}
85