Skip to content

Commit 47482cb

Browse files
committed
Laravel 10
1 parent e3011c4 commit 47482cb

File tree

13 files changed

+37
-55
lines changed

13 files changed

+37
-55
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ composer.lock
77
cghooks.lock
88

99
.php-cs-fixer.cache
10+
.phpunit.cache/

composer.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
},
2424
"require-dev": {
2525
"mockery/mockery": "^1.5",
26-
"phpunit/phpunit": "^9.5|^10.0",
27-
"orchestra/testbench": "^7.4",
28-
"friendsofphp/php-cs-fixer": "^3.8"
26+
"phpunit/phpunit": "^10.0",
27+
"orchestra/testbench": "^8.0",
28+
"friendsofphp/php-cs-fixer": "^3.8",
29+
"brainmaestro/composer-git-hooks": "dev-master",
30+
"laravel/pint": "^1.5"
2931
},
3032
"extra": {
3133
"laravel": {
@@ -57,8 +59,8 @@
5759
"cghooks update"
5860
],
5961
"cghooks": "vendor/bin/cghooks",
60-
"check-style": "php-cs-fixer fix --using-cache=no --diff --dry-run --ansi",
61-
"fix-style": "php-cs-fixer fix --using-cache=no --ansi",
62+
"check-style": "vendor/bin/pint --test",
63+
"fix-style": "vendor/bin/pint",
6264
"test": "phpunit --colors=always"
6365
},
6466
"scripts-descriptions": {

config/follow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
return [
4-
/*
4+
/*
55
* Use uuid as primary key.
66
*/
77
'uuids' => false,

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
33
<coverage>
44
<include>
55
<directory suffix=".php">src/</directory>

src/Events/Event.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
class Event
88
{
99
public int|string $followable_id;
10+
1011
public int|string $followable_type;
12+
1113
public int|string $follower_id;
14+
1215
public int|string $user_id;
1316

1417
protected Followable $relation;

src/FollowServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class FollowServiceProvider extends ServiceProvider
99
public function boot()
1010
{
1111
$this->publishes([
12-
\dirname(__DIR__) . '/config/follow.php' => config_path('follow.php'),
12+
\dirname(__DIR__).'/config/follow.php' => config_path('follow.php'),
1313
], 'config');
1414

1515
$this->publishes([
16-
\dirname(__DIR__) . '/migrations/' => database_path('migrations'),
16+
\dirname(__DIR__).'/migrations/' => database_path('migrations'),
1717
], 'migrations');
1818
}
1919
}

src/Followable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
namespace Overtrue\LaravelFollow;
44

5+
use function config;
56
use Illuminate\Database\Eloquent\Builder;
67
use Illuminate\Database\Eloquent\Model;
78
use Illuminate\Database\Eloquent\Relations\BelongsTo;
89
use Illuminate\Database\Eloquent\Relations\HasMany;
910
use Illuminate\Database\Eloquent\Relations\MorphTo;
10-
use Illuminate\Database\Eloquent\Relations\Pivot;
1111
use Illuminate\Support\Str;
1212
use Overtrue\LaravelFollow\Events\Followed;
1313
use Overtrue\LaravelFollow\Events\Unfollowed;
14-
use function config;
1514

1615
/**
1716
* @property int|string $followable_id;
1817
* @property int|string $followable_type;
1918
* @property int|string $user_id;
19+
*
2020
* @method HasMany of(Model $model)
2121
* @method HasMany followedBy(Model $model)
2222
* @method HasMany withType(string $type)

src/Traits/Followable.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@
22

33
namespace Overtrue\LaravelFollow\Traits;
44

5-
use Illuminate\Contracts\Pagination\Paginator;
6-
use Illuminate\Database\Eloquent\Builder;
5+
use function config;
76
use Illuminate\Database\Eloquent\Collection;
87
use Illuminate\Database\Eloquent\Model;
98
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
109
use Illuminate\Database\Eloquent\Relations\HasMany;
11-
use Illuminate\Pagination\CursorPaginator;
12-
use Illuminate\Pagination\LengthAwarePaginator;
13-
use Illuminate\Support\Enumerable;
14-
use Illuminate\Support\LazyCollection;
1510
use Overtrue\LaravelFollow\Traits\Follower as Follower;
16-
use function config;
1711

1812
/**
1913
* @property Collection $followables
@@ -28,7 +22,7 @@ public function needsToApproveFollowRequests(): bool
2822

2923
public function rejectFollowRequestFrom(Model $follower): void
3024
{
31-
if (!in_array(Follower::class, \class_uses($follower))) {
25+
if (! in_array(Follower::class, \class_uses($follower))) {
3226
throw new \InvalidArgumentException('The model must use the Follower trait.');
3327
}
3428

@@ -37,7 +31,7 @@ public function rejectFollowRequestFrom(Model $follower): void
3731

3832
public function acceptFollowRequestFrom(Model $follower): void
3933
{
40-
if (!in_array(Follower::class, \class_uses($follower))) {
34+
if (! in_array(Follower::class, \class_uses($follower))) {
4135
throw new \InvalidArgumentException('The model must use the Follower trait.');
4236
}
4337

@@ -46,7 +40,7 @@ public function acceptFollowRequestFrom(Model $follower): void
4640

4741
public function isFollowedBy(Model $follower): bool
4842
{
49-
if (!in_array(Follower::class, \class_uses($follower))) {
43+
if (! in_array(Follower::class, \class_uses($follower))) {
5044
throw new \InvalidArgumentException('The model must use the Follower trait.');
5145
}
5246

src/Traits/Follower.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,36 @@
22

33
namespace Overtrue\LaravelFollow\Traits;
44

5+
use function abort_if;
6+
use function class_uses;
7+
use function collect;
58
use Illuminate\Contracts\Pagination\Paginator;
6-
use Illuminate\Database\Eloquent\Builder;
79
use Illuminate\Database\Eloquent\Collection;
810
use Illuminate\Database\Eloquent\Model;
9-
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
1011
use Illuminate\Database\Eloquent\Relations\HasMany;
1112
use Illuminate\Pagination\CursorPaginator;
1213
use Illuminate\Pagination\LengthAwarePaginator;
1314
use Illuminate\Support\Enumerable;
1415
use Illuminate\Support\LazyCollection;
15-
use InvalidArgumentException;
16-
use JetBrains\PhpStorm\ArrayShape;
17-
use Overtrue\LaravelFollow\Traits\Followable;
18-
use function abort_if;
19-
use function class_uses;
20-
use function collect;
2116
use function in_array;
17+
use InvalidArgumentException;
2218
use function is_array;
2319
use function iterator_to_array;
20+
use JetBrains\PhpStorm\ArrayShape;
2421

2522
/**
2623
* @property Collection $followings
2724
*/
2825
trait Follower
2926
{
30-
#[ArrayShape(['pending' => "mixed"])]
27+
#[ArrayShape(['pending' => 'mixed'])]
3128
public function follow(Model $followable): array
3229
{
3330
if ($followable->is($this)) {
3431
throw new InvalidArgumentException('Cannot follow yourself.');
3532
}
3633

37-
if (!in_array(Followable::class, class_uses($followable))) {
34+
if (! in_array(Followable::class, class_uses($followable))) {
3835
throw new InvalidArgumentException('The followable model must use the Followable trait.');
3936
}
4037

@@ -45,15 +42,15 @@ public function follow(Model $followable): array
4542
'followable_id' => $followable->getKey(),
4643
'followable_type' => $followable->getMorphClass(),
4744
], [
48-
'accepted_at' => $isPending ? null : now()
45+
'accepted_at' => $isPending ? null : now(),
4946
]);
5047

5148
return ['pending' => $isPending];
5249
}
5350

5451
public function unfollow(Model $followable): void
5552
{
56-
if (!in_array(Followable::class, class_uses($followable))) {
53+
if (! in_array(Followable::class, class_uses($followable))) {
5754
throw new InvalidArgumentException('The followable model must use the Followable trait.');
5855
}
5956

@@ -67,7 +64,7 @@ public function toggleFollow(Model $followable): void
6764

6865
public function isFollowing(Model $followable): bool
6966
{
70-
if (!in_array(Followable::class, class_uses($followable))) {
67+
if (! in_array(Followable::class, class_uses($followable))) {
7168
throw new InvalidArgumentException('The followable model must use the Followable trait.');
7269
}
7370

@@ -84,7 +81,7 @@ public function isFollowing(Model $followable): bool
8481

8582
public function hasRequestedToFollow(Model $followable): bool
8683
{
87-
if (!in_array(\Overtrue\LaravelFollow\Traits\Followable::class, \class_uses($followable))) {
84+
if (! in_array(\Overtrue\LaravelFollow\Traits\Followable::class, \class_uses($followable))) {
8885
throw new InvalidArgumentException('The followable model must use the Followable trait.');
8986
}
9087

@@ -144,7 +141,7 @@ public function attachFollowStatus($followables, callable $resolver = null)
144141
break;
145142
}
146143

147-
abort_if(!($followables instanceof Enumerable), 422, 'Invalid $followables type.');
144+
abort_if(! ($followables instanceof Enumerable), 422, 'Invalid $followables type.');
148145

149146
$followed = $this->followings()->get();
150147

tests/FeatureTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Tests;
44

55
use Illuminate\Support\Carbon;
6-
use Illuminate\Support\Facades\DB;
76
use Illuminate\Support\Facades\Event;
87
use Overtrue\LaravelFollow\Events\Followed;
98
use Overtrue\LaravelFollow\Events\Unfollowed;
@@ -180,11 +179,6 @@ function () use ($user1, $user2, $user3, $user4) {
180179
$this->assertSame(0, $sqls->count());
181180
}
182181

183-
/**
184-
* @param \Closure $callback
185-
*
186-
* @return \Illuminate\Support\Collection
187-
*/
188182
protected function getQueryLog(\Closure $callback): \Illuminate\Support\Collection
189183
{
190184
$sqls = \collect([]);

0 commit comments

Comments
 (0)