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.
Passed
Push — master ( 4b3d26...06dcf5 )
by Enjoys
12:36 queued 13s
created

ValueTypecasting   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 36
ccs 11
cts 11
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCastValue() 0 3 1
A __construct() 0 4 1
A determine() 0 8 3
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace Enjoys\Dotenv;
7
8
9
use Enjoys\Dotenv\Types\BoolType;
10
use Enjoys\Dotenv\Types\FalseType;
11
use Enjoys\Dotenv\Types\FloatType;
12
use Enjoys\Dotenv\Types\Int16Type;
13
use Enjoys\Dotenv\Types\Int8Type;
14
use Enjoys\Dotenv\Types\IntType;
15
use Enjoys\Dotenv\Types\NullType;
16
use Enjoys\Dotenv\Types\StringType;
17
use Enjoys\Dotenv\Types\TrueType;
18
use Enjoys\Dotenv\Types\TypeCastInterface;
19
20
final class ValueTypecasting
21
{
22
23
    private const DEFINABLE_TYPES_MAP = [
24
        IntType::class,
25
        FloatType::class,
26
        TrueType::class,
27
        FalseType::class,
28
        NullType::class,
29
        BoolType::class,
30
        StringType::class,
31
        Int8Type::class,
32
        Int16Type::class
33
    ];
34
35
    private float|bool|int|string|null $castedValue;
36
37 34
    public function __construct(private string $originalValue)
38
    {
39 34
        $this->castedValue = $this->originalValue;
40 34
        $this->determine();
41
    }
42
43 34
    public function getCastValue(): float|bool|int|string|null
44
    {
45 34
        return $this->castedValue;
46
    }
47
48 34
    private function determine(): void
49
    {
50 34
         foreach (self::DEFINABLE_TYPES_MAP as $typeClass) {
51
             /** @var TypeCastInterface $type */
52 34
             $type = new $typeClass($this->originalValue);
53 34
            if ($type->isPossible()){
54 24
                $this->castedValue = $type->getCastedValue();
55 24
                break;
56
            }
57
        }
58
    }
59
60
61
62
}
63