SlashPathSegmentNameGenerator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 19
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSegmentName() 0 6 2
A slashize() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the zibios/sharep.
7
 *
8
 * (c) Zbigniew Ślązak
9
 */
10
11
namespace App\Swagger\Operation;
12
13
use ApiPlatform\Core\Operation\PathSegmentNameGeneratorInterface;
14
use Doctrine\Common\Inflector\Inflector;
15
16
final class SlashPathSegmentNameGenerator implements PathSegmentNameGeneratorInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21 7
    public function getSegmentName(string $name, bool $collection = true): string
22
    {
23 7
        $name = $this->slashize($name);
24
25 7
        return $collection ? Inflector::pluralize($name) : $name;
26
    }
27
28 7
    private function slashize(string $string): string
29
    {
30 7
        $string = preg_replace('~(?<=\\w)([A-Z])~', '/$1', $string);
31
32 7
        return strtolower($string);
33
    }
34
}
35