Passed
Push — master ( 3e0ae5...66dbef )
by Melech
01:47 queued 20s
created

Type::asValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Valkyrja\Type\Abstract;
15
16
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Valkyrja\Type\Contract\Type as Contract;
18
19
/**
20
 * Class Type.
21
 *
22
 * @author Melech Mizrachi
23
 *
24
 * @implements Contract<T>
25
 *
26
 * @template T
27
 */
28
abstract class Type implements Contract
29
{
30
    /**
31
     * @var T
32
     */
33
    protected mixed $subject;
34
35
    /**
36
     * @inheritDoc
37
     */
38
    #[Override]
39
    abstract public static function fromValue(mixed $value): static;
40
41
    /**
42
     * @inheritDoc
43
     */
44
    #[Override]
45
    public function asValue(): mixed
46
    {
47
        return $this->subject;
48
    }
49
50
    /**
51
     * @inheritDoc
52
     */
53
    #[Override]
54
    public function modify(callable $closure): static
55
    {
56
        return static::fromValue($closure($this->subject));
57
    }
58
59
    /**
60
     * @inheritDoc
61
     */
62
    #[Override]
63
    public function jsonSerialize(): mixed
64
    {
65
        return $this->asValue();
66
    }
67
68
    /**
69
     * @inheritDoc
70
     */
71
    #[Override]
72
    abstract public function asFlatValue(): string|int|float|bool|null;
73
}
74