diff --git a/src/Visits.php b/src/Visits.php index b1107d9..14ebcff 100755 --- a/src/Visits.php +++ b/src/Visits.php @@ -195,6 +195,7 @@ protected function isCrawler() * @param int $inc value to increment * @param bool $force force increment, skip time limit * @param array $ignore to ignore recording visits of periods, country, refer, language and operatingSystem. pass them on this array. + * @return bool */ public function increment($inc = 1, $force = false, $ignore = []) { @@ -212,16 +213,21 @@ public function increment($inc = 1, $force = false, $ignore = []) $this->{'record'.Str::studly($method)}($inc); } } + + return true; } + + return false; } /** * @param int $inc * @param array $ignore to ignore recording visits like country, periods ... + * @return bool */ public function forceIncrement($inc = 1, $ignore = []) { - $this->increment($inc, true, $ignore); + return $this->increment($inc, true, $ignore); } /** @@ -229,19 +235,21 @@ public function forceIncrement($inc = 1, $ignore = []) * * @param int $dec * @param array $ignore to ignore recording visits like country, periods ... + * @return bool */ public function decrement($dec = 1, $force = false, $ignore = []) { - $this->increment(-$dec, $force, $ignore); + return $this->increment(-$dec, $force, $ignore); } /** * @param int $dec * @param array $ignore to ignore recording visits like country, periods ... + * @return bool */ public function forceDecrement($dec = 1, $ignore = []) { - $this->decrement($dec, true, $ignore); + return $this->decrement($dec, true, $ignore); } /** diff --git a/tests/Feature/VisitsTestCase.php b/tests/Feature/VisitsTestCase.php index 9f6503b..cb53653 100755 --- a/tests/Feature/VisitsTestCase.php +++ b/tests/Feature/VisitsTestCase.php @@ -30,6 +30,20 @@ public function by_can_accept_array() $this->assertEquals(0, visits($post)->count()); } + /** @test * */ + public function by_cant_repeat_accept_array() + { + User::create(); + $post = Post::create(); + + $firstResult = visits($post)->increment(); + $secondResult = visits($post)->increment(); + + $this->assertTrue($firstResult); + $this->assertFalse($secondResult); + $this->assertEquals(1, visits($post)->count()); + } + /** @test * */ public function visits_by_user_lists() {