@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | private $cacheExpire = 1; // 1 day |
| 14 | 14 | |
| 15 | - public function __construct(array $rules = []) |
|
| 15 | + public function __construct(array $rules = [ ]) |
|
| 16 | 16 | { |
| 17 | 17 | $this->initRules($rules); |
| 18 | 18 | } |
@@ -20,9 +20,9 @@ discard block |
||
| 20 | 20 | /** |
| 21 | 21 | * @param array $rules |
| 22 | 22 | */ |
| 23 | - public function initRules(array $rules = []) |
|
| 23 | + public function initRules(array $rules = [ ]) |
|
| 24 | 24 | { |
| 25 | - $this->rules = []; |
|
| 25 | + $this->rules = [ ]; |
|
| 26 | 26 | $this->addRules($rules); |
| 27 | 27 | } |
| 28 | 28 | |
@@ -33,15 +33,15 @@ discard block |
||
| 33 | 33 | { |
| 34 | 34 | foreach ($rules as $rule) { |
| 35 | 35 | try { |
| 36 | - $this->rules[] = new AdblockRule($rule); |
|
| 36 | + $this->rules[ ] = new AdblockRule($rule); |
|
| 37 | 37 | } catch (InvalidRuleException $e) { |
| 38 | 38 | // Skip invalid rules |
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | // Sort rules, exceptions first |
| 43 | - usort($this->rules, function (AdblockRule $a, AdblockRule $b) { |
|
| 44 | - return (int)$a->isException() < (int)$b->isException(); |
|
| 43 | + usort($this->rules, function(AdblockRule $a, AdblockRule $b) { |
|
| 44 | + return (int) $a->isException() < (int) $b->isException(); |
|
| 45 | 45 | }); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function shouldBlock($url) |
| 86 | 86 | { |
| 87 | - $rules = []; |
|
| 87 | + $rules = [ ]; |
|
| 88 | 88 | $url = trim($url); |
| 89 | 89 | |
| 90 | 90 | if (filter_var($url, FILTER_VALIDATE_URL) === false) { |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | if ($rule->matchUrl($url)) { |
| 100 | - $rules[] = $rule->getRule(); |
|
| 100 | + $rules[ ] = $rule->getRule(); |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | public function setCacheFolder($cacheFolder) |
| 133 | 133 | { |
| 134 | - $this->cacheFolder = rtrim($cacheFolder, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
|
| 134 | + $this->cacheFolder = rtrim($cacheFolder, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | public function clearCache() |
| 161 | 161 | { |
| 162 | 162 | if ($this->cacheFolder) { |
| 163 | - foreach (glob($this->cacheFolder . '*') as $file) { |
|
| 163 | + foreach (glob($this->cacheFolder.'*') as $file) { |
|
| 164 | 164 | unlink($file); |
| 165 | 165 | } |
| 166 | 166 | } |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | return @file_get_contents($url); |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - $cacheFile = $this->cacheFolder . basename($url) . md5($url); |
|
| 180 | + $cacheFile = $this->cacheFolder.basename($url).md5($url); |
|
| 181 | 181 | |
| 182 | 182 | if (file_exists($cacheFile) && (filemtime($cacheFile) > (time() - 60 * 24 * $this->cacheExpire))) { |
| 183 | 183 | // Cache file is less than five minutes old. |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | public function matchUrl($url) |
| 73 | 73 | { |
| 74 | 74 | try { |
| 75 | - return (boolean)preg_match('/' . $this->getRegex() . '/', $url); |
|
| 75 | + return (boolean) preg_match('/'.$this->getRegex().'/', $url); |
|
| 76 | 76 | } catch (\Exception $e) { |
| 77 | 77 | throw new \Exception($e); |
| 78 | 78 | } |
@@ -143,18 +143,18 @@ discard block |
||
| 143 | 143 | |
| 144 | 144 | // | in the end means the end of the address |
| 145 | 145 | if (Str::endsWith($regex, '|')) { |
| 146 | - $regex = mb_substr($regex, 0, mb_strlen($regex) - 1) . '$'; |
|
| 146 | + $regex = mb_substr($regex, 0, mb_strlen($regex) - 1).'$'; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | // || in the beginning means beginning of the domain name |
| 150 | 150 | if (Str::startsWith($regex, '||')) { |
| 151 | 151 | if (mb_strlen($regex) > 2) { |
| 152 | 152 | // http://tools.ietf.org/html/rfc3986#appendix-B |
| 153 | - $regex = "^([^:\/?#]+:)?(\/\/([^\/?#]*\.)?)?" . mb_substr($regex, 2); |
|
| 153 | + $regex = "^([^:\/?#]+:)?(\/\/([^\/?#]*\.)?)?".mb_substr($regex, 2); |
|
| 154 | 154 | } |
| 155 | 155 | // | in the beginning means start of the address |
| 156 | 156 | } elseif (Str::startsWith($regex, '|')) { |
| 157 | - $regex = '^' . mb_substr($regex, 1); |
|
| 157 | + $regex = '^'.mb_substr($regex, 1); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | // other | symbols should be escaped |