Code

< 40 %
40-60 %
> 60 %
1
<?php
2
3
/**
4
 * Part of SplTypes package.
5
 *
6
 * (c) Adrien Loyant <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Ducks\Component\SplTypes;
15
16
/**
17
 * Parent class for all SPL types.
18
 *
19
 * @template T
20
 *
21
 * @psalm-api
22
 */
23
abstract class SplType implements
24
    \JsonSerializable,
25
    \Stringable
26
{
27
    /** @use SplTypeTrait<T> */
28
    use SplTypeTrait;
29
30
    /**
31
     * Default value.
32
     *
33
     * @var mixed
34
     */
35
    // phpcs:ignore Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
36
    protected const __default = null;
37
38
    /**
39
     * Creates a new value of some type.
40
     *
41
     * @param mixed $initial_value Type and default value depends on the extension class.
42
     * @param bool $strict Whether to set the object's sctrictness.
43
     *
44
     * @return void
45
     *
46
     * @phpstan-param T|null $initial_value Type and default value depends on the extension class.
47
     * @phpstan-param bool $strict Whether to set the object's sctrictness.
48
     * @phpstan-ignore-next-line
49
     *
50
     * @psalm-suppress PossiblyUnusedParam
51
     *
52
     * @SuppressWarnings(PHPMD.CamelCaseParameterName)
53
     * @SuppressWarnings(PHPMD.CamelCaseVariableName)
54
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
55
     */
56 25
    public function __construct($initial_value = self::__default, /** @scrutinizer ignore-unused */ bool $strict = true)
57
    {
58
        /** @var T $this->__default */
59 25
        $this->__default = $initial_value ?? static::__default;
60
    }
61
}
62