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
|
5 |
|
public function detectUnderscoreLowercaseFromSniffNames(array $sniffClassesOrNames) |
18
|
|
|
{ |
19
|
5 |
|
$underscoreLowercaseNames = []; |
20
|
5 |
|
foreach ($sniffClassesOrNames as $sniffClassOrName) { |
21
|
5 |
|
$sniffNameParts = explode('.', $sniffClassOrName); |
22
|
5 |
|
array_splice($sniffNameParts, 1, 0, ['Sniffs']); |
23
|
5 |
|
$sniffNameParts[3] .= 'Sniff'; |
24
|
5 |
|
$underscoreName = implode('_', $sniffNameParts); |
25
|
|
|
|
26
|
5 |
|
$underscoreLowercaseNames[] = strtolower($underscoreName); |
27
|
|
|
} |
28
|
|
|
|
29
|
5 |
|
return $underscoreLowercaseNames; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
3 |
|
public function detectDottedFromFilePaths(array $sniffFilePaths) |
36
|
|
|
{ |
37
|
3 |
|
$dottedNames = []; |
38
|
3 |
|
foreach ($sniffFilePaths as $sniffFilePath) { |
39
|
3 |
|
$sniffFilePathParts = explode(DIRECTORY_SEPARATOR, $sniffFilePath); |
40
|
3 |
|
$sniffFilePathParts = array_slice($sniffFilePathParts, -4); |
41
|
|
|
|
42
|
3 |
|
unset($sniffFilePathParts[1]); // drop "/Sniffs" |
43
|
3 |
|
$sniffFilePathParts[3] = substr($sniffFilePathParts[3], 0, -9); // drop "Sniff.php" |
44
|
|
|
|
45
|
3 |
|
$dottedName = implode($sniffFilePathParts, '.'); |
46
|
|
|
|
47
|
3 |
|
$dottedNames[$dottedName] = $sniffFilePath; |
48
|
|
|
} |
49
|
|
|
|
50
|
3 |
|
return $dottedNames; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|