@@ -9,9 +9,9 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | private $cacheExpire = 1; // 1 day |
| 11 | 11 | |
| 12 | - public function __construct($rules = []) |
|
| 12 | + public function __construct($rules = [ ]) |
|
| 13 | 13 | { |
| 14 | - $this->rules = []; |
|
| 14 | + $this->rules = [ ]; |
|
| 15 | 15 | $this->addRules($rules); |
| 16 | 16 | } |
| 17 | 17 | |
@@ -22,15 +22,15 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | foreach ($rules as $rule) { |
| 24 | 24 | try { |
| 25 | - $this->rules[] = new AdblockRule($rule); |
|
| 25 | + $this->rules[ ] = new AdblockRule($rule); |
|
| 26 | 26 | } catch (InvalidRuleException $e) { |
| 27 | 27 | // Skip invalid rules |
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | // Sort rules, eceptions first |
| 32 | - usort($this->rules, function ($a, $b) { |
|
| 33 | - return (int)$a->isException() < (int)$b->isException(); |
|
| 32 | + usort($this->rules, function($a, $b) { |
|
| 33 | + return (int) $a->isException() < (int) $b->isException(); |
|
| 34 | 34 | }); |
| 35 | 35 | } |
| 36 | 36 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public function setCacheFolder($cacheFolder) |
| 124 | 124 | { |
| 125 | - $this->cacheFolder = rtrim($cacheFolder, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
|
| 125 | + $this->cacheFolder = rtrim($cacheFolder, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | public function clearCache() |
| 152 | 152 | { |
| 153 | 153 | if ($this->cacheFolder) { |
| 154 | - foreach (glob($this->cacheFolder . '*') as $file) { |
|
| 154 | + foreach (glob($this->cacheFolder.'*') as $file) { |
|
| 155 | 155 | unlink($file); |
| 156 | 156 | } |
| 157 | 157 | } |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | return @file_get_contents($url); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - $cacheFile = $this->cacheFolder . basename($url) . md5($url); |
|
| 171 | + $cacheFile = $this->cacheFolder.basename($url).md5($url); |
|
| 172 | 172 | |
| 173 | 173 | if (file_exists($cacheFile) && (filemtime($cacheFile) > (time() - 60 * 24 * $this->cacheExpire))) { |
| 174 | 174 | // Cache file is less than five minutes old. |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function matchUrl($url) |
| 45 | 45 | { |
| 46 | - return (boolean)preg_match( |
|
| 47 | - '/' . $this->getRegex() . '/', |
|
| 46 | + return (boolean) preg_match( |
|
| 47 | + '/'.$this->getRegex().'/', |
|
| 48 | 48 | $url |
| 49 | 49 | ); |
| 50 | 50 | } |
@@ -113,18 +113,18 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | // | in the end means the end of the address |
| 115 | 115 | if (Str::endsWith($regex, '|')) { |
| 116 | - $regex = mb_substr($regex, 0, mb_strlen($regex) - 1) . '$'; |
|
| 116 | + $regex = mb_substr($regex, 0, mb_strlen($regex) - 1).'$'; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | // || in the beginning means beginning of the domain name |
| 120 | 120 | if (Str::startsWith($regex, '||')) { |
| 121 | 121 | if (mb_strlen($regex) > 2) { |
| 122 | 122 | // http://tools.ietf.org/html/rfc3986#appendix-B |
| 123 | - $regex = "^([^:\/?#]+:)?(\/\/([^\/?#]*\.)?)?" . mb_substr($regex, 2); |
|
| 123 | + $regex = "^([^:\/?#]+:)?(\/\/([^\/?#]*\.)?)?".mb_substr($regex, 2); |
|
| 124 | 124 | } |
| 125 | 125 | // | in the beginning means start of the address |
| 126 | 126 | } elseif (Str::startsWith($regex, '|')) { |
| 127 | - $regex = '^' . mb_substr($regex, 1); |
|
| 127 | + $regex = '^'.mb_substr($regex, 1); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | // other | symbols should be escaped |