Skip to content

Commit a67aff6

Browse files
committed
* Various CS fix and better exception handling
1 parent 964e499 commit a67aff6

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

lib/IDS/Event.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class Event implements \Countable, \IteratorAggregate
105105
*
106106
* @return void
107107
*/
108-
public function __construct($name, $value, Array $filters)
108+
public function __construct($name, $value, array $filters)
109109
{
110110
if (!is_scalar($name)) {
111111
throw new \InvalidArgumentException(

lib/IDS/Filter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,22 @@ public function __construct($id, $rule, $description, array $tags, $impact)
108108
* Matches given string against the filter rule the specific object of this
109109
* class represents
110110
*
111-
* @param string $string the string to match
111+
* @param string $input the string input to match
112112
*
113113
* @throws InvalidArgumentException if argument is no string
114114
* @return boolean
115115
*/
116-
public function match($string)
116+
public function match($input)
117117
{
118-
if (!is_string($string)) {
118+
if (!is_string($input)) {
119119
throw new \InvalidArgumentException(
120-
'Invalid argument. Expected a string, received ' . gettype($string)
120+
'Invalid argument. Expected a string, received ' . gettype($input)
121121
);
122122
}
123123

124124
return (bool) preg_match(
125125
'/' . $this->getRule() . '/ms',
126-
strtolower($string)
126+
strtolower($input)
127127
);
128128
}
129129

lib/IDS/Filter/Storage.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,10 @@ final public function __construct(Init $init)
9898
{
9999
if ($init->config) {
100100

101-
$caching = isset($init->config['Caching']['caching']) ?
102-
$init->config['Caching']['caching'] : 'none';
101+
$caching = isset($init->config['Caching']['caching']) ? $init->config['Caching']['caching'] : 'none';
103102

104103
$type = $init->config['General']['filter_type'];
105-
$this->source = $init->getBasePath()
106-
. $init->config['General']['filter_path'];
104+
$this->source = $init->getBasePath(). $init->config['General']['filter_path'];
107105

108106
if ($caching && $caching !== 'none') {
109107
$this->cacheSettings = $init->config['Caching'];
@@ -186,6 +184,7 @@ private function isCached()
186184
* If caching mode is enabled the result will be cached to increase
187185
* the performance.
188186
*
187+
* @throws \InvalidArgumentException if source file doesn't exist
189188
* @throws \RuntimeException if problems with fetching the XML data occur
190189
* @return object $this
191190
*/
@@ -205,14 +204,19 @@ public function getFilterFromXML()
205204
if (file_exists($this->source)) {
206205
if (LIBXML_VERSION >= 20621) {
207206
$filters = simplexml_load_file(
208-
$this->source,
209-
null,
210-
LIBXML_COMPACT
211-
);
207+
$this->source,
208+
null,
209+
LIBXML_COMPACT
210+
);
212211
} else {
213212
$filters = simplexml_load_file($this->source);
214213
}
215214
}
215+
216+
throw new \InvalidArgumentException(
217+
sprintf( 'Invalid config: %s doesn\'t exist. ',
218+
$this->source )
219+
);
216220
}
217221

218222
/*
@@ -304,12 +308,12 @@ public function getFilterFromJson()
304308
if (!$filters) {
305309
if (file_exists($this->source)) {
306310
$filters = json_decode(file_get_contents($this->source));
307-
} else {
308-
throw new \RuntimeException(
309-
'JSON data could not be loaded.' .
310-
' Make sure you specified the correct path.'
311-
);
312311
}
312+
313+
throw new \RuntimeException(
314+
'JSON data could not be loaded.' .
315+
' Make sure you specified the correct path.'
316+
);
313317
}
314318

315319
if (!$filters) {

lib/IDS/Monitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public function __construct(array $request, Init $init, array $tags = null)
225225
);
226226
}
227227

228-
$this->report = new Report;
228+
$this->report = new Report();
229229
}
230230

231231
/**

lib/IDS/Report.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Report implements \Countable, \IteratorAggregate
7676
* Impact level
7777
*
7878
* The impact level is calculated on demand by adding the results of the
79-
* event objects on IDS_Report->getImpact()
79+
* event objects on IDS\Report->getImpact()
8080
*
8181
* @var integer
8282
*/

0 commit comments

Comments
 (0)