forked from PHPCSStandards/PHP_CodeSniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaselineSet.php
More file actions
66 lines (52 loc) · 1.66 KB
/
BaselineSet.php
File metadata and controls
66 lines (52 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Baseline collection class to store and query baselined violations
*
* @author Frank Dekker <fdekker@123inkt.nl>
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/
namespace PHP_CodeSniffer\Baseline;
class BaselineSet
{
/**
* A collection of a baselined violations
*
* @var array<string, ViolationBaseline[]>
*/
private $violations = [];
/**
* Add a single entry to the baseline set
*
* @param ViolationBaseline $entry the entry to add to the collection
*
* @return void
*/
public function addEntry(ViolationBaseline $entry)
{
$this->violations[$entry->getSniffName()][$entry->getSignature()][] = $entry;
}//end addEntry()
/**
* Test if the given sniff and filename is in the baseline collection
*
* @param string $sniffName the name of the sniff to search for
* @param string $fileName the full filename of the file to match
* @param string $signature the code signature of the violation
*
* @return bool
*/
public function contains($sniffName, $fileName, $signature)
{
if (isset($this->violations[$sniffName][$signature]) === false) {
return false;
}
// Normalize slashes in file name.
$fileName = str_replace('\\', '/', $fileName);
foreach ($this->violations[$sniffName][$signature] as $baseline) {
if ($baseline->matches($fileName) === true) {
return true;
}
}
return false;
}//end contains()
}//end class