Skip to content

Commit

Permalink
Increased the severity of code style. Preparing to work with a binary…
Browse files Browse the repository at this point in the history
… string
  • Loading branch information
rez1dent3 committed May 2, 2022
1 parent 60154b4 commit 75225a4
Show file tree
Hide file tree
Showing 24 changed files with 70 additions and 136 deletions.
5 changes: 4 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

use Rector\CodeQuality\Rector\PropertyFetch\ExplicitMethodCallOverMagicGetSetRector;
use Rector\Core\Configuration\Option;
use Rector\Laravel\Set\LaravelSetList;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Php80\Rector\FunctionLike\UnionTypesRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
Expand All @@ -18,9 +18,12 @@
__DIR__ . '/tests',
]);

$parameters->set(Option::SKIP, [ExplicitMethodCallOverMagicGetSetRector::class]);

// Define what rule sets will be applied
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_91);
$containerConfigurator->import(LaravelSetList::LARAVEL_80);
$containerConfigurator->import(SetList::CODE_QUALITY);
$containerConfigurator->import(SetList::DEAD_CODE);
$containerConfigurator->import(SetList::PHP_80);

Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Assembler/TransactionDtoAssembler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function create(
Model $payable,
int $walletId,
string $type,
string $amount,
float|int|string $amount,
bool $confirmed,
?array $meta
): TransactionDtoInterface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function create(
Model $payable,
int $walletId,
string $type,
string $amount,
float|int|string $amount,
bool $confirmed,
?array $meta
): TransactionDtoInterface;
Expand Down
4 changes: 2 additions & 2 deletions src/Internal/Dto/TransactionDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(
private int|string $payableId,
private int $walletId,
private string $type,
private string $amount,
private float|int|string $amount,
private bool $confirmed,
private ?array $meta
) {
Expand Down Expand Up @@ -51,7 +51,7 @@ public function getType(): string
return $this->type;
}

