Completed
Push — master ( 4d96cc...d35fc1 )
by Tomáš
04:03 queued 01:56
created

detectUnderscoreLowercaseFromSniffClasses()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of Symplify
5
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
6
 */
7
8
namespace Symplify\MultiCodingStandard\CodeSniffer\Naming;
9
10
use Nette\Utils\Strings;
11
use Symplify\MultiCodingStandard\Contract\CodeSniffer\Naming\SniffNamingInterface;
12
13
final class SniffNaming implements SniffNamingInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18 6
    public function detectUnderscoreLowercaseFromSniffClassesOrNames(array $sniffClassesOrNames)
19
    {
20 6
        $underscoreLowercaseNames = [];
21 6
        foreach ($sniffClassesOrNames as $sniffClassOrName) {
22 6
            if (Strings::contains($sniffClassOrName, '.')) {
23 2
                $sniffNameParts = explode('.', $sniffClassOrName);
24 2
                array_splice($sniffNameParts, 1, 0, ['Sniffs']);
25 2
                $sniffNameParts[3] .= 'Sniff';
26 2
                $underscoreName = implode('_', $sniffNameParts);
27
            } else {
28 5
                $underscoreName = str_replace(['\\'], ['_'], $sniffClassOrName);
29
            }
30
31 6
            $underscoreLowercaseNames[] = strtolower($underscoreName);
32
        }
33
34 6
        return $underscoreLowercaseNames;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 3
    public function detectDottedFromFilePaths(array $sniffFilePaths)
41
    {
42 3
        $dottedNames = [];
43 3
        foreach ($sniffFilePaths as $sniffFilePath) {
44 3
            $sniffFilePathParts = explode(DIRECTORY_SEPARATOR, $sniffFilePath);
45 3
            $sniffFilePathParts = array_slice($sniffFilePathParts, -4);
46
            
47 3
            unset($sniffFilePathParts[1]); // drop "/Sniffs"
48 3
            $sniffFilePathParts[3] = substr($sniffFilePathParts[3], 0, -9); // drop "Sniff.php"
49
50 3
            $dottedName = implode($sniffFilePathParts, '.');
51
52 3
            $dottedNames[$dottedName] = $sniffFilePath;
53
        }
54
55 3
        return $dottedNames;
56
    }
57
}
58