Skip to content

Commit 82f71bf

Browse files
authored
Apply fixes from StyleCI (#28)
1 parent 8b7dd51 commit 82f71bf

File tree

3 files changed

+130
-124
lines changed

3 files changed

+130
-124
lines changed

src/Follow.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/*
4-
* This file is part of the overtrue/laravel-follow.
4+
* This file is part of the overtrue/laravel-follow
55
*
66
* (c) overtrue <[email protected]>
77
*
@@ -22,10 +22,15 @@
2222
class Follow
2323
{
2424
const RELATION_LIKE = 'like';
25+
2526
const RELATION_FOLLOW = 'follow';
27+
2628
const RELATION_SUBSCRIBE = 'subscribe';
29+
2730
const RELATION_FAVORITE = 'favorite';
31+
2832
const RELATION_UPVOTE = 'upvote';
33+
2934
const RELATION_DOWNVOTE = 'downvote';
3035

3136
/**
@@ -120,9 +125,10 @@ public static function formatTargets($targets, $classname, array $update = [])
120125
$targets = [$targets];
121126
}
122127

123-
$result->ids = array_map(function($target) use ($result){
128+
$result->ids = array_map(function ($target) use ($result) {
124129
if ($target instanceof Model) {
125130
$result->classname = get_class($target);
131+
126132
return $target->getKey();
127133
}
128134

@@ -151,4 +157,4 @@ protected static function getRelationTypeFromRelation(MorphToMany $relation)
151157

152158
return $wheres['followables.relation'];
153159
}
154-
}
160+
}

src/Traits/CanBeVoted.php

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,30 @@ public function isVotedBy($user, $type = null)
2929
{
3030
return Follow::isRelationExists($this, 'voters', $user);
3131
}
32-
33-
/**
34-
* Check if item is upvoted by given user.
35-
*
36-
* @param int $user
37-
*
38-
* @return bool
39-
*/
40-
public function isUpvotedBy($user)
41-
{
42-
return Follow::isRelationExists($this, 'upvoters', $user);
43-
}
44-
45-
/**
46-
* Check if item is downvoted by given user.
47-
*
48-
* @param int $user
49-
*
50-
* @return bool
51-
*/
52-
public function isDownvotedBy($user)
53-
{
54-
return Follow::isRelationExists($this, 'downvoters', $user);
55-
}
32+
33+
/**
34+
* Check if item is upvoted by given user.
35+
*
36+
* @param int $user
37+
*
38+
* @return bool
39+
*/
40+
public function isUpvotedBy($user)
41+
{
42+
return Follow::isRelationExists($this, 'upvoters', $user);
43+
}
44+
45+
/**
46+
* Check if item is downvoted by given user.
47+
*
48+
* @param int $user
49+
*
50+
* @return bool
51+
*/
52+
public function isDownvotedBy($user)
53+
{
54+
return Follow::isRelationExists($this, 'downvoters', $user);
55+
}
5656

5757
/**
5858
* Return voters.
@@ -65,28 +65,28 @@ public function voters()
6565
->wherePivotIn('relation', [Follow::RELATION_UPVOTE, Follow::RELATION_DOWNVOTE])
6666
->withPivot('followable_type', 'relation', 'created_at');
6767
}
68-
69-
/**
70-
* Return upvoters.
71-
*
72-
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
73-
*/
74-
public function upvoters()
75-
{
76-
return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table'))
77-
->wherePivot('relation', '=', Follow::RELATION_UPVOTE)
78-
->withPivot('followable_type', 'relation', 'created_at');
79-
}
80-
81-
/**
82-
* Return downvoters.
83-
*
84-
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
85-
*/
86-
public function downvoters()
87-
{
88-
return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table'))
89-
->wherePivot('relation', '=', Follow::RELATION_DOWNVOTE)
90-
->withPivot('followable_type', 'relation', 'created_at');
91-
}
68+
69+
/**
70+
* Return upvoters.
71+
*
72+
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
73+
*/
74+
public function upvoters()
75+
{
76+
return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table'))
77+
->wherePivot('relation', '=', Follow::RELATION_UPVOTE)
78+
->withPivot('followable_type', 'relation', 'created_at');
79+
}
80+
81+
/**
82+
* Return downvoters.
83+
*
84+
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
85+
*/
86+
public function downvoters()
87+
{
88+
return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table'))
89+
->wherePivot('relation', '=', Follow::RELATION_DOWNVOTE)
90+
->withPivot('followable_type', 'relation', 'created_at');
91+
}
9292
}

