Skip to content

Commit

Permalink
Merge c20c5ae into e14b4da
Browse files Browse the repository at this point in the history
  • Loading branch information
JayBizzle committed Dec 5, 2016
2 parents e14b4da + c20c5ae commit 1049e5b
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 32 deletions.
5 changes: 2 additions & 3 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -62,4 +61,4 @@ enabled:
- unalign_equals
- unary_operators_spaces
- visibility
- whitespacy_lines
- whitespacy_lines
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
],
"require": {
"php": ">=5.3.0"
"php": "^7.0"
},
"require-dev": {
"phpunit/phpunit": "*"
Expand Down
33 changes: 17 additions & 16 deletions src/CrawlerDetect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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.
Expand All @@ -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();
Expand All @@ -77,15 +78,15 @@ 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)) {
$httpHeaders = $_SERVER;
}

// Clear existing headers.
$this->httpHeaders = array();
$this->httpHeaders = [];

// Only save HTTP headers. In PHP land, that means
// only _SERVER vars that start with HTTP_.
Expand All @@ -101,7 +102,7 @@ public function setHttpHeaders($httpHeaders = null)
*
* @return array
*/
public function getUaHttpHeaders()
public function getUaHttpHeaders(): array
{
return $this->uaHttpHeaders->getAll();
}
Expand All @@ -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;
Expand All @@ -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;
}
}

Expand All @@ -132,7 +133,7 @@ public function setUserAgent($userAgent = null)
*
* @return string
*/
public function getRegex()
public function getRegex(): string
{
return '('.implode('|', $this->crawlers->getAll()).')';
}
Expand All @@ -142,7 +143,7 @@ public function getRegex()
*
* @return string
*/
public function getExclusions()
public function getExclusions(): string
{
return '('.implode('|', $this->exclusions->getAll()).')';
}
Expand All @@ -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;

Expand All @@ -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;
}
}
3 changes: 2 additions & 1 deletion src/Fixtures/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions src/Fixtures/Crawlers.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Crawlers extends AbstractProvider
*
* @var array
*/
protected $data = array(
protected $data = [
'.*Java.*outbrain',
'008\/',
'192.comAgent',
Expand Down Expand Up @@ -211,6 +211,7 @@ class Crawlers extends AbstractProvider
'FeedChecker',
'Feedly',
'Feedspot',
'Feedwind\/[0-9]',
'feeltiptop',
'Fetch API',
'Fetch\/[0-9]',
Expand Down Expand Up @@ -329,6 +330,7 @@ class Crawlers extends AbstractProvider
'internetVista monitor',
'IODC',
'IOI',
'IPS\/[0-9]',
'ips-agent',
'iqdb\/',
'Irokez',
Expand Down Expand Up @@ -392,6 +394,7 @@ class Crawlers extends AbstractProvider
'Microsoft Windows Network Diagnostics',
'Mindjet',
'Miniflux',
'mixdata dot com',
'Mnogosearch',
'mogimogi',
'Mojolicious (Perl)',
Expand Down Expand Up @@ -448,6 +451,7 @@ class Crawlers extends AbstractProvider
'OrgProbe\/[0-9]',
'ow\.ly',
'ownCloud News',
'OxfordCloudService\/[0-9]',
'Page Analyzer',
'Page Valet',
'page2rss',
Expand Down Expand Up @@ -724,5 +728,5 @@ class Crawlers extends AbstractProvider
'ZnajdzFoto',
'ZyBorg',
'[a-z0-9\-_]*((?<!cu)bot|crawler|archiver|transcoder|spider|uptime|validator|fetcher)',
);
];
}
4 changes: 2 additions & 2 deletions src/Fixtures/Exclusions.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Exclusions extends AbstractProvider
*
* @var array
*/
protected $data = array(
protected $data = [
'Safari.[\d\.]*',
'Firefox.[\d\.]*',
'Chrome.[\d\.]*',
Expand Down Expand Up @@ -61,5 +61,5 @@ class Exclusions extends AbstractProvider
'Opera',
' \.NET[\d\.]*',
'\(|\)|;|,', // Remove the following characters ( ) : ,
);
];
}
4 changes: 2 additions & 2 deletions src/Fixtures/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Headers extends AbstractProvider
*
* @var array
*/
protected $data = array(
protected $data = [
// The default User-Agent string.
'HTTP_USER_AGENT',
// Header can occur on devices using Opera Mini.
Expand All @@ -32,5 +32,5 @@ class Headers extends AbstractProvider
'HTTP_X_UCBROWSER_DEVICE_UA',
// Sometimes, bots (especially Google) use a genuine user agent, but fill this header in with their email address
'HTTP_FROM',
);
];
}
5 changes: 5 additions & 0 deletions tests/crawlers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2404,3 +2404,8 @@ gvfs/1.20.3
request.js
Microsoft URL Control - 6.01.9782
git/2.1.4
IPS/1.0
OxfordCloudService/1.0
Mozilla/5.0 (compatible; informatique at mixdata dot com/0.6; +http://t.co/GSRLLKex24; informatique at mixdata dot com)
Mozilla/5.0 (compatible; Feedwind/2.0; +http://feed.mikle.com/support/description/)
Mozilla/5.0 (compatible; Feedwind/3.0; +http://feed.mikle.com/support/description/)

0 comments on commit 1049e5b

Please sign in to comment.