77use App \Models \User ;
88use Illuminate \Database \Eloquent \Collection ;
99use Illuminate \Database \Eloquent \Relations \HasMany ;
10- use Illuminate \Support \Str ;
10+ use Illuminate \Support \Number ;
1111use Laravelcm \Gamify \Exceptions \InvalidPayeeModelException ;
1212use Laravelcm \Gamify \Exceptions \PointsNotDefinedException ;
1313use Laravelcm \Gamify \Exceptions \PointSubjectNotSetException ;
@@ -30,14 +30,18 @@ public function givePoint(PointType $pointType): bool
3030 }
3131
3232 if ($ this ->storeReputation ($ pointType )) {
33- return $ pointType ->payee ()->addPoint ($ pointType ->getPoints ());
33+ $ pointType ->payee ()->addPoint ($ pointType ->getPoints ());
34+ return true ;
3435 }
36+
37+ return false ;
3538 }
3639
3740 /**
3841 * Undo last given point for a subject model
3942 *
4043 * @throws InvalidPayeeModelException
44+ * @throws PointSubjectNotSetException
4145 */
4246 public function undoPoint (PointType $ pointType ): bool
4347 {
@@ -47,12 +51,13 @@ public function undoPoint(PointType $pointType): bool
4751 return false ;
4852 }
4953
50- // undo reputation
5154 $ reputation ->undo ();
5255 }
5356
5457 /**
5558 * Reputations of user relation
59+ *
60+ * @return HasMany<User>
5661 */
5762 public function reputations (): HasMany
5863 {
@@ -74,16 +79,13 @@ public function storeReputation(PointType $pointType, array $meta = []): bool
7479 return false ;
7580 }
7681
77- return $ pointType ->storeReputation ($ meta );
82+ return $ pointType ->storeReputation ($ meta ) instanceof \ Laravelcm \ Gamify \ Models \Reputation ;
7883 }
7984
8085 /**
8186 * Give point to a user
82- *
83- * @param int $point
84- * @return HasReputations
8587 */
86- public function addPoint ($ point = 1 )
88+ public function addPoint (int $ point = 1 ): static
8789 {
8890 $ this ->increment ($ this ->getReputationField (), $ point );
8991
@@ -92,11 +94,8 @@ public function addPoint($point = 1)
9294
9395 /**
9496 * Reduce a user point
95- *
96- * @param int $point
97- * @return HasReputations
9897 */
99- public function reducePoint ($ point = 1 )
98+ public function reducePoint (int $ point = 1 ): static
10099 {
101100 $ this ->decrement ($ this ->getReputationField (), $ point );
102101
@@ -105,10 +104,8 @@ public function reducePoint($point = 1)
105104
106105 /**
107106 * Reset a user point to zero
108- *
109- * @return mixed
110107 */
111- public function resetPoint (): mixed
108+ public function resetPoint (): static
112109 {
113110 $ this ->forceFill ([$ this ->getReputationField () => 0 ])->save ();
114111
@@ -117,25 +114,16 @@ public function resetPoint(): mixed
117114
118115 /**
119116 * Get user reputation point
120- *
121- * @param bool $formatted
122- * @return int|string
123117 */
124118 public function getPoints (bool $ formatted = false ): int |string
125119 {
126120 $ point = $ this ->{$ this ->getReputationField ()};
127121
128- if ($ formatted ) {
129- return Str::numbers ($ point );
130- }
131-
132- return (int ) $ point ;
122+ return $ formatted ? Number::abbreviate ($ point ) : (int ) $ point ;
133123 }
134124
135125 /**
136126 * Get the reputation column name
137- *
138- * @return string
139127 */
140128 protected function getReputationField (): string
141129 {
@@ -146,8 +134,6 @@ protected function getReputationField(): string
146134
147135 /**
148136 * Check for duplicate point allowed
149- *
150- * @return bool
151137 */
152138 protected function isDuplicatePointAllowed (PointType $ pointType ): bool
153139 {
0 commit comments