Test Failed
Push — main ( a95cda...41a204 )
by Pieter
03:08
created

StringTraitProvider::toSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
4
namespace Apie\ValueObjectPlugin\SchemaProviders;
5
6
use Apie\OpenapiSchema\Contract\SchemaContract;
7
use Apie\OpenapiSchema\Factories\SchemaFactory;
8
use Apie\SchemaGenerator\Context\SchemaContext;
9
use Apie\SchemaGenerator\Contracts\SchemaProvider;
10
use Apie\ValueObjects\StringTrait;
11
use ReflectionClass;
12
13
class StringTraitProvider implements SchemaProvider
14
{
15
    public function supports(ReflectionClass $class, ?SchemaContext $schemaContext = null): bool
16
    {
17
        return in_array(StringTrait::class, class_uses($class->name));
18
    }
19
20
    public function toSchema(ReflectionClass $class, ?SchemaContext $schemaContext = null): SchemaContract
21
    {
22
        return SchemaFactory::createStringSchema(strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $class->getShortName())));
23
    }
24
}