forked from PHPCompatibility/PHPCompatibility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSniff.php
106 lines (95 loc) · 3.49 KB
/
Sniff.php
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* PHPCompatibility_Sniff.
*
* PHP version 5.6
*
* @category PHP
* @package PHPCompatibility
* @author Wim Godden <[email protected]>
* @copyright 2014 Cu.be Solutions bvba
*/
/**
* PHPCompatibility_Sniff.
*
* @category PHP
* @package PHPCompatibility
* @author Wim Godden <[email protected]>
* @version 1.1.0
* @copyright 2014 Cu.be Solutions bvba
*/
abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
{
/* The testVersion configuration variable may be in any of the following formats:
* 1) Omitted/empty, in which case no version is specified. This effectively
* disables all the checks provided by this standard.
* 2) A single PHP version number, e.g. "5.4" in which case the standard checks that
* the code will run on that version of PHP (no deprecated features or newer
* features being used).
* 3) A range, e.g. "5.0-5.5", in which case the standard checks the code will run
* on all PHP versions in that range, and that it doesn't use any features that
* were deprecated by the final version in the list, or which were not available
* for the first version in the list.
* PHP version numbers should always be in Major.Minor format. Both "5", "5.3.2"
* would be treated as invalid, and ignored.
* This standard doesn't support checking against PHP4, so the minimum version that
* is recognised is "5.0".
*/
private function getTestVersion()
{
/**
* var $testVersion will hold an array containing min/max version of PHP
* that we are checking against (see above). If only a single version
* number is specified, then this is used as both the min and max.
*/
static $arrTestVersions;
if (!isset($testVersion)) {
$testVersion = PHP_CodeSniffer::getConfigData('testVersion');
$testVersion = trim($testVersion);
$arrTestVersions = array(null, null);
if (preg_match('/^\d+\.\d+$/', $testVersion)) {
$arrTestVersions = array($testVersion, $testVersion);
}
elseif (preg_match('/^(\d+\.\d+)\s*-\s*(\d+\.\d+)$/', $testVersion,
$matches))
{
if (version_compare($matches[1], $matches[2], ">")) {
trigger_error("Invalid range in testVersion setting: '"
. $testVersion . "'", E_USER_WARNING);
}
else {
$arrTestVersions = array($matches[1], $matches[2]);
}
}
elseif (!$testVersion == "") {
trigger_error("Invalid testVersion setting: '" . $testVersion
. "'", E_USER_WARNING);
}
}
return $arrTestVersions;
}
public function supportsAbove($phpVersion)
{
$testVersion = $this->getTestVersion();
$testVersion = $testVersion[1];
if (is_null($testVersion)
|| version_compare($testVersion, $phpVersion) >= 0
) {
return true;
} else {
return false;
}
}//end supportsAbove()
public function supportsBelow($phpVersion)
{
$testVersion = $this->getTestVersion();
$testVersion = $testVersion[0];
if (!is_null($testVersion)
&& version_compare($testVersion, $phpVersion) <= 0
) {
return true;
} else {
return false;
}
}//end supportsBelow()
}//end class