1<?php
2
3
4namespace ComboStrap\Meta\Api;
5
6
7use ComboStrap\DataType;
8use ComboStrap\ExceptionCompile;
9use ComboStrap\LogUtility;
10use ComboStrap\Meta\Api\Metadata;
11
12abstract class MetadataInteger extends Metadata
13{
14
15    /**
16     * @var int
17     */
18    protected $value;
19
20
21    static public function getDataType(): string
22    {
23        return DataType::INTEGER_TYPE_VALUE;
24    }
25
26    public function getValue(): ?int
27    {
28        $this->buildCheck();
29        return $this->value;
30    }
31
32    public function valueIsNotNull(): bool
33    {
34        return $this->value !== null;
35    }
36
37
38    /**
39     * @throws ExceptionCompile
40     */
41    public function setValue($value): Metadata
42    {
43        $this->value = DataType::toInteger($value);
44        return $this;
45    }
46
47    /**
48     * @throws ExceptionCompile
49     */
50    public function setFromStoreValue($value): Metadata
51    {
52        return $this->setValue($value);
53    }
54
55    public function setFromStoreValueWithoutException($value): Metadata
56    {
57        if ($value === null || $value === "") {
58            $this->value = null;
59            return $this;
60        }
61        if (!is_string($value)) {
62            LogUtility::msg("This value of a text metadata is not a string. " . var_export($value, true));
63            return $this;
64        }
65        $this->value = $value;
66        return $this;
67    }
68
69    public function getDefaultValue(): int
70    {
71        return 0;
72    }
73
74}
75