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

StringTraitProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 3
c 1
b 0
f 0
dl 0
loc 10
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 3 1
A toSchema() 0 3 1
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
}