Skip to content

Commit e692811

Browse files
committed
Revert "Ability to give or update the points to a reputation record"
This reverts commit a2f43c3.
1 parent a2f43c3 commit e692811

File tree

4 files changed

+0
-123
lines changed

4 files changed

+0
-123
lines changed

src/HasReputations.php

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,6 @@ public function givePoint(PointType $pointType)
2323
}
2424
}
2525

26-
/**
27-
* Give or update reputation points to payee
28-
*
29-
* @param PointType $pointType
30-
* @return bool
31-
*/
32-
public function giveOrUpdatePoint(PointType $pointType)
33-
{
34-
if (!$pointType->qualifier()) {
35-
return false;
36-
}
37-
38-
if ($pointType->reputationExists()) {
39-
$originalPoints = $pointType->syncPointsChange();
40-
return $pointType->payee()->syncPointsChange($originalPoints, $pointType->getPoints());
41-
}else if ($this->storeReputation($pointType)) {
42-
return $pointType->payee()->addPoint($pointType->getPoints());
43-
}
44-
}
45-
4626
/**
4727
* Undo last given point for a subject model
4828
*
@@ -102,22 +82,6 @@ public function addPoint($point = 1)
10282
return $this;
10383
}
10484

105-
/**
106-
* Sync points changed for a reputation record to a payee
107-
*
108-
* @param int $point
109-
* @return HasReputations|\Illuminate\Database\Eloquent\Model
110-
*/
111-
public function syncPointsChange($originalPoints, $newPoints = 1)
112-
{
113-
$this->decrement($this->getReputationField(), $originalPoints);
114-
$this->increment($this->getReputationField(), $newPoints);
115-
116-
ReputationChanged::dispatch($this, $newPoints, true);
117-
118-
return $this;
119-
}
120-
12185
/**
12286
* Reduce a user point
12387
*

src/PointType.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,6 @@ public function storeReputation($meta = [])
134134
]);
135135
}
136136

137-
/**
138-
* Sync updates to points to an existing reputation record
139-
* @return int $originalPoints
140-
*/
141-
public function syncPointsChange()
142-
{
143-
$dbPointType = $this->firstReputation();
144-
$originalPoints = $dbPointType->point;
145-
$dbPointType->update([
146-
'point' => $this->getPoints()
147-
]);
148-
return $originalPoints;
149-
}
150-
151137
/**
152138
* Get reputation query for this point
153139
*

src/helpers.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,6 @@ function givePoint(PointType $pointType, $payee = null)
2222
}
2323
}
2424

25-
if (!function_exists('giveOrUpdatePoint')) {
26-
27-
/**
28-
* Give point to user
29-
*
30-
* @param PointType $pointType
31-
* @param null $payee
32-
*/
33-
function giveOrUpdatePoint(PointType $pointType, $payee = null)
34-
{
35-
$payee = $payee ?? auth()->user();
36-
37-
if (!$payee) {
38-
return;
39-
}
40-
41-
$payee->giveOrUpdatePoint($pointType);
42-
}
43-
}
44-
4525
if (!function_exists('undoPoint')) {
4626

4727
/**

tests/PointTest.php

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -69,41 +69,6 @@ public function it_gives_point_to_a_user()
6969
]);
7070
}
7171

72-
/**
73-
* it gives point to a user, then updates it validating that that change
74-
*
75-
* @test
76-
*/
77-
public function it_gives_and_updates_points_to_a_user()
78-
{
79-
$user = $this->createUser();
80-
$post = $this->createPost(['user_id' => $user->id]);
81-
82-
$user->giveOrUpdatePoint(new FakeUpdateablePostPoint($post));
83-
84-
$this->assertEquals(1, $user->fresh()->getPoints());
85-
$this->assertCount(1, $user->reputations);
86-
$this->assertDatabaseHas('reputations', [
87-
'payee_id' => $user->id,
88-
'subject_type' => $post->getMorphClass(),
89-
'subject_id' => $post->id,
90-
'point' => 1,
91-
'name' => 'FakeUpdateablePostPoint'
92-
]);
93-
94-
$user->giveOrUpdatePoint(new FakeUpdateablePostPoint($post, 5));
95-
96-
$this->assertEquals(5, $user->fresh()->getPoints());
97-
$this->assertCount(1, $user->reputations);
98-
$this->assertDatabaseHas('reputations', [
99-
'payee_id' => $user->id,
100-
'subject_type' => $post->getMorphClass(),
101-
'subject_id' => $post->id,
102-
'point' => 5,
103-
'name' => 'FakeUpdateablePostPoint'
104-
]);
105-
}
106-
10772
/**
10873
* it can access a reputation payee and subject
10974
*
@@ -304,24 +269,6 @@ public function payee()
304269
}
305270
}
306271

307-
class FakeUpdateablePostPoint extends PointType
308-
{
309-
protected $points = 1;
310-
311-
public $allowDuplicates = false;
312-
313-
public function __construct($subject, $points = 1)
314-
{
315-
$this->subject = $subject;
316-
$this->points = $points;
317-
}
318-
319-
public function payee()
320-
{
321-
return $this->getSubject()->user;
322-
}
323-
}
324-
325272
class FakeWelcomeUserWithNamePoint extends PointType
326273
{
327274
protected $name = 'FakeName';

0 commit comments

Comments
 (0)