Completed
Push — master ( 96b2f8...da2c9c )
by Kirill
05:58
created

Renderer::oneOf()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.9332
c 0
b 0
f 0
cc 3
nc 2
nop 1
crap 12
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\Reflection\Common;
11
12
/**
13
 * Class Renderer
14
 */
15
class Renderer
16
{
17
    /**
18
     * @param string $name
19
     * @return string
20
     */
21
    public static function typeName(string $name): string
22
    {
23
        $name = \str_replace(['-', '_'], ' ', $name);
24
        $name = \ucwords($name);
25
26
        return (string)\str_replace(' ', '', $name);
27
    }
28
29
    /**
30
     * @param iterable|string[] $names
31
     * @return string
32
     */
33
    public static function oneOf(iterable $names): string
34
    {
35
        $result = \implode(', ', $names instanceof \Traversable ? \iterator_to_array($names) : $names);
36
37
        if (($position = \strrpos($result, ', ')) !== false) {
38
            return \substr_replace($result, ' or ', $position, 2);
39
        }
40
41
        return $result;
42
    }
43
}
44