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
|
|
|
|