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

StringEnumTrait::toSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
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 ReflectionClass;
8
9
trait StringEnumTrait
10
{
11
    use StringTrait;
12
13
    final protected function validValue(string $value): bool
14
    {
15
        $values = self::getValidValues();
16
        return isset($values[$value]) || false !== array_search($value, $values, true);
17
    }
18
19
    final protected function sanitizeValue(string $value): string
20
    {
21
        $values = self::getValidValues();
22
        if (isset($values[$value])) {
23
            return $values[$value];
24
        }
25
        return $value;
26
    }
27
28
29
    final public static function getValidValues()
30
    {
31
        $reflectionClass = new ReflectionClass(__CLASS__);
32
        return $reflectionClass->getConstants();
33
    }
34
}