Passed
Pull Request — 1.x (#13)
by
unknown
43:32 queued 28:34
created

StringFormatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 6
c 1
b 0
f 0
dl 0
loc 19
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveString() 0 7 2
A getClassShortName() 0 5 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema\Renderer\MermaidRenderer;
6
7
trait StringFormatter
8
{
9
    private function resolveString(string $value): string
10
    {
11
        if (\preg_match('/[^_a-zA-Z0-9]/u', $value)) {
12
            $value = \preg_replace('/[^a-z0-9_]/u', '_', $value);
13
        }
14
15
        return $value;
16
    }
17
18
    /**
19
     * @param class-string|object $class
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string|object at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string|object.
Loading history...
20
     */
21
    private function getClassShortName($class): string
22
    {
23
        $className = \is_object($class) ? \get_class($class) : $class;
24
25
        return \substr($className, ((int)\strrpos($className, '\\')) + 1);
26
    }
27
}
28