@@ -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 ($this->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 ($this->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 ($this->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 |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | /** |
| 70 | 70 | * @param string $url |
| 71 | 71 | * |
| 72 | - * @return integer |
|
| 72 | + * @return boolean |
|
| 73 | 73 | */ |
| 74 | 74 | public function shouldBlock($url) |
| 75 | 75 | { |
@@ -118,7 +118,6 @@ discard block |
||
| 118 | 118 | /** |
| 119 | 119 | * Set external resources cache expire (in days) |
| 120 | 120 | * |
| 121 | - * @param integer $expire |
|
| 122 | 121 | */ |
| 123 | 122 | public function setCacheExpire($expireInDays) |
| 124 | 123 | { |
@@ -7,11 +7,11 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | private $cacheExpire = 1; // 1 day |
| 9 | 9 | |
| 10 | - const CACHE_FOLDER = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR; |
|
| 10 | + const CACHE_FOLDER = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR; |
|
| 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 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | public function clearCache() |
| 132 | 132 | { |
| 133 | - foreach (glob(self::CACHE_FOLDER . '*') as $file) { |
|
| 133 | + foreach (glob(self::CACHE_FOLDER.'*') as $file) { |
|
| 134 | 134 | unlink($file); |
| 135 | 135 | } |
| 136 | 136 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | private function getCachedResource($url) |
| 144 | 144 | { |
| 145 | - $cacheFile = self::CACHE_FOLDER . basename($url) . md5($url); |
|
| 145 | + $cacheFile = self::CACHE_FOLDER.basename($url).md5($url); |
|
| 146 | 146 | |
| 147 | 147 | if (file_exists($cacheFile) && (filemtime($cacheFile) > (time() - 60 * 24 * $this->cacheExpire))) { |
| 148 | 148 | // Cache file is less than five minutes old. |