SlashPathSegmentNameGenerator::getSegmentName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
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