Skip to content

Commit

Permalink
Merge pull request #5 from ARCANEDEV/patch-1
Browse files Browse the repository at this point in the history
Cleaning the package
  • Loading branch information
arcanedev-maroc authored Sep 7, 2017
2 parents b767c5a + 072d1d6 commit 32a7b45
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
.gitignore export-ignore
.scrutinizer.yml export-ignore
.travis.yml export-ignore
phpunit.xml export-ignore
phpunit.xml.dist export-ignore
CONTRIBUTING.md export-ignore
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ matrix:
allow_failures:
- php: nightly

env:
- TESTBENCH_VERSION=3.4.*

before_script:
- travis_retry composer self-update
- travis_retry composer require --prefer-source --no-interaction --dev "orchestra/testbench-browser-kit:${TESTBENCH_VERSION}"
- travis_retry composer install --prefer-source --no-interaction

script:
- composer validate
Expand Down
19 changes: 5 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
"license": "MIT",
"require": {
"php": ">=5.6.4",
"arcanedev/support": "~4.0",
"arcanedev/support": "~4.1.0",
"piwik/referrer-spam-blacklist": "~1.0"
},
"require-dev": {
"phpunit/phpcov": "~3.0",
"phpunit/phpunit": "~5.0"
"orchestra/testbench": "~3.4.0",
"phpunit/phpcov": "~3.0",
"phpunit/phpunit": "~5.0"
},
"autoload": {
"psr-4": {
Expand All @@ -31,15 +32,5 @@
"psr-4": {
"Arcanedev\\SpamBlocker\\Tests\\": "tests/"
}
},
"scripts": {
"testbench": "composer require --dev \"orchestra/testbench-browser-kit=~3.0\""
},
"extra": {
"branch-alias": {
"dev-master": "1.3-dev"
}
},
"minimum-stability": "dev",
"prefer-stable" : true
}
}
22 changes: 14 additions & 8 deletions config/spam-blocker.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
<?php

return [
/* ------------------------------------------------------------------------------------------------

/* -----------------------------------------------------------------
| Source
| ------------------------------------------------------------------------------------------------
| -----------------------------------------------------------------
| The blacklisted spammers source file.
*/

'source' => base_path('vendor/piwik/referrer-spam-blacklist/spammers.txt'),

/* ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Include
| ------------------------------------------------------------------------------------------------
| -----------------------------------------------------------------
| Include new hosts to the blacklist.
*/

'include' => [
//
],

/* ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Exclude
| ------------------------------------------------------------------------------------------------
| -----------------------------------------------------------------
| Exclude hosts from the blacklist.
*/

'exclude' => [
//
],

/* ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Cache
| ------------------------------------------------------------------------------------------------
| -----------------------------------------------------------------
*/

'cache' => [
'key' => 'arcanedev.spammers',

'expires' => 24 * 60, // 1 day
],

];
File renamed without changes.
12 changes: 7 additions & 5 deletions src/Contracts/SpamBlocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
*/
interface SpamBlocker
{
/* ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Getters & Setters
| ------------------------------------------------------------------------------------------------
| -----------------------------------------------------------------
*/

/**
* Get the loaded spammers.
*
Expand Down Expand Up @@ -60,10 +61,11 @@ public function getExcludes();
*/
public function setExcludes(array $excludes);

/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/

/**
* Load spammers.
*
Expand Down
44 changes: 30 additions & 14 deletions src/Entities/Spammer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,32 @@

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
use JsonSerializable;

/**
* Class Spammer
*
* @package Entities
* @author ARCANEDEV <[email protected]>
*/
class Spammer implements Arrayable, Jsonable
class Spammer implements Arrayable, Jsonable, JsonSerializable
{
/* ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Properties
| ------------------------------------------------------------------------------------------------
| -----------------------------------------------------------------
*/

/** @var string */
protected $host;

/** @var bool */
protected $blocked;

/* ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Constructor
| ------------------------------------------------------------------------------------------------
| -----------------------------------------------------------------
*/

/**
* Spammer constructor.
*
Expand All @@ -37,10 +40,11 @@ public function __construct($host, $blocked)
$this->setBlocked($blocked);
}

/* ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Getters & Setters
| ------------------------------------------------------------------------------------------------
| -----------------------------------------------------------------
*/

/**
* Get the host url.
*
Expand Down Expand Up @@ -89,10 +93,11 @@ public function setBlocked($blocked)
return $this;
}

/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/

/**
* Make a spammer instance.
*
Expand All @@ -118,10 +123,11 @@ public function isSameHost($host)
return $this->host() === trim(utf8_encode($host));
}

/* ------------------------------------------------------------------------------------------------
| Other Functions
| ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Other Methods
| -----------------------------------------------------------------
*/

/**
* Get the instance as an array.
*
Expand All @@ -135,6 +141,16 @@ public function toArray()
];
}

/**
* Convert the object into something JSON serializable.
*
* @return array
*/
public function jsonSerialize()
{
return $this->toArray();
}

/**
* Convert the object to its JSON representation.
*
Expand All @@ -144,6 +160,6 @@ public function toArray()
*/
public function toJson($options = 0)
{
return json_encode($this->toArray(), $options);
return json_encode($this->jsonSerialize(), $options);
}
}
14 changes: 8 additions & 6 deletions src/Entities/Spammers.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
*/
class Spammers extends Collection
{
/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/

/**
* Load the items.
*
Expand Down Expand Up @@ -181,10 +182,11 @@ public function exists($host)
);
}

/* ------------------------------------------------------------------------------------------------
| Other Functions
| ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Other Methods
| -----------------------------------------------------------------
*/

/**
* Sanitize the host url.
*
Expand Down
3 changes: 2 additions & 1 deletion src/Facades/SpamBlocker.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Arcanedev\SpamBlocker\Facades;

use Arcanedev\SpamBlocker\Contracts\SpamBlocker as SpamBlockerContract;
use Illuminate\Support\Facades\Facade;

/**
Expand All @@ -15,5 +16,5 @@ class SpamBlocker extends Facade
*
* @return string
*/
protected static function getFacadeAccessor() { return \Arcanedev\SpamBlocker\Contracts\SpamBlocker::class; }
protected static function getFacadeAccessor() { return SpamBlockerContract::class; }
}
25 changes: 13 additions & 12 deletions src/Middleware/BlockReferralSpam.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
*/
class BlockReferralSpam
{
/* ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Properties
| ------------------------------------------------------------------------------------------------
| -----------------------------------------------------------------
*/

/** @var \Arcanedev\SpamBlocker\Contracts\SpamBlocker */
private $blocker;

/* ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Constructor
| ------------------------------------------------------------------------------------------------
| -----------------------------------------------------------------
*/

/**
* BlockReferralSpam constructor.
*
Expand All @@ -33,10 +35,11 @@ public function __construct(SpamBlocker $blocker)
$this->blocker = $blocker;
}

/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/

/**
* Handle an incoming request.
*
Expand All @@ -49,10 +52,8 @@ public function handle(Request $request, Closure $next)
{
$referer = $request->headers->get('referer');

if ($this->blocker->isBlocked($referer)) {
return response('Unauthorized.', 401);
}

return $next($request);
return $this->blocker->isBlocked($referer)
? response('Unauthorized.', 401)
: $next($request);
}
}
Loading

0 comments on commit 32a7b45

Please sign in to comment.