From dacf85a3d68b876d34f7b4e07e866e4fc59910ea Mon Sep 17 00:00:00 2001 From: Micha Viehauser Date: Mon, 14 Sep 2020 10:49:57 +0200 Subject: [PATCH 1/5] Add Laravel 8 support --- composer.json | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 853b8ee..8ed9e46 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "laravel/framework": "^5.5||~6.0||^7.0" + "laravel/framework": "^5.5||~6.0||^7.0||^8.0" }, "autoload": { "psr-4": { @@ -22,10 +22,9 @@ } }, "require-dev": { - "laravel/framework": "^5.5", "mockery/mockery": "^1.2", - "phpunit/phpunit": "~8.0", - "orchestra/testbench": "^3.7", + "phpunit/phpunit": "~9.0", + "orchestra/testbench": "^6.0", "brainmaestro/composer-git-hooks": "^2.7", "friendsofphp/php-cs-fixer": "^2.16" }, From 1ac661e75c0160bd378ce5d896b8e44a4f7366c2 Mon Sep 17 00:00:00 2001 From: overtrue Date: Wed, 2 Dec 2020 23:23:02 +0800 Subject: [PATCH 2/5] Uuids --- composer.json | 10 +++------ config/like.php | 13 +++++------- .../2018_12_14_000000_create_likes_table.php | 8 ------- src/Events/Event.php | 9 -------- src/Events/Liked.php | 9 -------- src/Events/Unliked.php | 9 -------- src/Like.php | 21 +++++++------------ src/LikeServiceProvider.php | 12 ----------- src/Traits/Likeable.php | 12 ----------- src/Traits/Liker.php | 12 ----------- tests/Book.php | 11 ---------- tests/FeatureTest.php | 11 ---------- tests/Post.php | 11 ---------- tests/TestCase.php | 8 ------- tests/User.php | 11 ---------- .../2018_12_14_095815_create_books_table.php | 8 ------- .../2018_12_14_095815_create_posts_table.php | 8 ------- .../2018_12_14_095815_create_users_table.php | 8 ------- 18 files changed, 16 insertions(+), 175 deletions(-) diff --git a/composer.json b/composer.json index 8ed9e46..5604213 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "laravel/framework": "^5.5||~6.0||^7.0||^8.0" + "laravel/framework": "^7.0|^8.0" }, "autoload": { "psr-4": { @@ -23,7 +23,7 @@ }, "require-dev": { "mockery/mockery": "^1.2", - "phpunit/phpunit": "~9.0", + "phpunit/phpunit": "^9.0", "orchestra/testbench": "^6.0", "brainmaestro/composer-git-hooks": "^2.7", "friendsofphp/php-cs-fixer": "^2.16" @@ -39,17 +39,13 @@ "composer test", "composer fix-style" ], - "pre-push": [ - "composer test", - "composer check-style" - ] + "post-merge": "composer install" } }, "scripts": { "post-update-cmd": [ "cghooks update" ], - "post-merge": "composer install", "post-install-cmd": [ "cghooks add --ignore-lock", "cghooks update" diff --git a/config/like.php b/config/like.php index 7b6b83c..17f6ed3 100644 --- a/config/like.php +++ b/config/like.php @@ -1,14 +1,11 @@ - * - * This source file is subject to the MIT license that is bundled. - */ - return [ + /** + * Use uuid as primary key. + */ + 'uuids' => false, + /* * User tables foreign key name. */ diff --git a/migrations/2018_12_14_000000_create_likes_table.php b/migrations/2018_12_14_000000_create_likes_table.php index 2e419a1..50f6b1d 100644 --- a/migrations/2018_12_14_000000_create_likes_table.php +++ b/migrations/2018_12_14_000000_create_likes_table.php @@ -1,13 +1,5 @@ - * - * This source file is subject to the MIT license that is bundled. - */ - use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; diff --git a/src/Events/Event.php b/src/Events/Event.php index 7da5ef6..a63801d 100644 --- a/src/Events/Event.php +++ b/src/Events/Event.php @@ -1,14 +1,5 @@ - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace Overtrue\LaravelLike\Events; use Illuminate\Database\Eloquent\Model; diff --git a/src/Events/Liked.php b/src/Events/Liked.php index efae1a4..c2342ae 100644 --- a/src/Events/Liked.php +++ b/src/Events/Liked.php @@ -1,14 +1,5 @@ - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace Overtrue\LaravelLike\Events; class Liked extends Event diff --git a/src/Events/Unliked.php b/src/Events/Unliked.php index 813952e..2432e51 100644 --- a/src/Events/Unliked.php +++ b/src/Events/Unliked.php @@ -1,14 +1,5 @@ - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace Overtrue\LaravelLike\Events; class Unliked extends Event diff --git a/src/Like.php b/src/Like.php index 34dca65..9b2c81b 100644 --- a/src/Like.php +++ b/src/Like.php @@ -1,26 +1,16 @@ - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace Overtrue\LaravelLike; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Str; use Overtrue\LaravelLike\Events\Liked; use Overtrue\LaravelLike\Events\Unliked; -/** - * Class Like. - */ class Like extends Model { + protected $guarded = []; + protected $dispatchesEvents = [ 'created' => Liked::class, 'deleted' => Unliked::class, @@ -45,6 +35,11 @@ protected static function boot() self::saving(function ($like) { $userForeignKey = \config('like.user_foreign_key'); $like->{$userForeignKey} = $like->{$userForeignKey} ?: auth()->id(); + + + if (\config('like.uuids')) { + $like->{$like->getKeyName()} = $like->{$like->getKeyName()} ?: (string) Str::orderedUuid(); + } }); } diff --git a/src/LikeServiceProvider.php b/src/LikeServiceProvider.php index 7b0a321..3961db6 100644 --- a/src/LikeServiceProvider.php +++ b/src/LikeServiceProvider.php @@ -1,21 +1,9 @@ - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace Overtrue\LaravelLike; use Illuminate\Support\ServiceProvider; -/** - * Class LikeServiceProvider. - */ class LikeServiceProvider extends ServiceProvider { /** diff --git a/src/Traits/Likeable.php b/src/Traits/Likeable.php index 6c81de5..75f3b34 100644 --- a/src/Traits/Likeable.php +++ b/src/Traits/Likeable.php @@ -1,21 +1,9 @@ - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace Overtrue\LaravelLike\Traits; use Illuminate\Database\Eloquent\Model; -/** - * Trait Likeable. - */ trait Likeable { /** diff --git a/src/Traits/Liker.php b/src/Traits/Liker.php index 02d868b..f06a320 100644 --- a/src/Traits/Liker.php +++ b/src/Traits/Liker.php @@ -1,22 +1,10 @@ - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace Overtrue\LaravelLike\Traits; use Illuminate\Database\Eloquent\Model; use Overtrue\LaravelLike\Like; -/** - * Trait Liker. - */ trait Liker { /** diff --git a/tests/Book.php b/tests/Book.php index d118d03..03f8471 100644 --- a/tests/Book.php +++ b/tests/Book.php @@ -1,21 +1,10 @@ - * - * This source file is subject to the MIT license that is bundled. - */ - namespace Tests; use Illuminate\Database\Eloquent\Model; use Overtrue\LaravelLike\Traits\Likeable; -/** - * Class Book. - */ class Book extends Model { use Likeable; diff --git a/tests/FeatureTest.php b/tests/FeatureTest.php index db61139..624eac4 100644 --- a/tests/FeatureTest.php +++ b/tests/FeatureTest.php @@ -1,13 +1,5 @@ - * - * This source file is subject to the MIT license that is bundled. - */ - namespace Tests; use Illuminate\Database\Eloquent\Relations\Relation; @@ -16,9 +8,6 @@ use Overtrue\LaravelLike\Events\Unliked; use Overtrue\LaravelLike\Like; -/** - * Class FeatureTest. - */ class FeatureTest extends TestCase { public function setUp() : void diff --git a/tests/Post.php b/tests/Post.php index 21bf1a7..597e443 100644 --- a/tests/Post.php +++ b/tests/Post.php @@ -1,21 +1,10 @@ - * - * This source file is subject to the MIT license that is bundled. - */ - namespace Tests; use Illuminate\Database\Eloquent\Model; use Overtrue\LaravelLike\Traits\Likeable; -/** - * Class Post. - */ class Post extends Model { use Likeable; diff --git a/tests/TestCase.php b/tests/TestCase.php index 4b1b0e7..2093c5c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,13 +1,5 @@ - * - * This source file is subject to the MIT license that is bundled. - */ - namespace Tests; use Overtrue\LaravelLike\LikeServiceProvider; diff --git a/tests/User.php b/tests/User.php index 49d28b0..063a3a8 100644 --- a/tests/User.php +++ b/tests/User.php @@ -1,21 +1,10 @@ - * - * This source file is subject to the MIT license that is bundled. - */ - namespace Tests; use Illuminate\Database\Eloquent\Model; use Overtrue\LaravelLike\Traits\Liker; -/** - * Class User. - */ class User extends Model { use Liker; diff --git a/tests/migrations/2018_12_14_095815_create_books_table.php b/tests/migrations/2018_12_14_095815_create_books_table.php index 90bd192..e24355a 100644 --- a/tests/migrations/2018_12_14_095815_create_books_table.php +++ b/tests/migrations/2018_12_14_095815_create_books_table.php @@ -1,13 +1,5 @@ - * - * This source file is subject to the MIT license that is bundled. - */ - use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; diff --git a/tests/migrations/2018_12_14_095815_create_posts_table.php b/tests/migrations/2018_12_14_095815_create_posts_table.php index fa9d4ab..ef42f4e 100644 --- a/tests/migrations/2018_12_14_095815_create_posts_table.php +++ b/tests/migrations/2018_12_14_095815_create_posts_table.php @@ -1,13 +1,5 @@ - * - * This source file is subject to the MIT license that is bundled. - */ - use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; diff --git a/tests/migrations/2018_12_14_095815_create_users_table.php b/tests/migrations/2018_12_14_095815_create_users_table.php index fcb013a..170e354 100644 --- a/tests/migrations/2018_12_14_095815_create_users_table.php +++ b/tests/migrations/2018_12_14_095815_create_users_table.php @@ -1,13 +1,5 @@ - * - * This source file is subject to the MIT license that is bundled. - */ - use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; From dcbe6e59d0c8782f7f45edd398eb10493da18d48 Mon Sep 17 00:00:00 2001 From: overtrue Date: Wed, 2 Dec 2020 23:23:27 +0800 Subject: [PATCH 3/5] Uuids --- src/Events/Event.php | 9 +++++++++ src/Events/Liked.php | 9 +++++++++ src/Events/Unliked.php | 9 +++++++++ src/Like.php | 10 ++++++++++ src/LikeServiceProvider.php | 9 +++++++++ src/Traits/Likeable.php | 9 +++++++++ src/Traits/Liker.php | 9 +++++++++ 7 files changed, 64 insertions(+) diff --git a/src/Events/Event.php b/src/Events/Event.php index a63801d..7da5ef6 100644 --- a/src/Events/Event.php +++ b/src/Events/Event.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Overtrue\LaravelLike\Events; use Illuminate\Database\Eloquent\Model; diff --git a/src/Events/Liked.php b/src/Events/Liked.php index c2342ae..efae1a4 100644 --- a/src/Events/Liked.php +++ b/src/Events/Liked.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Overtrue\LaravelLike\Events; class Liked extends Event diff --git a/src/Events/Unliked.php b/src/Events/Unliked.php index 2432e51..813952e 100644 --- a/src/Events/Unliked.php +++ b/src/Events/Unliked.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Overtrue\LaravelLike\Events; class Unliked extends Event diff --git a/src/Like.php b/src/Like.php index 9b2c81b..24a61ff 100644 --- a/src/Like.php +++ b/src/Like.php @@ -1,4 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Overtrue\LaravelLike; use Illuminate\Database\Eloquent\Builder; diff --git a/src/LikeServiceProvider.php b/src/LikeServiceProvider.php index 3961db6..ce99917 100644 --- a/src/LikeServiceProvider.php +++ b/src/LikeServiceProvider.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Overtrue\LaravelLike; use Illuminate\Support\ServiceProvider; diff --git a/src/Traits/Likeable.php b/src/Traits/Likeable.php index 75f3b34..b8b1b65 100644 --- a/src/Traits/Likeable.php +++ b/src/Traits/Likeable.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Overtrue\LaravelLike\Traits; use Illuminate\Database\Eloquent\Model; diff --git a/src/Traits/Liker.php b/src/Traits/Liker.php index f06a320..d32fc09 100644 --- a/src/Traits/Liker.php +++ b/src/Traits/Liker.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Overtrue\LaravelLike\Traits; use Illuminate\Database\Eloquent\Model; From 1f54a597aa1c0408e573469444c1a72f10cbb5ba Mon Sep 17 00:00:00 2001 From: overtrue Date: Wed, 2 Dec 2020 23:24:56 +0800 Subject: [PATCH 4/5] Remove header comments. --- .php_cs | 50 +++++++++++++++++++++++-------------- src/Events/Event.php | 9 ------- src/Events/Liked.php | 9 ------- src/Events/Unliked.php | 9 ------- src/Like.php | 9 ------- src/LikeServiceProvider.php | 9 ------- src/Traits/Likeable.php | 9 ------- src/Traits/Liker.php | 9 ------- tests/FeatureTest.php | 8 +++--- tests/TestCase.php | 2 +- 10 files changed, 36 insertions(+), 87 deletions(-) diff --git a/.php_cs b/.php_cs index 7384d8b..52dd8e5 100644 --- a/.php_cs +++ b/.php_cs @@ -1,36 +1,48 @@ - -This source file is subject to the MIT license that is bundled -with this source code in the file LICENSE. -EOF; - return PhpCsFixer\Config::create() ->setRules([ '@PSR2' => true, - 'header_comment' => ['header' => $header], + 'binary_operator_spaces' => true, 'blank_line_after_opening_tag' => true, - 'braces' => ['allow_single_line_closure' => true], 'compact_nullable_typehint' => true, - 'concat_space' => ['spacing' => 'one'], - 'declare_equal_normalize' => ['space' => 'none'], - 'function_typehint_space' => true, + 'declare_equal_normalize' => true, + 'lowercase_cast' => true, + 'lowercase_static_reference' => true, 'new_with_braces' => true, - 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], - 'no_empty_statement' => true, + 'no_blank_lines_after_class_opening' => true, 'no_leading_import_slash' => true, - 'no_leading_namespace_whitespace' => true, 'no_whitespace_in_blank_line' => true, - 'return_type_declaration' => ['space_before' => 'none'], + 'ordered_class_elements' => [ + 'order' => [ + 'use_trait', + ], + ], + 'ordered_imports' => [ + 'imports_order' => [ + 'class', + 'function', + 'const', + ], + 'sort_algorithm' => 'none', + ], + 'return_type_declaration' => true, + 'short_scalar_cast' => true, + 'single_blank_line_before_namespace' => true, 'single_trait_insert_per_statement' => true, + 'ternary_operator_spaces' => true, + 'unary_operator_spaces' => true, + 'visibility_required' => [ + 'elements' => [ + 'const', + 'method', + 'property', + ], + ], ]) ->setFinder( PhpCsFixer\Finder::create() ->exclude('vendor') - ->in([__DIR__.'/src/']) + ->in([__DIR__.'/src/', __DIR__.'/tests/']) ) ; diff --git a/src/Events/Event.php b/src/Events/Event.php index 7da5ef6..a63801d 100644 --- a/src/Events/Event.php +++ b/src/Events/Event.php @@ -1,14 +1,5 @@ - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace Overtrue\LaravelLike\Events; use Illuminate\Database\Eloquent\Model; diff --git a/src/Events/Liked.php b/src/Events/Liked.php index efae1a4..c2342ae 100644 --- a/src/Events/Liked.php +++ b/src/Events/Liked.php @@ -1,14 +1,5 @@ - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace Overtrue\LaravelLike\Events; class Liked extends Event diff --git a/src/Events/Unliked.php b/src/Events/Unliked.php index 813952e..2432e51 100644 --- a/src/Events/Unliked.php +++ b/src/Events/Unliked.php @@ -1,14 +1,5 @@ - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace Overtrue\LaravelLike\Events; class Unliked extends Event diff --git a/src/Like.php b/src/Like.php index 24a61ff..dd79ee3 100644 --- a/src/Like.php +++ b/src/Like.php @@ -1,14 +1,5 @@ - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace Overtrue\LaravelLike; use Illuminate\Database\Eloquent\Builder; diff --git a/src/LikeServiceProvider.php b/src/LikeServiceProvider.php index ce99917..3961db6 100644 --- a/src/LikeServiceProvider.php +++ b/src/LikeServiceProvider.php @@ -1,14 +1,5 @@ - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace Overtrue\LaravelLike; use Illuminate\Support\ServiceProvider; diff --git a/src/Traits/Likeable.php b/src/Traits/Likeable.php index b8b1b65..75f3b34 100644 --- a/src/Traits/Likeable.php +++ b/src/Traits/Likeable.php @@ -1,14 +1,5 @@ - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace Overtrue\LaravelLike\Traits; use Illuminate\Database\Eloquent\Model; diff --git a/src/Traits/Liker.php b/src/Traits/Liker.php index d32fc09..f06a320 100644 --- a/src/Traits/Liker.php +++ b/src/Traits/Liker.php @@ -1,14 +1,5 @@ - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace Overtrue\LaravelLike\Traits; use Illuminate\Database\Eloquent\Model; diff --git a/tests/FeatureTest.php b/tests/FeatureTest.php index 624eac4..7169b5a 100644 --- a/tests/FeatureTest.php +++ b/tests/FeatureTest.php @@ -10,7 +10,7 @@ class FeatureTest extends TestCase { - public function setUp() : void + public function setUp(): void { parent::setUp(); @@ -98,7 +98,7 @@ public function test_object_likers() $this->assertSame('overtrue', $post->likers[0]['name']); $this->assertSame('allen', $post->likers[1]['name']); - $sqls = $this->getQueryLog(function() use ($post, $user1, $user2, $user3) { + $sqls = $this->getQueryLog(function () use ($post, $user1, $user2, $user3) { $this->assertTrue($post->isLikedBy($user1)); $this->assertTrue($post->isLikedBy($user2)); $this->assertFalse($post->isLikedBy($user3)); @@ -142,14 +142,14 @@ public function test_eager_loading() $user->like($book2); // start recording - $sqls = $this->getQueryLog(function() use ($user) { + $sqls = $this->getQueryLog(function () use ($user) { $user->load('likes.likeable'); }); $this->assertSame(3, $sqls->count()); // from loaded relations - $sqls = $this->getQueryLog(function() use ($user, $post1) { + $sqls = $this->getQueryLog(function () use ($user, $post1) { $user->hasLiked($post1); }); diff --git a/tests/TestCase.php b/tests/TestCase.php index 2093c5c..cae8294 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -37,7 +37,7 @@ protected function getEnvironmentSetUp($app) /** * run package database migrations. */ - public function setUp() : void + public function setUp(): void { parent::setUp(); $this->loadMigrationsFrom(__DIR__.'/migrations'); From b1ddfaded1526d98fb50414d8dbd8f41f94328b0 Mon Sep 17 00:00:00 2001 From: overtrue Date: Wed, 2 Dec 2020 23:26:36 +0800 Subject: [PATCH 5/5] Remove old php versions. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31e67a3..81667ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: phpunit: strategy: matrix: - php_version: [7.2, 7.3, 7.4] + php_version: [7.4] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2