public function getAmount(): string
public function getAmount(): float|int|string
{
return $this->amount;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Dto/TransactionDtoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function getWalletId(): int;

public function getType(): string;

public function getAmount(): string;
public function getAmount(): float|int|string;

public function isConfirmed(): bool;

Expand Down
5 changes: 4 additions & 1 deletion src/Internal/Repository/WalletRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

use Bavix\Wallet\Internal\Exceptions\ExceptionInterface;
use Bavix\Wallet\Internal\Exceptions\ModelNotFoundException;
use Bavix\Wallet\Internal\Service\UuidFactoryService;
use Bavix\Wallet\Internal\Service\UuidFactoryServiceInterface;
use Bavix\Wallet\Models\Wallet;
use Illuminate\Database\Eloquent\ModelNotFoundException as EloquentModelNotFoundException;

final class WalletRepository implements WalletRepositoryInterface
{
public function __construct(
private UuidFactoryServiceInterface $uuidFactoryService,
private Wallet $wallet
) {
}
Expand Down Expand Up @@ -67,7 +70,7 @@ public function getById(int $id): Wallet
public function getByUuid(string $uuid): Wallet
{
return $this->getBy([
'uuid' => $uuid,
'uuid' => $this->uuidFactoryService->cast($uuid),
]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Internal/Service/DispatcherService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public function dispatch(EventInterface $event): void

public function flush(): void
{
foreach ($this->events as $event => $value) {
foreach (array_keys($this->events) as $event) {
$this->dispatcher->flush($event);
}
}

public function forgot(): void
{
foreach ($this->events as $event => $value) {
foreach (array_keys($this->events) as $event) {
$this->dispatcher->forget($event);
}
}
Expand Down
60 changes: 12 additions & 48 deletions src/Internal/Service/MathService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,118 +17,82 @@ public function __construct(ConfigRepository $config)
$this->scale = (int) $config->get('wallet.math.scale', 64);
}

/**
* {@inheritdoc}
*/
public function add($first, $second, ?int $scale = null): string
public function add(float|int|string $first, float|int|string $second, ?int $scale = null): string
{
return (string) BigDecimal::of($first)
->plus(BigDecimal::of($second))
->toScale($scale ?? $this->scale, RoundingMode::DOWN)
;
}

/**
* {@inheritdoc}
*/
public function sub($first, $second, ?int $scale = null): string
public function sub(float|int|string $first, float|int|string $second, ?int $scale = null): string
{
return (string) BigDecimal::of($first)
->minus(BigDecimal::of($second))
->toScale($scale ?? $this->scale, RoundingMode::DOWN)
;
}

/**
* {@inheritdoc}
*/
public function div($first, $second, ?int $scale = null): string
public function div(float|int|string $first, float|int|string $second, ?int $scale = null): string
{
return (string) BigDecimal::of($first)
->dividedBy(BigDecimal::of($second), $scale ?? $this->scale, RoundingMode::DOWN)
;
}

/**
* {@inheritdoc}
*/
public function mul($first, $second, ?int $scale = null): string
public function mul(float|int|string $first, float|int|string $second, ?int $scale = null): string
{
return (string) BigDecimal::of($first)
->multipliedBy(BigDecimal::of($second))
->toScale($scale ?? $this->scale, RoundingMode::DOWN)
;
}

/**
* {@inheritdoc}
*/
public function pow($first, $second, ?int $scale = null): string
public function pow(float|int|string $first, float|int|string $second, ?int $scale = null): string
{
return (string) BigDecimal::of($first)
->power((int) $second)
->toScale($scale ?? $this->scale, RoundingMode::DOWN)
;
}

/**
* {@inheritdoc}
*/
public function powTen($number): string
public function powTen(float|int|string $number): string
{
return $this->pow(10, $number);
}

/**
* {@inheritdoc}
*/
public function ceil($number): string
public function ceil(float|int|string $number): string
{
return (string) BigDecimal::of($number)
->dividedBy(BigDecimal::one(), 0, RoundingMode::CEILING)
;
}

/**
* {@inheritdoc}
*/
public function floor($number): string
public function floor(float|int|string $number): string
{
return (string) BigDecimal::of($number)
->dividedBy(BigDecimal::one(), 0, RoundingMode::FLOOR)
;
}

/**
* {@inheritdoc}
*/
public function round($number, int $precision = 0): string
public function round(float|int|string $number, int $precision = 0): string
{
return (string) BigDecimal::of($number)
->dividedBy(BigDecimal::one(), $precision, RoundingMode::HALF_UP)
;
}

/**
* {@inheritdoc}
*/
public function abs($number): string
public function abs(float|int|string $number): string
{
return (string) BigDecimal::of($number)->abs();
}

/**
* {@inheritdoc}
*/
public function negative($number): string
public function negative(float|int|string $number): string
{
return (string) BigDecimal::of($number)->negated();
}

/**
* {@inheritdoc}
*/
public function compare($first, $second): int
public function compare(float|int|string $first, float|int|string $second): int
{
return BigDecimal::of($first)->compareTo(BigDecimal::of($second));
}
Expand Down
66 changes: 12 additions & 54 deletions src/Internal/Service/MathServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,27 @@

interface MathServiceInterface
{
/**
* @param float|int|string $first
* @param float|int|string $second
*/
public function add($first, $second, ?int $scale = null): string;
public function add(float|int|string $first, float|int|string $second, ?int $scale = null): string;

/**
* @param float|int|string $first
* @param float|int|string $second
*/
public function sub($first, $second, ?int $scale = null): string;
public function sub(float|int|string $first, float|int|string $second, ?int $scale = null): string;

/**
* @param float|int|string $first
* @param float|int|string $second
*/
public function div($first, $second, ?int $scale = null): string;
public function div(float|int|string $first, float|int|string $second, ?int $scale = null): string;

/**
* @param float|int|string $first
* @param float|int|string $second
*/
public function mul($first, $second, ?int $scale = null): string;
public function mul(float|int|string $first, float|int|string $second, ?int $scale = null): string;

/**
* @param float|int|string $first
* @param float|int|string $second
*/
public function pow($first, $second, ?int $scale = null): string;
public function pow(float|int|string $first, float|int|string $second, ?int $scale = null): string;

/**
* @param float|int|string $number
*/
public function powTen($number): string;
public function powTen(float|int|string $number): string;

/**
* @param float|int|string $number
*/
public function round($number, int $precision = 0): string;
public function round(float|int|string $number, int $precision = 0): string;

/**
* @param float|int|string $number
*/
public function floor($number): string;
public function floor(float|int|string $number): string;

/**
* @param float|int|string $number
*/
public function ceil($number): string;
public function ceil(float|int|string $number): string;

/**
* @param float|int|string $number
*/
public function abs($number): string;
public function abs(float|int|string $number): string;

/**
* @param float|int|string $number
*/
public function negative($number): string;
public function negative(float|int|string $number): string;

/**
* @param float|int|string $first
* @param float|int|string $second
*/
public function compare($first, $second): int;
public function compare(float|int|string $first, float|int|string $second): int;
}
5 changes: 5 additions & 0 deletions src/Internal/Service/UuidFactoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ public function uuid4(): string
->toString()
;
}

public function cast(string $uuid): string
{
return $uuid;
}
}
2 changes: 2 additions & 0 deletions src/Internal/Service/UuidFactoryServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
interface UuidFactoryServiceInterface
{
public function uuid4(): string;

public function cast(string $uuid): string;
}
2 changes: 1 addition & 1 deletion src/Models/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Transaction extends Model

public function getTable(): string
{
if (!$this->table) {
if ((string) $this->table === '') {
$this->table = config('wallet.transaction.table', 'transactions');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Models/Transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Transfer extends Model

public function getTable(): string
{
if (!$this->table) {
if ((string) $this->table === '') {
$this->table = config('wallet.transfer.table', 'transfers');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Models/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Wallet extends Model implements Customer, WalletFloat, Confirmable, Exchan

public function getTable(): string
{
if (!$this->table) {
if ((string) $this->table === '') {
$this->table = config('wallet.wallet.table', 'wallets');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Objects/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function getBasketDto(): BasketDtoInterface
$this->getUniqueItems()
);

if (count($items) === 0) {
if ($items === []) {
throw new CartEmptyException('Cart is empty', ExceptionInterface::CART_EMPTY);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Services/AtmService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function makeTransactions(array $objects): array
$items = $this->transactionRepository->findBy($query);
}

assert(count($items) > 0);
assert($items !== []);

$results = [];
foreach ($items as $item) {
Expand All @@ -67,7 +67,7 @@ public function makeTransfers(array $objects): array
$items = $this->transferRepository->findBy($query);
}

assert(count($items) > 0);
assert($items !== []);

$results = [];
foreach ($items as $item) {
Expand Down
Loading

0 comments on commit 75225a4

Please sign in to comment.