diff --git a/.styleci.yml b/.styleci.yml index 0a5f029..17990f2 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -19,13 +19,11 @@ enabled: - linefeed - list_commas - logical_not_operators_with_successor_space - - long_array_syntax - lowercase_constants - lowercase_keywords - method_argument_space - multiline_array_trailing_comma - multiline_spaces_before_semicolon - - multiple_use - namespace_no_leading_whitespace - no_blank_lines_after_class_opening - no_empty_lines_after_phpdocs @@ -47,6 +45,7 @@ enabled: - remove_leading_slash_use - return - self_accessor + - short_array_syntax - short_echo_tag - short_tag - single_array_no_trailing_comma @@ -62,4 +61,4 @@ enabled: - unalign_equals - unary_operators_spaces - visibility - - whitespacy_lines + - whitespacy_lines \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a740bac..107dfd6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,13 +2,8 @@ language: php matrix: include: - - php: 5.3 - - php: 5.4 - - php: 5.5 - - php: 5.6 - php: 7.0 - php: 7.1 - - php: hhvm - php: nightly allow_failures: - php: nightly diff --git a/composer.json b/composer.json index 90948e0..5db0f53 100755 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ } ], "require": { - "php": ">=5.3.0" + "php": "^7.0" }, "require-dev": { "phpunit/phpunit": "*" diff --git a/src/CrawlerDetect.php b/src/CrawlerDetect.php index b189d90..3a5fda8 100644 --- a/src/CrawlerDetect.php +++ b/src/CrawlerDetect.php @@ -11,9 +11,7 @@ namespace Jaybizzle\CrawlerDetect; -use Jaybizzle\CrawlerDetect\Fixtures\Crawlers; -use Jaybizzle\CrawlerDetect\Fixtures\Exclusions; -use Jaybizzle\CrawlerDetect\Fixtures\Headers; +use Jaybizzle\CrawlerDetect\Fixtures\{Crawlers, Exclusions, Headers}; class CrawlerDetect { @@ -29,14 +27,14 @@ class CrawlerDetect * * @var array */ - protected $httpHeaders = array(); + protected $httpHeaders = []; /** * Store regex matches. * * @var array */ - protected $matches = array(); + protected $matches = []; /** * Crawlers object. @@ -60,9 +58,12 @@ class CrawlerDetect protected $uaHttpHeaders; /** - * Class constructor. + * Constuctor. + * + * @param array|null $headers + * @param string|null $userAgent */ - public function __construct(array $headers = null, $userAgent = null) + public function __construct(array $headers = null, string $userAgent = null) { $this->crawlers = new Crawlers(); $this->exclusions = new Exclusions(); @@ -77,7 +78,7 @@ public function __construct(array $headers = null, $userAgent = null) * * @param array $httpHeaders */ - public function setHttpHeaders($httpHeaders = null) + public function setHttpHeaders(array $httpHeaders = null) { // Use global _SERVER if $httpHeaders aren't defined. if (! is_array($httpHeaders) || ! count($httpHeaders)) { @@ -85,7 +86,7 @@ public function setHttpHeaders($httpHeaders = null) } // Clear existing headers. - $this->httpHeaders = array(); + $this->httpHeaders = []; // Only save HTTP headers. In PHP land, that means // only _SERVER vars that start with HTTP_. @@ -101,7 +102,7 @@ public function setHttpHeaders($httpHeaders = null) * * @return array */ - public function getUaHttpHeaders() + public function getUaHttpHeaders(): array { return $this->uaHttpHeaders->getAll(); } @@ -111,7 +112,7 @@ public function getUaHttpHeaders() * * @param string $userAgent */ - public function setUserAgent($userAgent = null) + public function setUserAgent(string $userAgent = null) { if (false === empty($userAgent)) { $this->userAgent = $userAgent; @@ -123,7 +124,7 @@ public function setUserAgent($userAgent = null) } } - $this->userAgent = (! empty($this->userAgent) ? trim($this->userAgent) : null); + $this->userAgent = ! empty($this->userAgent) ? trim($this->userAgent) : null; } } @@ -132,7 +133,7 @@ public function setUserAgent($userAgent = null) * * @return string */ - public function getRegex() + public function getRegex(): string { return '('.implode('|', $this->crawlers->getAll()).')'; } @@ -142,7 +143,7 @@ public function getRegex() * * @return string */ - public function getExclusions() + public function getExclusions(): string { return '('.implode('|', $this->exclusions->getAll()).')'; } @@ -154,7 +155,7 @@ public function getExclusions() * * @return bool */ - public function isCrawler($userAgent = null) + public function isCrawler(string $userAgent = null): bool { $agent = $userAgent ?: $this->userAgent; @@ -180,6 +181,6 @@ public function isCrawler($userAgent = null) */ public function getMatches() { - return isset($this->matches[0]) ? $this->matches[0] : null; + return $this->matches[0] ?? null; } } diff --git a/src/Fixtures/AbstractProvider.php b/src/Fixtures/AbstractProvider.php index 68e7498..30ded51 100644 --- a/src/Fixtures/AbstractProvider.php +++ b/src/Fixtures/AbstractProvider.php @@ -19,12 +19,13 @@ abstract class AbstractProvider * @var array */ protected $data; + /** * Return the data set. * * @return array */ - public function getAll() + public function getAll(): array { return $this->data; } diff --git a/src/Fixtures/Crawlers.php b/src/Fixtures/Crawlers.php index a4fd474..2d76da5 100644 --- a/src/Fixtures/Crawlers.php +++ b/src/Fixtures/Crawlers.php @@ -18,7 +18,7 @@ class Crawlers extends AbstractProvider * * @var array */ - protected $data = array( + protected $data = [ '.*Java.*outbrain', '008\/', '192.comAgent', @@ -211,6 +211,7 @@ class Crawlers extends AbstractProvider 'FeedChecker', 'Feedly', 'Feedspot', + 'Feedwind\/[0-9]', 'feeltiptop', 'Fetch API', 'Fetch\/[0-9]', @@ -329,6 +330,7 @@ class Crawlers extends AbstractProvider 'internetVista monitor', 'IODC', 'IOI', + 'IPS\/[0-9]', 'ips-agent', 'iqdb\/', 'Irokez', @@ -392,6 +394,7 @@ class Crawlers extends AbstractProvider 'Microsoft Windows Network Diagnostics', 'Mindjet', 'Miniflux', + 'mixdata dot com', 'Mnogosearch', 'mogimogi', 'Mojolicious (Perl)', @@ -448,6 +451,7 @@ class Crawlers extends AbstractProvider 'OrgProbe\/[0-9]', 'ow\.ly', 'ownCloud News', + 'OxfordCloudService\/[0-9]', 'Page Analyzer', 'Page Valet', 'page2rss', @@ -724,5 +728,5 @@ class Crawlers extends AbstractProvider 'ZnajdzFoto', 'ZyBorg', '[a-z0-9\-_]*((?