src/Traits/CanVote.php

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,38 @@ trait CanVote
2929
*/
3030
public function vote($targets, $type = 'upvote', $class = __CLASS__)
3131
{
32-
$this->cancelVote($targets);
33-
32+
$this->cancelVote($targets);
33+
3434
return Follow::attachRelations($this, str_plural($type), $targets, $class);
3535
}
36-
37-
/**
38-
* Upvote an item or items.
39-
*
40-
* @param int|array|\Illuminate\Database\Eloquent\Model $targets
41-
* @param string $type
42-
* @param string $class
43-
*
44-
* @return array
45-
*/
46-
public function upvote($targets, $class = __CLASS__)
47-
{
48-
return $this->vote($targets, 'upvote', $class);
49-
}
50-
51-
/**
52-
* Downvote an item or items.
53-
*
54-
* @param int|array|\Illuminate\Database\Eloquent\Model $targets
55-
* @param string $type
56-
* @param string $class
57-
*
58-
* @return array
59-
*/
60-
public function downvote($targets, $class = __CLASS__)
61-
{
62-
return $this->vote($targets, 'downvote', $class);
63-
}
36+
37+
/**
38+
* Upvote an item or items.
39+
*
40+
* @param int|array|\Illuminate\Database\Eloquent\Model $targets
41+
* @param string $type
42+
* @param string $class
43+
*
44+
* @return array
45+
*/
46+
public function upvote($targets, $class = __CLASS__)
47+
{
48+
return $this->vote($targets, 'upvote', $class);
49+
}
50+
51+
/**
52+
* Downvote an item or items.
53+
*
54+
* @param int|array|\Illuminate\Database\Eloquent\Model $targets
55+
* @param string $type
56+
* @param string $class
57+
*
58+
* @return array
59+
*/
60+
public function downvote($targets, $class = __CLASS__)
61+
{
62+
return $this->vote($targets, 'downvote', $class);
63+
}
6464

6565
/**
6666
* Cancel vote for an item or items.
@@ -74,8 +74,8 @@ public function cancelVote($targets, $class = __CLASS__)
7474
{
7575
Follow::detachRelations($this, 'upvotes', $targets, $class);
7676
Follow::detachRelations($this, 'downvotes', $targets, $class);
77-
78-
return $this;
77+
78+
return $this;
7979
}
8080

8181
/**
@@ -90,33 +90,33 @@ public function hasUpvoted($target, $class = __CLASS__)
9090
{
9191
return Follow::isRelationExists($this, 'upvote', $target, $class);
9292
}
93-
94-
/**
95-
* Check if user is downvoted given item.
96-
*
97-
* @param int|array|\Illuminate\Database\Eloquent\Model $target
98-
* @param string $class
99-
*
100-
* @return bool
101-
*/
102-
public function hasDownvoted($target, $class = __CLASS__)
103-
{
104-
return Follow::isRelationExists($this, 'downvote', $target, $class);
105-
}
106-
107-
/**
108-
* Return item votes.
109-
*
110-
* @param string $class
111-
*
112-
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
113-
*/
114-
public function votes($class = __CLASS__)
115-
{
116-
return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table'))
117-
->wherePivotIn('relation', [Follow::RELATION_UPVOTE, Follow::RELATION_DOWNVOTE])
118-
->withPivot('followable_type', 'relation', 'created_at');
119-
}
93+
94+
/**
95+
* Check if user is downvoted given item.
96+
*
97+
* @param int|array|\Illuminate\Database\Eloquent\Model $target
98+
* @param string $class
99+
*
100+
* @return bool
101+
*/
102+
public function hasDownvoted($target, $class = __CLASS__)
103+
{
104+
return Follow::isRelationExists($this, 'downvote', $target, $class);
105+
}
106+
107+
/**
108+
* Return item votes.
109+
*
110+
* @param string $class
111+
*
112+
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
113+
*/
114+
public function votes($class = __CLASS__)
115+
{
116+
return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table'))
117+
->wherePivotIn('relation', [Follow::RELATION_UPVOTE, Follow::RELATION_DOWNVOTE])
118+
->withPivot('followable_type', 'relation', 'created_at');
119+
}
120120

121121
/**
122122
* Return item upvotes.
@@ -131,18 +131,18 @@ public function upvotes($class = __CLASS__)
131131
->wherePivot('relation', '=', Follow::RELATION_UPVOTE)
132132
->withPivot('followable_type', 'relation', 'created_at');
133133
}
134-
135-
/**
136-
* Return item downvotes.
137-
*
138-
* @param string $class
139-
*
140-
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
141-
*/
142-
public function downvotes($class = __CLASS__)
143-
{
144-
return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table'))
145-
->wherePivot('relation', '=', Follow::RELATION_DOWNVOTE)
146-
->withPivot('followable_type', 'relation', 'created_at');
147-
}
134+
135+
/**
136+
* Return item downvotes.
137+
*
138+
* @param string $class
139+
*
140+
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
141+
*/
142+
public function downvotes($class = __CLASS__)
143+
{
144+
return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table'))
145+
->wherePivot('relation', '=', Follow::RELATION_DOWNVOTE)
146+
->withPivot('followable_type', 'relation', 'created_at');
147+
}
148148
}

0 commit comments

Comments
 (0)