From 1a07ab1f665b045e7a115786cb31ea0bf938a23b Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 8 Sep 2017 16:29:19 +0100 Subject: [PATCH] Cleaning the package --- .gitattributes | 16 +++--- .scrutinizer.yml | 2 +- .travis.yml | 5 +- composer.json | 25 +++------ phpunit.xml => phpunit.xml.dist | 0 src/Entities/Locales.php | 2 +- src/Helpers/TextReplacer.php | 3 + src/Http/Controllers/Admin/Controller.php | 7 ++- .../Controllers/Admin/FootersController.php | 10 +--- .../Controllers/Admin/PagesController.php | 11 +--- .../Controllers/Admin/RedirectsController.php | 10 +--- .../Controllers/Admin/SettingsController.php | 1 + .../Middleware/SeoSpamBlockerMiddleware.php | 55 ------------------- .../Admin/Footers/CreateFooterRequest.php | 1 + .../Admin/Footers/FooterFormRequest.php | 8 +-- .../Admin/Footers/UpdateFooterRequest.php | 1 + src/Http/Requests/Admin/FormRequest.php | 3 +- .../Admin/Pages/CreatePageRequest.php | 1 + .../Admin/Pages/UpdatePageRequest.php | 1 + .../Admin/Redirects/CreateRedirectRequest.php | 1 + .../Admin/Redirects/UpdateRedirectRequest.php | 1 + src/Http/Routes/Admin/FootersRoutes.php | 2 +- src/Http/Routes/Admin/MetasRoutes.php | 2 +- src/Http/Routes/Admin/PagesRoutes.php | 2 +- src/Http/Routes/Admin/RedirectsRoutes.php | 2 +- src/Http/Routes/Admin/SettingsRoutes.php | 1 + src/Http/Routes/Admin/SpammersRoutes.php | 1 + src/Http/Routes/Front/FootersRoutes.php | 4 +- src/Models/Footer.php | 3 + src/Models/Meta.php | 1 + src/Models/Page.php | 2 + src/Models/Presenters/FooterPresenter.php | 1 + src/Models/Presenters/PagePresenter.php | 6 +- src/Models/Redirect.php | 8 +-- src/Providers/RouteServiceProvider.php | 1 + .../Front/FooterWidgetComposer.php | 6 +- src/ViewComposers/ViewComposer.php | 17 ++---- .../SeoSpamBlockerMiddlewareTest.php | 26 +++++---- tests/SeoServiceProviderTest.php | 20 ++++--- tests/TestCase.php | 17 ++++-- 40 files changed, 119 insertions(+), 167 deletions(-) rename phpunit.xml => phpunit.xml.dist (100%) delete mode 100644 src/Http/Middleware/SeoSpamBlockerMiddleware.php diff --git a/.gitattributes b/.gitattributes index 301e170..e286af4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,8 +1,8 @@ -/_docs export-ignore -/tests export-ignore -/.gitattributes export-ignore -/.gitignore export-ignore -/.scrutinizer.yml export-ignore -/.travis.yml export-ignore -/CONTRIBUTING.md export-ignore -/phpunit.xml export-ignore +/_docs export-ignore +/tests export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.scrutinizer.yml export-ignore +/.travis.yml export-ignore +/CONTRIBUTING.md export-ignore +/phpunit.xml.dist export-ignore diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 69d4755..282131b 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -22,7 +22,7 @@ checks: tools: external_code_coverage: timeout: 600 - runs: 4 + runs: 3 php_code_sniffer: enabled: true config: diff --git a/.travis.yml b/.travis.yml index 489c6d5..a4500e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/composer.json b/composer.json index 5fe96da..1f07055 100644 --- a/composer.json +++ b/composer.json @@ -17,14 +17,15 @@ "license": "MIT", "require": { "php": ">=5.6.4", - "arcanedev/laravel-seo": "~0.5", - "arcanedev/spam-blocker": "~1.3", - "arcanesoft/auth": "~3.0", - "arcanesoft/core": "~2.4" + "arcanedev/laravel-seo": "~0.5.0", + "arcanedev/spam-blocker": "~1.3.0", + "arcanesoft/auth": "~3.0.0", + "arcanesoft/core": "~2.6.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": { @@ -35,15 +36,5 @@ "psr-4": { "Arcanesoft\\Seo\\Tests\\": "tests/" } - }, - "scripts": { - "testbench": "composer require --dev \"orchestra/testbench-browser-kit=~3.4.0\"" - }, - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "minimum-stability": "dev", - "prefer-stable" : true + } } diff --git a/phpunit.xml b/phpunit.xml.dist similarity index 100% rename from phpunit.xml rename to phpunit.xml.dist diff --git a/src/Entities/Locales.php b/src/Entities/Locales.php index d46a097..8df3707 100644 --- a/src/Entities/Locales.php +++ b/src/Entities/Locales.php @@ -22,7 +22,7 @@ class Locales */ public static function all() { - return new Collection(trans("seo::locales")); + return new Collection(trans('seo::locales')); } /** diff --git a/src/Helpers/TextReplacer.php b/src/Helpers/TextReplacer.php index b3b22a1..53e721d 100644 --- a/src/Helpers/TextReplacer.php +++ b/src/Helpers/TextReplacer.php @@ -14,6 +14,7 @@ class TextReplacer | Properties | ----------------------------------------------------------------- */ + /** @var array */ protected $replacements; @@ -21,6 +22,7 @@ class TextReplacer | Constructor | ----------------------------------------------------------------- */ + /** * TextReplacer constructor. * @@ -79,6 +81,7 @@ protected function mergeReplacements(array $replacements) | Main Methods | ----------------------------------------------------------------- */ + /** * Make the instance. * diff --git a/src/Http/Controllers/Admin/Controller.php b/src/Http/Controllers/Admin/Controller.php index ff0da11..347271a 100644 --- a/src/Http/Controllers/Admin/Controller.php +++ b/src/Http/Controllers/Admin/Controller.php @@ -1,5 +1,6 @@ - */ -class SeoSpamBlockerMiddleware -{ - /* ----------------------------------------------------------------- - | Properties - | ----------------------------------------------------------------- - */ - /** @var \Arcanedev\SpamBlocker\Contracts\SpamBlocker */ - protected $blocker; - - /* ----------------------------------------------------------------- - | Constructor - | ----------------------------------------------------------------- - */ - /** - * SeoSpamBlockerMiddleware constructor. - * - * @param \Arcanedev\SpamBlocker\Contracts\SpamBlocker $blocker - */ - public function __construct(SpamBlocker $blocker) - { - $this->blocker = $blocker; - } - - /* ----------------------------------------------------------------- - | Main Methods - | ----------------------------------------------------------------- - */ - /** - * Handle an incoming request. - * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * - * @return mixed - */ - public function handle(Request $request, Closure $next) - { - if ($this->blocker->isBlocked($request->headers->get('referer'))) - return abort(401, 'Unauthorized.'); - - return $next($request); - } -} diff --git a/src/Http/Requests/Admin/Footers/CreateFooterRequest.php b/src/Http/Requests/Admin/Footers/CreateFooterRequest.php index cc1fa76..c1a068c 100644 --- a/src/Http/Requests/Admin/Footers/CreateFooterRequest.php +++ b/src/Http/Requests/Admin/Footers/CreateFooterRequest.php @@ -12,6 +12,7 @@ class CreateFooterRequest extends FooterFormRequest | Main Methods | ----------------------------------------------------------------- */ + /** * Determine if the user is authorized to make this request. * diff --git a/src/Http/Requests/Admin/Footers/FooterFormRequest.php b/src/Http/Requests/Admin/Footers/FooterFormRequest.php index 1ca0275..32440bd 100644 --- a/src/Http/Requests/Admin/Footers/FooterFormRequest.php +++ b/src/Http/Requests/Admin/Footers/FooterFormRequest.php @@ -38,10 +38,10 @@ public function getValidatedData() */ protected function getPageRule() { - $existsRule = Rule::exists($this->getTablePrefix().'pages', 'id'); - - if ($this->has('locale')) - $existsRule = $existsRule->where('locale', $this->get('locale', config('app.locale'))); + $existsRule = Rule::exists($this->getTablePrefix().'pages', 'id')->where(function ($query) { + if ($this->has('locale')) + $query->where('locale', $this->get('locale', config('app.locale'))); + }); return ['required', 'integer', $existsRule]; } diff --git a/src/Http/Requests/Admin/Footers/UpdateFooterRequest.php b/src/Http/Requests/Admin/Footers/UpdateFooterRequest.php index 2598efe..416c145 100644 --- a/src/Http/Requests/Admin/Footers/UpdateFooterRequest.php +++ b/src/Http/Requests/Admin/Footers/UpdateFooterRequest.php @@ -12,6 +12,7 @@ class UpdateFooterRequest extends FooterFormRequest | Main Methods | ----------------------------------------------------------------- */ + /** * Determine if the user is authorized to make this request. * diff --git a/src/Http/Requests/Admin/FormRequest.php b/src/Http/Requests/Admin/FormRequest.php index 0a30eee..63c06d3 100644 --- a/src/Http/Requests/Admin/FormRequest.php +++ b/src/Http/Requests/Admin/FormRequest.php @@ -1,6 +1,6 @@ bind('seo_footer', function ($id) { - return Footer::findOrFail($id); + return Footer::query()->findOrFail($id); }); } diff --git a/src/Http/Routes/Admin/MetasRoutes.php b/src/Http/Routes/Admin/MetasRoutes.php index bcc291a..1986c9c 100644 --- a/src/Http/Routes/Admin/MetasRoutes.php +++ b/src/Http/Routes/Admin/MetasRoutes.php @@ -24,7 +24,7 @@ public static function bindings() $registrar = new static; $registrar->bind('seo_meta', function ($id) { - return Meta::findOrFail($id); + return Meta::query()->findOrFail($id); }); } diff --git a/src/Http/Routes/Admin/PagesRoutes.php b/src/Http/Routes/Admin/PagesRoutes.php index 8497849..6b92353 100644 --- a/src/Http/Routes/Admin/PagesRoutes.php +++ b/src/Http/Routes/Admin/PagesRoutes.php @@ -24,7 +24,7 @@ public static function bindings() $registrar = new static; $registrar->bind('seo_page', function ($id) { - return Page::findOrFail($id); + return Page::query()->findOrFail($id); }); } diff --git a/src/Http/Routes/Admin/RedirectsRoutes.php b/src/Http/Routes/Admin/RedirectsRoutes.php index 51ceb33..0b772b6 100644 --- a/src/Http/Routes/Admin/RedirectsRoutes.php +++ b/src/Http/Routes/Admin/RedirectsRoutes.php @@ -24,7 +24,7 @@ public static function bindings() $registrar = new static; $registrar->bind('seo_redirect', function ($id) { - return Redirect::findOrFail($id); + return Redirect::query()->findOrFail($id); }); } diff --git a/src/Http/Routes/Admin/SettingsRoutes.php b/src/Http/Routes/Admin/SettingsRoutes.php index 0c429a9..1f17540 100644 --- a/src/Http/Routes/Admin/SettingsRoutes.php +++ b/src/Http/Routes/Admin/SettingsRoutes.php @@ -14,6 +14,7 @@ class SettingsRoutes extends RouteRegistrar | Main Methods | ----------------------------------------------------------------- */ + /** * Define the routes for the application. */ diff --git a/src/Http/Routes/Admin/SpammersRoutes.php b/src/Http/Routes/Admin/SpammersRoutes.php index abefc20..debc230 100644 --- a/src/Http/Routes/Admin/SpammersRoutes.php +++ b/src/Http/Routes/Admin/SpammersRoutes.php @@ -14,6 +14,7 @@ class SpammersRoutes extends RouteRegistrar | Main Methods | ----------------------------------------------------------------- */ + /** * Define the routes for the application. */ diff --git a/src/Http/Routes/Front/FootersRoutes.php b/src/Http/Routes/Front/FootersRoutes.php index 0636810..1800196 100644 --- a/src/Http/Routes/Front/FootersRoutes.php +++ b/src/Http/Routes/Front/FootersRoutes.php @@ -15,13 +15,15 @@ class FootersRoutes extends RouteRegistrar | Main Methods | ----------------------------------------------------------------- */ + /** * Define the routes for the application. */ public function map() { $this->bind('seo_footer_uri', function ($uri) { - return Footer::where('uri', $uri) + return Footer::query() + ->where('uri', $uri) ->where('locale', config('app.locale')) ->firstOrFail(); }); diff --git a/src/Models/Footer.php b/src/Models/Footer.php index 81eada2..23ce5a0 100644 --- a/src/Models/Footer.php +++ b/src/Models/Footer.php @@ -25,6 +25,7 @@ class Footer extends AbstractModel | Traits | ----------------------------------------------------------------- */ + use Seoable, Presenters\FooterPresenter; @@ -32,6 +33,7 @@ class Footer extends AbstractModel | Properties | ----------------------------------------------------------------- */ + /** * The attributes that are mass assignable. * @@ -55,6 +57,7 @@ class Footer extends AbstractModel | Constructor | ----------------------------------------------------------------- */ + /** * Footer constructor. * diff --git a/src/Models/Meta.php b/src/Models/Meta.php index 13dfa35..69026a8 100644 --- a/src/Models/Meta.php +++ b/src/Models/Meta.php @@ -14,5 +14,6 @@ class Meta extends BaseMeta | Traits | ----------------------------------------------------------------- */ + use Presenters\MetaPresenter; } diff --git a/src/Models/Page.php b/src/Models/Page.php index 61e247a..af5f72f 100644 --- a/src/Models/Page.php +++ b/src/Models/Page.php @@ -21,12 +21,14 @@ class Page extends AbstractModel | Traits | ----------------------------------------------------------------- */ + use Presenters\PagePresenter; /* ----------------------------------------------------------------- | Properties | ----------------------------------------------------------------- */ + /** * The attributes that are mass assignable. * diff --git a/src/Models/Presenters/FooterPresenter.php b/src/Models/Presenters/FooterPresenter.php index 25cbfc2..41b3801 100644 --- a/src/Models/Presenters/FooterPresenter.php +++ b/src/Models/Presenters/FooterPresenter.php @@ -20,6 +20,7 @@ trait FooterPresenter | Accessors | ----------------------------------------------------------------- */ + /** * Get the `locale_name` attribute. * diff --git a/src/Models/Presenters/PagePresenter.php b/src/Models/Presenters/PagePresenter.php index e4e59b4..5445c8f 100644 --- a/src/Models/Presenters/PagePresenter.php +++ b/src/Models/Presenters/PagePresenter.php @@ -20,6 +20,7 @@ trait PagePresenter | Accessors | ----------------------------------------------------------------- */ + /** * Get the `locale_name` attribute. * @@ -44,6 +45,7 @@ public function getContentPreviewAttribute() | Other Methods | ----------------------------------------------------------------- */ + /** * Render the content. * @@ -51,7 +53,7 @@ public function getContentPreviewAttribute() * * @return string */ - public function renderContent(array $replacements) + protected function renderContent(array $replacements) { return $this->getContentReplacer()->replace($this->content, array_merge([ 'app_name' => config('app.name'), @@ -67,7 +69,7 @@ public function renderContent(array $replacements) * * @return \Arcanesoft\Seo\Helpers\TextReplacer */ - public static function getContentReplacer() + protected static function getContentReplacer() { return TextReplacer::make( config('arcanesoft.seo.pages.replacer', []) diff --git a/src/Models/Redirect.php b/src/Models/Redirect.php index d6aba50..9ed5864 100644 --- a/src/Models/Redirect.php +++ b/src/Models/Redirect.php @@ -24,10 +24,8 @@ class Redirect extends BaseRedirect */ public static function createRedirect(array $attributes) { - $redirect = new static($attributes); - - $redirect->save(); - - return $redirect; + return tap(new static($attributes), function (self $redirect) { + $redirect->save(); + }); } } diff --git a/src/Providers/RouteServiceProvider.php b/src/Providers/RouteServiceProvider.php index 1acc65a..4a0f089 100644 --- a/src/Providers/RouteServiceProvider.php +++ b/src/Providers/RouteServiceProvider.php @@ -44,6 +44,7 @@ public function map() | Other Methods | ----------------------------------------------------------------- */ + /** * Register the route bindings. */ diff --git a/src/ViewComposers/Front/FooterWidgetComposer.php b/src/ViewComposers/Front/FooterWidgetComposer.php index 7c3295e..80dfa1b 100644 --- a/src/ViewComposers/Front/FooterWidgetComposer.php +++ b/src/ViewComposers/Front/FooterWidgetComposer.php @@ -16,12 +16,14 @@ class FooterWidgetComposer extends ViewComposer | Constants | ----------------------------------------------------------------- */ + const VIEW = 'seo::public._composers.widgets.footer-widget'; /* ----------------------------------------------------------------- | Main Methods | ----------------------------------------------------------------- */ + /** * Compose the view. * @@ -29,8 +31,6 @@ class FooterWidgetComposer extends ViewComposer */ public function compose(View $view) { - $this->view = $view; - - $this->view->with('seoFooters', Footer::all()); + $view->with('seoFooters', Footer::all()); } } diff --git a/src/ViewComposers/ViewComposer.php b/src/ViewComposers/ViewComposer.php index 64cad2b..9316c56 100644 --- a/src/ViewComposers/ViewComposer.php +++ b/src/ViewComposers/ViewComposer.php @@ -11,16 +11,10 @@ */ class ViewComposer { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ - /** - * The View instance. - * - * @var \Illuminate\Contracts\View\View - */ - protected $view; /** * Caching time. @@ -29,10 +23,11 @@ class ViewComposer */ protected $minutes = 5; - /* ------------------------------------------------------------------------------------------------ - | Other Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Other Methods + | ----------------------------------------------------------------- */ + /** * Cache the results. * diff --git a/tests/Http/Middleware/SeoSpamBlockerMiddlewareTest.php b/tests/Http/Middleware/SeoSpamBlockerMiddlewareTest.php index c457264..c913893 100644 --- a/tests/Http/Middleware/SeoSpamBlockerMiddlewareTest.php +++ b/tests/Http/Middleware/SeoSpamBlockerMiddlewareTest.php @@ -10,38 +10,42 @@ */ class SeoSpamBlockerMiddlewareTest extends TestCase { - /* ------------------------------------------------------------------------------------------------ - | Test Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Tests + | ----------------------------------------------------------------- */ + /** @test */ public function it_can_accept_valid_referral() { - $this->callReferer('http://www.google.com'); + $response = $this->callReferer('http://www.google.com'); - $this->assertResponseOk(); + $response->assertSuccessful(); } /** @test */ public function it_can_deny_a_spammer_referral() { - $this->callReferer("http://0n-line.tv"); + $response = $this->callReferer("http://0n-line.tv"); - $this->assertResponseStatus(401); + $response->assertStatus(401); } - /* ------------------------------------------------------------------------------------------------ - | Other Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Other Methods + | ----------------------------------------------------------------- */ + /** * @param string $referer * @param string $url * @param string $method + * + * @return \Illuminate\Foundation\Testing\TestResponse */ private function callReferer($referer, $url = '/', $method = 'GET') { - $this->call($method, $url, [], [], [], [ + return $this->call($method, $url, [], [], [], [ 'HTTP_REFERER' => $referer, ]); } diff --git a/tests/SeoServiceProviderTest.php b/tests/SeoServiceProviderTest.php index cd1aca6..00c77c8 100644 --- a/tests/SeoServiceProviderTest.php +++ b/tests/SeoServiceProviderTest.php @@ -1,4 +1,5 @@ setUpRoutes($app); } + /* ----------------------------------------------------------------- + | Other Methods + | ----------------------------------------------------------------- + */ + /** * Setup routes. * @@ -68,7 +73,7 @@ private function setUpRoutes($app) { /** @var \Orchestra\Testbench\Http\Kernel $httpKernel */ $httpKernel = $app->make('Illuminate\Contracts\Http\Kernel'); - $httpKernel->pushMiddleware(\Arcanesoft\Seo\Http\Middleware\SeoSpamBlockerMiddleware::class); + $httpKernel->pushMiddleware(\Arcanedev\SpamBlocker\Middleware\BlockReferralSpam::class); $app['router']->get('/', function () { return 'Home page';