diff --git a/composer.json b/composer.json index 8fdf06a..5d57c7c 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,9 @@ "orchestra/testbench": "^8.0|^9.0", "phpunit/phpunit": "^10.0|^11.0", "larastan/larastan": "^2.0", - "pestphp/pest-plugin-laravel": "^2.3" + "pestphp/pest-plugin-laravel": "^2.3", + "rector/rector": "^1.2", + "driftingly/rector-laravel": "^1.2" }, "autoload": { "psr-4": { diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..0e91343 --- /dev/null +++ b/rector.php @@ -0,0 +1,20 @@ +withPaths([ + __DIR__ . '/config', + __DIR__ . '/routes', + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + // uncomment to reach your current PHP version + //->withPhpSets(php80: true) + ->withPreparedSets( + deadCode: true, + codeQuality: true + ) + ->withTypeCoverageLevel(0); diff --git a/src/Classes/Builder.php b/src/Classes/Builder.php index b55df51..3f8c5b5 100644 --- a/src/Classes/Builder.php +++ b/src/Classes/Builder.php @@ -411,7 +411,7 @@ public function make(): ShortURL $shortURL = new ShortURL($data); - if ($this->beforeCreateCallback) { + if ($this->beforeCreateCallback instanceof \Closure) { value($this->beforeCreateCallback, $shortURL); } @@ -485,7 +485,7 @@ private function setOptions(): void $this->urlKey = $this->keyGenerator->generateKeyUsing($this->generateKeyUsing); } - if (! $this->activateAt) { + if (!$this->activateAt instanceof \Carbon\Carbon) { $this->activateAt = Carbon::now(); } diff --git a/src/Classes/Resolver.php b/src/Classes/Resolver.php index 43516a1..bd2bab0 100644 --- a/src/Classes/Resolver.php +++ b/src/Classes/Resolver.php @@ -59,12 +59,7 @@ protected function shouldAllowAccess(ShortURL $shortURL): bool if (now()->isBefore($shortURL->activated_at)) { return false; } - - if ($shortURL->deactivated_at && now()->isAfter($shortURL->deactivated_at)) { - return false; - } - - return true; + return !($shortURL->deactivated_at && now()->isAfter($shortURL->deactivated_at)); } /** diff --git a/tests/Unit/Classes/BuilderTest.php b/tests/Unit/Classes/BuilderTest.php index 5447c33..6dda9f8 100644 --- a/tests/Unit/Classes/BuilderTest.php +++ b/tests/Unit/Classes/BuilderTest.php @@ -307,7 +307,7 @@ public function random_url_key_is_generated_if_one_is_not_explicitly_defined(): public function short_url_can_be_created_and_stored_in_the_database(): void { $builder = app(Builder::class); - $shortURL = $builder->destinationUrl('http://domain.com') + $builder->destinationUrl('http://domain.com') ->urlKey('customKey') ->secure() ->trackVisits(false) @@ -552,7 +552,7 @@ public function data_can_be_overridden_on_model_using_make_callback(): void { $shortUrl = app(Builder::class) ->destinationUrl('https://foo.com') - ->beforeCreate(function (ShortURL $shortURL) { + ->beforeCreate(function (ShortURL $shortURL): void { $shortURL->destination_url = 'https://bar.com'; }) ->make(); diff --git a/tests/Unit/Classes/ResolverTest.php b/tests/Unit/Classes/ResolverTest.php index 663df5f..824fe8b 100644 --- a/tests/Unit/Classes/ResolverTest.php +++ b/tests/Unit/Classes/ResolverTest.php @@ -418,7 +418,7 @@ public function referer_url_is_stored_if_it_is_enabled(): void $request = Request::create(config('short-url.default_url').'/short/12345', 'GET', [], [], [], [ 'HTTP_referer' => 'https://google.com', - 'HTTP_USER_AGENT' => static::trackingFieldsProvider()[1][0], + 'HTTP_USER_AGENT' => self::trackingFieldsProvider()[1][0], ]); $resolver = app(Resolver::class); @@ -454,7 +454,7 @@ public function fields_are_not_recorded_if_all_are_true_but_track_visits_is_disa $request = Request::create(config('short-url.default_url').'/short/12345', 'GET', [], [], [], [ 'HTTP_referer' => 'https://google.com', - 'HTTP_USER_AGENT' => static::trackingFieldsProvider()[1][0], + 'HTTP_USER_AGENT' => self::trackingFieldsProvider()[1][0], ]); $resolver = app(Resolver::class); diff --git a/tests/Unit/Controllers/ShortURLControllerTest.php b/tests/Unit/Controllers/ShortURLControllerTest.php index 6f8fca4..001a00d 100644 --- a/tests/Unit/Controllers/ShortURLControllerTest.php +++ b/tests/Unit/Controllers/ShortURLControllerTest.php @@ -67,12 +67,7 @@ public function event_is_dispatched_when_the_short_url_is_visited(): void if ($shortURL->toArray() != $event->shortURL->fresh()->toArray()) { return false; } - - if ($visit->toArray() != $event->shortURLVisit->fresh()->toArray()) { - return false; - } - - return true; + return $visit->toArray() == $event->shortURLVisit->fresh()->toArray(); }); }