Skip to content

Commit b29b8f5

Browse files
committed
fix docblocks - add type hint for exceptions - fix return types
1 parent beee8d7 commit b29b8f5

11 files changed

+36
-58
lines changed

src/Exceptions/InsufficientBalanceException.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33
namespace HPWebdeveloper\LaravelPayPocket\Exceptions;
44

55
use Exception;
6+
use Throwable;
67

78
class InsufficientBalanceException extends Exception
89
{
9-
/**
10-
* Construct the exception.
11-
*
12-
* @param string $message
13-
* @param int $code
14-
*/
15-
public function __construct($message = 'Insufficient balance to cover the order', $code = 0, ?\Throwable $previous = null)
10+
public function __construct(string $message = 'Insufficient balance to cover the order', int $code = 0, ?Throwable $previous = null)
1611
{
1712
parent::__construct($message, $code, $previous);
1813
}

src/Exceptions/InvalidDepositException.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33
namespace HPWebdeveloper\LaravelPayPocket\Exceptions;
44

55
use Exception;
6+
use Throwable;
67

78
class InvalidDepositException extends Exception
89
{
9-
/**
10-
* Construct the exception.
11-
*
12-
* @param string $message
13-
* @param int $code
14-
*/
15-
public function __construct($message = 'Invalid deposit operation', $code = 0, ?\Throwable $previous = null)
10+
public function __construct(string $message = 'Invalid deposit operation', int $code = 0, ?Throwable $previous = null)
1611
{
1712
parent::__construct($message, $code, $previous);
1813
}

src/Exceptions/InvalidValueException.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33
namespace HPWebdeveloper\LaravelPayPocket\Exceptions;
44

55
use Exception;
6+
use Throwable;
67

78
class InvalidValueException extends Exception
89
{
9-
/**
10-
* Construct the exception.
11-
*
12-
* @param string $message
13-
* @param int $code
14-
*/
15-
public function __construct($message = 'Invalie value to deposit', $code = 0, ?\Throwable $previous = null)
10+
public function __construct(string $message = 'Invalie value to deposit', int $code = 0, ?Throwable $previous = null)
1611
{
1712
parent::__construct($message, $code, $previous);
1813
}

src/Exceptions/InvalidWalletTypeException.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
namespace HPWebdeveloper\LaravelPayPocket\Exceptions;
44

55
use Exception;
6+
use Throwable;
67

78
class InvalidWalletTypeException extends Exception
89
{
9-
public function __construct($message = 'Invalid wallet type', $code = 0, ?\Throwable $previous = null)
10+
public function __construct(string $message = 'Invalid wallet type', int $code = 0, ?Throwable $previous = null)
1011
{
1112
parent::__construct($message, $code, $previous);
1213
}

src/Exceptions/WalletNotFoundException.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
namespace HPWebdeveloper\LaravelPayPocket\Exceptions;
44

55
use Exception;
6+
use Throwable;
67

78
class WalletNotFoundException extends Exception
89
{
9-
public function __construct($message = 'Wallet not found', $code = 0, ?\Throwable $previous = null)
10+
public function __construct(string $message = 'Wallet not found', int $code = 0, ?Throwable $previous = null)
1011
{
1112
parent::__construct($message, $code, $previous);
1213
}

src/Facades/LaravelPayPocket.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
namespace HPWebdeveloper\LaravelPayPocket\Facades;
44

5+
use HPWebdeveloper\LaravelPayPocket\Interfaces\WalletOperations;
56
use Illuminate\Support\Facades\Facade;
67

78
/**
89
* @see \HPWebdeveloper\LaravelPayPocket\Services\PocketServices
910
*
10-
* @method static void pay(\Illuminate\Database\Eloquent\Model $user, int|float $orderValue, ?string $notes = null)
11-
* @method static bool deposit(\Illuminate\Database\Eloquent\Model $user, string $type, int|float $amount, ?string $notes = null)
12-
* @method static int|float checkBalance(\Illuminate\Database\Eloquent\Model $user)
13-
* @method static int|float walletBalanceByType(\Illuminate\Database\Eloquent\Model $user, string $type)
11+
* @method static void pay(WalletOperations $user, int|float $orderValue, ?string $notes = null)
12+
* @method static bool deposit(WalletOperations $user, string $type, int|float $amount, ?string $notes = null)
13+
* @method static int|float checkBalance(WalletOperations $user)
14+
* @method static int|float walletBalanceByType(WalletOperations $user, string $type)
1415
*/
1516
class LaravelPayPocket extends Facade
1617
{
17-
protected static function getFacadeAccessor()
18+
protected static function getFacadeAccessor(): string
1819
{
1920
return \HPWebdeveloper\LaravelPayPocket\Services\PocketServices::class;
2021
}

src/Interfaces/WalletOperations.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace HPWebdeveloper\LaravelPayPocket\Interfaces;
44

5+
use HPWebdeveloper\LaravelPayPocket\Exceptions\InsufficientBalanceException;
6+
57
interface WalletOperations
68
{
79
/**
@@ -12,7 +14,7 @@ public function getWalletBalanceAttribute(): int|float;
1214
/**
1315
* Get the balance of a specific wallet type.
1416
*/
15-
public function getWalletBalanceByType(string $walletType): float|int;
17+
public function getWalletBalanceByType(string $walletType): int|float;
1618

1719
/**
1820
* Check if User's wallet balance is more than given value
@@ -22,16 +24,12 @@ public function hasSufficientBalance(int|float $value): bool;
2224
/**
2325
* Pay the order value from the user's wallets.
2426
*
25-
* @param ?string $notes
26-
*
27-
* @throws \HPWebdeveloper\LaravelPayPocket\Exceptions\InsufficientBalanceException
27+
* @throws InsufficientBalanceException
2828
*/
2929
public function pay(int|float $orderValue, ?string $notes = null): void;
3030

3131
/**
3232
* Deposit an amount to the user's wallet of a specific type.
33-
*
34-
* @param ?string $notes
3533
*/
3634
public function deposit(string $type, int|float $amount, ?string $notes = null): bool;
3735
}

src/Services/PocketServices.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,41 @@
22

33
namespace HPWebdeveloper\LaravelPayPocket\Services;
44

5-
use Illuminate\Database\Eloquent\Model;
5+
use HPWebdeveloper\LaravelPayPocket\Exceptions\InsufficientBalanceException;
6+
use HPWebdeveloper\LaravelPayPocket\Interfaces\WalletOperations;
67

78
class PocketServices
89
{
910
/**
1011
* Deposit an amount to the user's wallet of a specific type.
11-
*
12-
* @param ?string $notes
1312
*/
14-
public function deposit(Model $user, string $type, int|float $amount, ?string $notes = null): bool
13+
public function deposit(WalletOperations $user, string $type, int|float $amount, ?string $notes = null): bool
1514
{
1615
return $user->deposit($type, $amount, $notes);
1716
}
1817

1918
/**
2019
* Pay the order value from the user's wallets.
2120
*
22-
* @param ?string $notes
23-
*
24-
* @throws \HPWebdeveloper\LaravelPayPocket\Exceptions\InsufficientBalanceException
21+
* @throws InsufficientBalanceException
2522
*/
26-
public function pay(Model $user, int|float $orderValue, ?string $notes = null): void
23+
public function pay(WalletOperations $user, int|float $orderValue, ?string $notes = null): void
2724
{
2825
$user->pay($orderValue, $notes);
2926
}
3027

3128
/**
3229
* Get the balance of the user.
3330
*/
34-
public function checkBalance(Model $user): int|float
31+
public function checkBalance(WalletOperations $user): int|float
3532
{
3633
return $user->walletBalance;
3734
}
3835

3936
/**
4037
* Get the balance of a specific wallet type.
4138
*/
42-
public function walletBalanceByType(Model $user, string $type): float|int
39+
public function walletBalanceByType(WalletOperations $user, string $type): int|float
4340
{
4441
return $user->getWalletBalanceByType($type);
4542
}

src/Traits/HandlesDeposit.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88
use HPWebdeveloper\LaravelPayPocket\Exceptions\InvalidWalletTypeException;
99
use Illuminate\Support\Facades\DB;
1010

11-
// Use your defined exception
12-
1311
trait HandlesDeposit
1412
{
1513
/**
1614
* Deposit an amount to the user's wallet of a specific type.
1715
*
18-
* @param ?string $notes
19-
*
20-
* @throws InvalidDepositException|InvalidValueException|InvalidWalletTypeException
16+
* @throws InvalidDepositException
17+
* @throws InvalidValueException
18+
* @throws InvalidWalletTypeException
2119
*/
2220
public function deposit(string $type, int|float $amount, ?string $notes = null): bool
2321
{
@@ -56,9 +54,6 @@ private function getDepositableTypes(): array
5654
/**
5755
* Check if the given type is valid.
5856
*
59-
* @var string
60-
* @var array
61-
*
6257
* @throws InvalidWalletTypeException
6358
*/
6459
private function isRequestValid($type, array $depositable): bool

src/Traits/HandlesPayment.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ trait HandlesPayment
1010
/**
1111
* Pay the order value from the user's wallets.
1212
*
13-
* @param ?string $notes
14-
*
15-
* @throws \HPWebdeveloper\LaravelPayPocket\Exceptions\InsufficientBalanceException
13+
* @throws InsufficientBalanceException
1614
*/
1715
public function pay(int|float $orderValue, ?string $notes = null): void
1816
{

0 commit comments

Comments
 (0)