Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ging-dev committed Oct 2, 2024
1 parent f63d951 commit d9d3372
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 20 deletions.
11 changes: 8 additions & 3 deletions src/Api/AuthenticatedApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
*/
final class AuthenticatedApi extends AbstractApi
{
use LazyGhostTrait;
use LazyGhostTrait {
createLazyGhost as private;
initializeLazyObject as private;
isLazyObjectInitialized as private;
resetLazyObject as private;
}

public Customer $customer;

Expand Down Expand Up @@ -49,9 +54,9 @@ private function populateLazyProperties(): void

public function transactions(?string $accountNumber = null): TransactionBuilder
{
return new TransactionBuilder(
['accountNumber' => $accountNumber ?? $this->customer->accountNumber],
return TransactionBuilder::from(
$this->getTransactions(...),
['accountNumber' => $accountNumber ?? $this->customer->accountNumber],
);
}

Expand Down
24 changes: 20 additions & 4 deletions src/Builder/TransactionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,36 @@
/**
* @psalm-import-type ParametersType from BodyBuilder
*
* @psalm-type GetterType = \Closure(ParametersType):\Traversable<Transaction>
*
* @implements \IteratorAggregate<int,Transaction>
*/
final class TransactionBuilder implements \IteratorAggregate
{
/**
* @param ParametersType $parameters
* @param \Closure(ParametersType):\Traversable<Transaction> $getter
* @param GetterType $getter
* @param ParametersType $parameters
*/
public function __construct(
private array $parameters,
private function __construct(
private \Closure $getter,
private array $parameters,
) {
}

/**
* @param GetterType $getter
* @param ParametersType $parameters
*/
public static function from(
\Closure $getter,
array $parameters,
): self {
return new self(
$getter,
$parameters,
);
}

public function between(
\DateTimeInterface $from,
\DateTimeInterface $to,
Expand Down
32 changes: 30 additions & 2 deletions src/Entity/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,50 @@

namespace IPay\Entity;

use EventSauce\ObjectHydrator\Constructor;

readonly class AccountState
{
public function __construct(
private function __construct(
public int $availableBalance,
public int $balance,
) {
}

#[Constructor]
public static function create(
int $availableBalance,
int $balance,
): self {
return new self(
$availableBalance,
$balance,
);
}
}

readonly class Account
{
public function __construct(
private function __construct(
public string $title,
public string $number,
public string $currencyCode,
public AccountState $accountState,
) {
}

#[Constructor]
public static function create(
string $title,
string $number,
string $currencyCode,
AccountState $accountState,
): self {
return new self(
$title,
$number,
$currencyCode,
$accountState,
);
}
}
25 changes: 17 additions & 8 deletions src/Entity/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@

namespace IPay\Entity;

use EventSauce\ObjectHydrator\MapFrom;
use EventSauce\ObjectHydrator\Constructor;

#[MapFrom([
'fullname' => 'name',
'phone' => 'phone',
'jobTitle' => 'job',
'feeAcctNo' => 'accountNumber',
])]
readonly class Customer
{
public function __construct(
private function __construct(
public string $name,
public string $phone,
public string $job,
public string $accountNumber,
) {
}

#[Constructor]
public static function create(
string $fullname,
string $phone,
string $jobTitle,
string $feeAcctNo,
): self {
return new self(
$fullname,
$phone,
$jobTitle,
$feeAcctNo,
);
}
}
26 changes: 23 additions & 3 deletions src/Entity/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,40 @@

namespace IPay\Entity;

use EventSauce\ObjectHydrator\Constructor;
use EventSauce\ObjectHydrator\PropertyCasters\CastToDateTimeImmutable;
use EventSauce\ObjectHydrator\PropertyCasters\CastToType;

readonly class Transaction
{
public function __construct(
private function __construct(
public string $currency,
#[CastToType('integer')]
public int $amount,
public string $remark,
public string $corresponsiveAccount,
public string $corresponsiveName,
#[CastToDateTimeImmutable('d-m-Y H:i:s')]
public \DateTimeImmutable $processDate,
) {
}

#[Constructor]
public static function create(
string $currency,
#[CastToType('integer')]
int $amount,
string $remark,
string $corresponsiveAccount,
string $corresponsiveName,
#[CastToDateTimeImmutable('d-m-Y H:i:s')]
\DateTimeImmutable $processDate,
): self {
return new self(
$currency,
$amount,
$remark,
$corresponsiveAccount,
$corresponsiveName,
$processDate,
);
}
}

0 comments on commit d9d3372

Please sign in to comment.