Completed
Pull Request — master (#2)
by Tomáš
03:03
created

SniffNaming   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 1 Features 1
Metric Value
wmc 4
c 5
b 1
f 1
lcom 0
cbo 0
dl 0
loc 39
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A detectUnderscoreLowercaseFromSniffClasses() 0 12 2
A detectDottedFromFilePaths() 0 17 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 Symplify\MultiCodingStandard\Contract\CodeSniffer\Naming\SniffNamingInterface;
11
12
final class SniffNaming implements SniffNamingInterface
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17 4
    public function detectUnderscoreLowercaseFromSniffClasses(array $sniffClasses)
18
    {
19 4
        $underscoreLowercaseNames = [];
20 4
        foreach ($sniffClasses as $sniffClass) {
21 4
            $classNameParts = explode('\\', $sniffClass);
22 4
            $underscoreName = implode($classNameParts, '_');
23
24 4
            $underscoreLowercaseNames[] = strtolower($underscoreName);
25
        }
26
27 4
        return $underscoreLowercaseNames;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 2
    public function detectDottedFromFilePaths(array $sniffFilePaths)
34
    {
35 2
        $dottedNames = [];
36 2
        foreach ($sniffFilePaths as $sniffFilePath) {
37 2
            $sniffFilePathParts = explode(DIRECTORY_SEPARATOR, $sniffFilePath);
38 2
            $sniffFilePathParts = array_slice($sniffFilePathParts, -4);
39
            
40 2
            unset($sniffFilePathParts[1]); // drop "/Sniffs" 
41 2
            $sniffFilePathParts[3] = substr($sniffFilePathParts[3], 0, -9); // drop "Sniff.php"
42
43 2
            $dottedName = implode($sniffFilePathParts, '.');
44
45 2
            $dottedNames[$dottedName] = $sniffFilePath;
46
        }
47
48 2
        return $dottedNames;
49
    }
50
}
51