Passed
Push — main ( d3195b...6056b6 )
by Pieter
02:36
created

StringTrait::toSchema()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
4
namespace Apie\ValueObjects;
5
6
use Apie\OpenapiSchema\Contract\SchemaContract;
0 ignored issues
show
Bug introduced by
The type Apie\OpenapiSchema\Contract\SchemaContract 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...
7
use Apie\ValueObjects\Exceptions\InvalidValueForValueObjectException;
8
use LogicException;
9
use ReflectionClass;
10
11
trait StringTrait
12
{
13
    private $value;
14
15
    final public static function fromNative($value)
16
    {
17
        return new self((string) $value);
18
    }
19
20
    final public function __construct(string $value)
21
    {
22
        if (!$this->validValue($value)) {
23
            throw new InvalidValueForValueObjectException($value, __CLASS__);
24
        }
25
        $this->value = $this->sanitizeValue($value);
26
    }
27
28
    abstract protected function validValue(string $value): bool;
29
30
    abstract protected function sanitizeValue(string $value): string;
31
32
    final public function toNative()
33
    {
34
        return $this->value;
35
    }
36
37
    final public function __toString(): string
38
    {
39
        return $this->toNative();
40
    }
41
}