|
8 | 8 | * @SuppressWarnings docBlocks
|
9 | 9 | */
|
10 | 10 | abstract class CheckStyleConfig {
|
11 |
| - abstract public function getTestItems($test); |
12 |
| - abstract public function getConfigItems($config); |
13 |
| - abstract public function getTestExceptions($test); |
14 |
| - abstract public function getTest($test); |
15 |
| - abstract public function getTestLevel($test); |
16 |
| - abstract public function getTestRegExp($test); |
17 |
| - abstract public function getTestDeprecations($test); |
18 |
| - abstract public function getTestAliases($test); |
19 |
| - abstract public function getTestReplacements($test); |
20 |
| - abstract public function getTestProperty($test, $property); |
| 11 | + /** |
| 12 | + * Stores the check configuration. |
| 13 | + * @var array |
| 14 | + */ |
| 15 | + public $config = array(); |
| 16 | + |
| 17 | + /** |
| 18 | + * Return a true if the test exist, false otherwise. |
| 19 | + * |
| 20 | + * @param String $test name of the test |
| 21 | + * @return Boolean true if test exists. |
| 22 | + */ |
| 23 | + public function getTest($test) { |
| 24 | + return (array_key_exists(strtolower($test), $this->config)); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * Return a list of items associed with a test. |
| 29 | + * |
| 30 | + * @param String $test name of the test |
| 31 | + * @return array the list of items for this test. |
| 32 | + */ |
| 33 | + public function getTestItems($test) { |
| 34 | + $test = strtolower($test); |
| 35 | + return isset($this->config[$test]['item']) ? $this->config[$test]['item'] : false; |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Return a list of exceptionfor a test. |
| 40 | + * |
| 41 | + * @param String $test name of the test |
| 42 | + * @return array the list of exceptions for this test. |
| 43 | + */ |
| 44 | + public function getTestExceptions($test) { |
| 45 | + $test = strtolower($test); |
| 46 | + return isset($this->config[$test]['exception']) ? $this->config[$test]['exception'] : false; |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Return a list of items associed with a configuration. |
| 51 | + * |
| 52 | + * @param String $config name of the config |
| 53 | + * @return array the list of items for this config. |
| 54 | + */ |
| 55 | + public function getConfigItems($config) { |
| 56 | + $config = strtolower($config); |
| 57 | + return isset($this->config[$config]) ? $this->config[$config] : array(); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Return the level of severity of a test. |
| 62 | + * |
| 63 | + * @param String $test name of the test |
| 64 | + * @return the level of severity. |
| 65 | + */ |
| 66 | + public function getTestLevel($test) { |
| 67 | + $ret = WARNING; |
| 68 | + |
| 69 | + $test = strtolower($test); |
| 70 | + |
| 71 | + if (array_key_exists($test, $this->config) && array_key_exists('level', $this->config[$test])) { |
| 72 | + $ret = $this->config[$test]['level']; |
| 73 | + } |
| 74 | + |
| 75 | + $invalidLevels = array(ERROR, IGNORE, INFO, WARNING); |
| 76 | + |
| 77 | + if (!in_array($ret, $invalidLevels)) { |
| 78 | + echo "Invalid level for test " . $test . " : " . $ret; |
| 79 | + $ret = WARNING; |
| 80 | + } |
| 81 | + |
| 82 | + return $ret; |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Return the regular expression linked to the test. |
| 87 | + * |
| 88 | + * @param String $test name of the test |
| 89 | + * @return the regular expression. |
| 90 | + */ |
| 91 | + public function getTestRegExp($test) { |
| 92 | + $test = strtolower($test); |
| 93 | + $ret = ""; |
| 94 | + if (array_key_exists($test, $this->config) && array_key_exists('regexp', $this->config[$test])) { |
| 95 | + $ret = $this->config[$test]['regexp']; |
| 96 | + } |
| 97 | + |
| 98 | + return $ret; |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * Return the list of deprecated method and their replacement. |
| 103 | + * |
| 104 | + * @param String $test name of the test |
| 105 | + * @return the list of depecated values. |
| 106 | + */ |
| 107 | + public function getTestDeprecations($test) { |
| 108 | + $test = strtolower($test); |
| 109 | + $ret = ""; |
| 110 | + if (array_key_exists($test, $this->config)) { |
| 111 | + $ret = $this->config[$test]; |
| 112 | + } |
| 113 | + |
| 114 | + return $ret; |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Return the list of aliases and their replacement. |
| 119 | + * |
| 120 | + * @param String $test name of the test |
| 121 | + * @return the list of replaced values. |
| 122 | + */ |
| 123 | + public function getTestAliases($test) { |
| 124 | + $test = strtolower($test); |
| 125 | + $ret = ""; |
| 126 | + if (array_key_exists($test, $this->config)) { |
| 127 | + $ret = $this->config[$test]; |
| 128 | + } |
| 129 | + |
| 130 | + return $ret; |
| 131 | + } |
| 132 | + |
| 133 | + /** |
| 134 | + * Return the list of replacements. |
| 135 | + * |
| 136 | + * @param String $test name of the test |
| 137 | + * @return the list of replaced values. |
| 138 | + */ |
| 139 | + public function getTestReplacements($test) { |
| 140 | + $test = strtolower($test); |
| 141 | + $ret = ""; |
| 142 | + if (array_key_exists($test, $this->config)) { |
| 143 | + $ret = $this->config[$test]; |
| 144 | + } |
| 145 | + |
| 146 | + return $ret; |
| 147 | + } |
| 148 | + |
| 149 | + /** |
| 150 | + * Return the value of a property |
| 151 | + * |
| 152 | + * @param String $test name of the test |
| 153 | + * @param String $property name of the property |
| 154 | + * @return the value. |
| 155 | + */ |
| 156 | + public function getTestProperty($test, $property) { |
| 157 | + $test = strtolower($test); |
| 158 | + $property = strtolower($property); |
| 159 | + if (array_key_exists($test, $this->config) && array_key_exists($property, $this->config[$test])) { |
| 160 | + return $this->config[$test][$property]; |
| 161 | + } else { |
| 162 | + return false; |
| 163 | + } |
| 164 | + } |
21 | 165 | }
|
0 commit comments