Skip to content

Commit

Permalink
Merge pull request #21 from mpociot/fix-exception-names
Browse files Browse the repository at this point in the history
Fix exception names
  • Loading branch information
zgabievi authored Jul 7, 2018
2 parents a54ece9 + 320bfaa commit 7171997
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Exception;

class AlreadyUsedExceprion extends Exception
class AlreadyUsedException extends Exception
{
/**
* @var string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Exception;

class InvalidPromocodeExceprion extends Exception
class InvalidPromocodeException extends Exception
{
/**
* @var string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Exception;

class UnauthenticatedExceprion extends Exception
class UnauthenticatedException extends Exception
{
/**
* @var string
Expand Down
24 changes: 12 additions & 12 deletions src/Promocodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use Carbon\Carbon;
use Gabievi\Promocodes\Models\Promocode;
use Gabievi\Promocodes\Exceptions\AlreadyUsedExceprion;
use Gabievi\Promocodes\Exceptions\UnauthenticatedExceprion;
use Gabievi\Promocodes\Exceptions\InvalidPromocodeExceprion;
use Gabievi\Promocodes\Exceptions\AlreadyUsedException;
use Gabievi\Promocodes\Exceptions\UnauthenticatedException;
use Gabievi\Promocodes\Exceptions\InvalidPromocodeException;

class Promocodes
{
Expand Down Expand Up @@ -120,14 +120,14 @@ public function createDisposable($amount = 1, $reward = null, array $data = [],
* @param string $code
*
* @return bool|\Gabievi\Promocodes\Model\Promocode
* @throws \Gabievi\Promocodes\Exceptions\InvalidPromocodeExceprion
* @throws \Gabievi\Promocodes\Exceptions\InvalidPromocodeException
*/
public function check($code)
{
$promocode = Promocode::byCode($code)->first();

if ($promocode === null) {
throw new InvalidPromocodeExceprion;
throw new InvalidPromocodeException;
}

if ($promocode->isExpired() || ($promocode->isDisposable() && $promocode->users()->exists())) {
Expand All @@ -143,18 +143,18 @@ public function check($code)
* @param string $code
*
* @return bool|\Gabievi\Promocodes\Model\Promocode
* @throws \Gabievi\Promocodes\Exceptions\UnauthenticatedExceprion|\Gabievi\Promocodes\Exceptions\AlreadyUsedExceprion
* @throws \Gabievi\Promocodes\Exceptions\UnauthenticatedException|\Gabievi\Promocodes\Exceptions\AlreadyUsedException
*/
public function apply($code)
{
if (!auth()->check()) {
throw new UnauthenticatedExceprion;
throw new UnauthenticatedException;
}

try {
if ($promocode = $this->check($code)) {
if ($this->isSecondUsageAttempt($promocode)) {
throw new AlreadyUsedExceprion;
throw new AlreadyUsedException;
}

$promocode->users()->attach(auth()->user()->id, [
Expand All @@ -163,7 +163,7 @@ public function apply($code)

return $promocode->load('users');
}
} catch(InvalidPromocodeExceprion $exception) {
} catch (InvalidPromocodeException $exception) {
//
}

Expand All @@ -176,7 +176,7 @@ public function apply($code)
* @param string $code
*
* @return bool|\Gabievi\Promocodes\Model\Promocode
* @throws \Gabievi\Promocodes\Exceptions\UnauthenticatedExceprion|\Gabievi\Promocodes\Exceptions\AlreadyUsedExceprion
* @throws \Gabievi\Promocodes\Exceptions\UnauthenticatedException|\Gabievi\Promocodes\Exceptions\AlreadyUsedException
*/
public function redeem($code)
{
Expand All @@ -188,14 +188,14 @@ public function redeem($code)
*
* @param string $code
* @return bool
* @throws \Gabievi\Promocodes\Exceptions\InvalidPromocodeExceprion
* @throws \Gabievi\Promocodes\Exceptions\InvalidPromocodeException
*/
public function disable($code)
{
$promocode = Promocode::byCode($code)->first();

if ($promocode === null) {
throw new InvalidPromocodeExceprion;
throw new InvalidPromocodeException;
}

$promocode->expires_at = Carbon::now();
Expand Down
12 changes: 6 additions & 6 deletions src/Traits/Rewardable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Carbon\Carbon;
use Gabievi\Promocodes\Models\Promocode;
use Gabievi\Promocodes\Facades\Promocodes;
use Gabievi\Promocodes\Exceptions\AlreadyUsedExceprion;
use Gabievi\Promocodes\Exceptions\InvalidPromocodeExceprion;
use Gabievi\Promocodes\Exceptions\AlreadyUsedException;
use Gabievi\Promocodes\Exceptions\InvalidPromocodeException;

trait Rewardable
{
Expand All @@ -28,14 +28,14 @@ public function promocodes()
* @param null|\Closure $callback
*
* @return null|\Gabievi\Promocodes\Model\Promocode
* @throws \Gabievi\Promocodes\Exceptions\AlreadyUsedExceprion
* @throws \Gabievi\Promocodes\Exceptions\AlreadyUsedException
*/
public function applyCode($code, $callback = null)
{
try {
if ($promocode = Promocodes::check($code)) {
if ($promocode->users()->wherePivot('user_id', $this->id)->exists()) {
throw new AlreadyUsedExceprion;
throw new AlreadyUsedException;
}

$promocode->users()->attach($this->id, [
Expand All @@ -50,7 +50,7 @@ public function applyCode($code, $callback = null)

return $promocode;
}
} catch (InvalidPromocodeExceprion $exception) {
} catch (InvalidPromocodeException $exception) {
//
}

Expand All @@ -68,7 +68,7 @@ public function applyCode($code, $callback = null)
* @param null|\Closure $callback
*
* @return null|\Gabievi\Promocodes\Model\Promocode
* @throws \Gabievi\Promocodes\Exceptions\AlreadyUsedExceprion
* @throws \Gabievi\Promocodes\Exceptions\AlreadyUsedException
*/
public function redeemCode($code, $callback = null)
{
Expand Down
8 changes: 4 additions & 4 deletions tests/ApplyPromocodeToUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
use Promocodes;
use Gabievi\Promocodes\Models\Promocode;
use Gabievi\Promocodes\Test\Models\User;
use Gabievi\Promocodes\Exceptions\AlreadyUsedExceprion;
use Gabievi\Promocodes\Exceptions\UnauthenticatedExceprion;
use Gabievi\Promocodes\Exceptions\AlreadyUsedException;
use Gabievi\Promocodes\Exceptions\UnauthenticatedException;

class ApplyPromocodeToUserTest extends TestCase
{
/** @test */
public function it_throws_exception_if_user_is_not_authenticated()
{
$this->expectException(UnauthenticatedExceprion::class);
$this->expectException(UnauthenticatedException::class);

$promocodes = Promocodes::create();
$promocode = $promocodes->first();
Expand All @@ -37,7 +37,7 @@ public function it_returns_false_if_promocode_doesnt_exist()
/** @test */
public function it_throws_exception_if_user_tries_to_apply_code_twice()
{
$this->expectException(AlreadyUsedExceprion::class);
$this->expectException(AlreadyUsedException::class);

$user = User::find(1);
$this->actingAs($user);
Expand Down
4 changes: 2 additions & 2 deletions tests/CheckPromocodeValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
use Promocodes;
use Gabievi\Promocodes\Models\Promocode;
use Gabievi\Promocodes\Test\Models\User;
use Gabievi\Promocodes\Exceptions\InvalidPromocodeExceprion;
use Gabievi\Promocodes\Exceptions\InvalidPromocodeException;

class CheckPromocodeValidationTest extends TestCase
{
/** @test */
public function it_throws_exception_if_there_is_not_such_promocode()
{
$this->expectException(InvalidPromocodeExceprion::class);
$this->expectException(InvalidPromocodeException::class);

Promocodes::check('INVALID-CODE');
}
Expand Down
4 changes: 2 additions & 2 deletions tests/DisablePromocodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

use Promocodes;
use Gabievi\Promocodes\Models\Promocode;
use Gabievi\Promocodes\Exceptions\InvalidPromocodeExceprion;
use Gabievi\Promocodes\Exceptions\InvalidPromocodeException;

class DisablePromocodeTest extends TestCase
{
/** @test */
public function it_thows_exception_if_promocode_is_invalid()
{
$this->expectException(InvalidPromocodeExceprion::class);
$this->expectException(InvalidPromocodeException::class);

Promocodes::disable('INVALID-CODE');
}
Expand Down
4 changes: 2 additions & 2 deletions tests/RewardableTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Promocodes;
use Gabievi\Promocodes\Models\Promocode;
use Gabievi\Promocodes\Test\Models\User;
use Gabievi\Promocodes\Exceptions\AlreadyUsedExceprion;
use Gabievi\Promocodes\Exceptions\AlreadyUsedException;

class RewardableTraitTest extends TestCase
{
Expand Down Expand Up @@ -40,7 +40,7 @@ public function it_returns_null_in_callback_if_could_not_apply_promocode()
/** @test */
public function it_throws_exception_if_user_already_applied_to_code()
{
$this->expectException(AlreadyUsedExceprion::class);
$this->expectException(AlreadyUsedException::class);

$promocodes = Promocodes::create();
$promocode = $promocodes->first();
Expand Down

0 comments on commit 7171997

Please sign in to comment.