Skip to content

Commit

Permalink
Merge pull request #67 from cash-track/bugfix/relation-query-missing-id
Browse files Browse the repository at this point in the history
Bugfix / Relation Query Missing ID
  • Loading branch information
vokomarov authored Oct 19, 2021
2 parents 1d29062 + bc00525 commit 201469c
Show file tree
Hide file tree
Showing 18 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ jobs:
run: ./vendor/bin/phpcs -p -n --standard=PSR12 --colors --report=code ./app/src

- name: Run Psalm
run: ./vendor/bin/psalm --php-version=8.0 --show-info=true
run: ./vendor/bin/psalm --php-version=8.0 --show-info=true --no-cache
2 changes: 1 addition & 1 deletion app/src/Controller/Profile/ProfileStatisticsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function walletsLatest(
ChargeRepository $chargeRepository,
WalletsView $view
): ResponseInterface {
$wallets = $walletRepository->findByUserPKLatestWithLimit($this->user->id);
$wallets = $walletRepository->findByUserPKLatestWithLimit((int) $this->user->id);

foreach ($wallets as $wallet) {
$wallet->latestCharges = new ArrayCollection($chargeRepository->findByWalletIDLatest((int) $wallet->id));
Expand Down
4 changes: 2 additions & 2 deletions app/src/Controller/Wallets/ActiveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class ActiveController extends Controller
*/
public function activate(int $id): ResponseInterface
{
$wallet = $this->wallets->findByPKByUserPK($id, $this->user->id);
$wallet = $this->wallets->findByPKByUserPK($id, (int) $this->user->id);

if (! $wallet instanceof Wallet) {
return $this->response->create(404);
Expand Down Expand Up @@ -53,7 +53,7 @@ public function activate(int $id): ResponseInterface
*/
public function disable(int $id): ResponseInterface
{
$wallet = $this->wallets->findByPKByUserPK($id, $this->user->id);
$wallet = $this->wallets->findByPKByUserPK($id, (int) $this->user->id);

if (! $wallet instanceof Wallet) {
return $this->response->create(404);
Expand Down
4 changes: 2 additions & 2 deletions app/src/Controller/Wallets/ArchiveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class ArchiveController extends Controller
*/
public function archive(int $id): ResponseInterface
{
$wallet = $this->wallets->findByPKByUserPK($id, $this->user->id);
$wallet = $this->wallets->findByPKByUserPK($id, (int) $this->user->id);

if (! $wallet instanceof Wallet) {
return $this->response->create(404);
Expand Down Expand Up @@ -53,7 +53,7 @@ public function archive(int $id): ResponseInterface
*/
public function unArchive(int $id): ResponseInterface
{
$wallet = $this->wallets->findByPKByUserPK($id, $this->user->id);
$wallet = $this->wallets->findByPKByUserPK($id, (int) $this->user->id);

if (! $wallet instanceof Wallet) {
return $this->response->create(404);
Expand Down
10 changes: 5 additions & 5 deletions app/src/Controller/Wallets/Charges/ChargesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ChargesController extends Controller
*/
public function list(int $walletId): ResponseInterface
{
$wallet = $this->wallets->findByPKByUserPK($walletId, $this->user->id);
$wallet = $this->wallets->findByPKByUserPK($walletId, (int) $this->user->id);

if (! $wallet instanceof Wallet) {
return $this->response->create(404);
Expand All @@ -50,7 +50,7 @@ public function list(int $walletId): ResponseInterface
*/
public function create(int $walletId, CreateRequest $request): ResponseInterface
{
$wallet = $this->wallets->findByPKByUserPK($walletId, $this->user->id);
$wallet = $this->wallets->findByPKByUserPK($walletId, (int) $this->user->id);

if (! $wallet instanceof Wallet) {
return $this->response->create(404);
Expand All @@ -70,7 +70,7 @@ public function create(int $walletId, CreateRequest $request): ResponseInterface
$charge->wallet = $wallet;
$charge->walletId = (int) $wallet->id;
$charge->user = $this->user;
$charge->userId = $this->user->id;
$charge->userId = (int) $this->user->id;

// TODO. Implement currency conversion when charge currency is different that wallet.

Expand Down Expand Up @@ -103,7 +103,7 @@ public function create(int $walletId, CreateRequest $request): ResponseInterface
*/
public function update(int $walletId, string $chargeId, CreateRequest $request): ResponseInterface
{
$wallet = $this->wallets->findByPKByUserPK($walletId, $this->user->id);
$wallet = $this->wallets->findByPKByUserPK($walletId, (int) $this->user->id);

if (! $wallet instanceof Wallet) {
return $this->response->create(404);
Expand Down Expand Up @@ -158,7 +158,7 @@ public function update(int $walletId, string $chargeId, CreateRequest $request):
*/
public function delete(int $walletId, string $chargeId): ResponseInterface
{
$wallet = $this->wallets->findByPKByUserPK($walletId, $this->user->id);
$wallet = $this->wallets->findByPKByUserPK($walletId, (int) $this->user->id);

if (! $wallet instanceof Wallet) {
return $this->response->create(404);
Expand Down
6 changes: 3 additions & 3 deletions app/src/Controller/Wallets/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class UsersController extends Controller
*/
public function users(int $id): ResponseInterface
{
$wallet = $this->wallets->findByPKByUserPKWithUsers($id, $this->user->id);
$wallet = $this->wallets->findByPKByUserPKWithUsers($id, (int) $this->user->id);

if (! $wallet instanceof Wallet) {
return $this->response->create(404);
Expand All @@ -40,7 +40,7 @@ public function users(int $id): ResponseInterface
*/
public function patch(int $id, int $userId): ResponseInterface
{
$wallet = $this->wallets->findByPKByUserPKWithUsers($id, $this->user->id);
$wallet = $this->wallets->findByPKByUserPKWithUsers($id, (int) $this->user->id);

if (! $wallet instanceof Wallet) {
return $this->response->create(404);
Expand Down Expand Up @@ -81,7 +81,7 @@ public function patch(int $id, int $userId): ResponseInterface
*/
public function delete(int $id, int $userId): ResponseInterface
{
$wallet = $this->wallets->findByPKByUserPKWithUsers($id, $this->user->id);
$wallet = $this->wallets->findByPKByUserPKWithUsers($id, (int) $this->user->id);

if (! $wallet instanceof Wallet) {
return $this->response->create(404);
Expand Down
14 changes: 7 additions & 7 deletions app/src/Controller/Wallets/WalletsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class WalletsController extends Controller
*/
public function list(): ResponseInterface
{
return $this->walletsView->json($this->wallets->findAllByUserPK($this->user->id));
return $this->walletsView->json($this->wallets->findAllByUserPK((int) $this->user->id));
}

/**
Expand All @@ -34,7 +34,7 @@ public function list(): ResponseInterface
*/
public function listUnArchived(): ResponseInterface
{
return $this->walletsView->json($this->wallets->findAllByUserPKByArchived($this->user->id, false));
return $this->walletsView->json($this->wallets->findAllByUserPKByArchived((int) $this->user->id, false));
}

/**
Expand All @@ -44,7 +44,7 @@ public function listUnArchived(): ResponseInterface
*/
public function listArchived(): ResponseInterface
{
return $this->walletsView->json($this->wallets->findAllByUserPKByArchived($this->user->id, true));
return $this->walletsView->json($this->wallets->findAllByUserPKByArchived((int) $this->user->id, true));
}

/**
Expand All @@ -55,7 +55,7 @@ public function listArchived(): ResponseInterface
*/
public function index(int $id): ResponseInterface
{
$wallet = $this->wallets->findByPKByUserPK($id, $this->user->id);
$wallet = $this->wallets->findByPKByUserPK($id, (int) $this->user->id);

if (! $wallet instanceof Wallet) {
return $this->response->create(404);
Expand All @@ -72,7 +72,7 @@ public function index(int $id): ResponseInterface
*/
public function indexTotal(int $id): ResponseInterface
{
$wallet = $this->wallets->findByPKByUserPK($id, $this->user->id);
$wallet = $this->wallets->findByPKByUserPK($id, (int) $this->user->id);

if (! $wallet instanceof Wallet) {
return $this->response->create(404);
Expand Down Expand Up @@ -122,7 +122,7 @@ public function create(CreateRequest $request): ResponseInterface
*/
public function update(int $id, UpdateRequest $request): ResponseInterface
{
$wallet = $this->wallets->findByPKByUserPK($id, $this->user->id);
$wallet = $this->wallets->findByPKByUserPK($id, (int) $this->user->id);

if (! $wallet instanceof Wallet) {
return $this->response->create(404);
Expand Down Expand Up @@ -180,7 +180,7 @@ public function update(int $id, UpdateRequest $request): ResponseInterface
*/
public function delete(int $id): ResponseInterface
{
$wallet = $this->wallets->findByPKByUserPK($id, $this->user->id);
$wallet = $this->wallets->findByPKByUserPK($id, (int) $this->user->id);

if (! $wallet instanceof Wallet) {
return $this->response->create(404);
Expand Down
4 changes: 2 additions & 2 deletions app/src/Database/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class Currency

/**
* @Cycle\Column(type = "string(3)", primary = true)
* @var string
* @var string|null
*/
public $code = '';
public $code;

/**
* @Cycle\Column(type = "string")
Expand Down
4 changes: 2 additions & 2 deletions app/src/Database/CurrencyExchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class CurrencyExchange
{
/**
* @Cycle\Column(type = "primary")
* @var int
* @var int|null
*/
public $id = 0;
public $id;

/**
* @Cycle\Column(type = "string(3)", name = "src_currency_code")
Expand Down
4 changes: 2 additions & 2 deletions app/src/Database/EmailConfirmation.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class EmailConfirmation
{
/**
* @Cycle\Column(type = "string", primary = true)
* @var string
* @var string|null
*/
public $email = '';
public $email;

/**
* @Cycle\Column(type = "string")
Expand Down
4 changes: 2 additions & 2 deletions app/src/Database/ForgotPasswordRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class ForgotPasswordRequest
{
/**
* @Cycle\Column(type = "string", primary = true)
* @var string
* @var string|null
*/
public $email = '';
public $email;

/**
* @Cycle\Column(type = "string")
Expand Down
4 changes: 2 additions & 2 deletions app/src/Database/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class User implements PasswordContainerInterface
{
/**
* @Cycle\Column(type = "primary")
* @var int
* @var int|null
*/
public $id = 0;
public $id;

/**
* @Cycle\Column(type = "string")
Expand Down
4 changes: 2 additions & 2 deletions app/src/Database/UserWallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UserWallet
{
/**
* @Cycle\Column(type = "primary")
* @var int
* @var int|null
*/
public $id = 0;
public $id;
}
2 changes: 1 addition & 1 deletion app/src/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getActor(TokenInterface $token): ?object
* @param string $email
* @return object|null
*/
public function findByEmail($email)
public function findByEmail(string $email): object|null
{
return $this->findOne(['email' => $email]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/Service/Auth/EmailConfirmationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function confirm(string $token): void
throw new \RuntimeException('Confirmation link are expired');
}

$user = $this->userRepository->findByEmail($confirmation->email);
$user = $this->userRepository->findByEmail((string) $confirmation->email);

if (! $user instanceof User) {
throw new \RuntimeException('Unable to find user linked to confirmation link');
Expand Down
2 changes: 1 addition & 1 deletion app/src/Service/Auth/ForgotPasswordService.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function reset(string $code, string $password): void
throw new \RuntimeException('Password reset link are expired');
}

$user = $this->userRepository->findByEmail($request->email);
$user = $this->userRepository->findByEmail((string) $request->email);

if (! $user instanceof User) {
throw new \RuntimeException('Unable to find user linked to password reset link');
Expand Down
10 changes: 5 additions & 5 deletions app/src/Service/Statistics/ProfileStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getChargeFlow(User $user, Currency $currency): array
{
$walletIDs = array_map(function (Wallet $wallet) {
return (int) $wallet->id;
}, $this->walletRepository->findAllByUserPKByCurrencyCode($user->id, $currency->code));
}, $this->walletRepository->findAllByUserPKByCurrencyCode((int) $user->id, (string) $currency->code));

$data = [
Charge::TYPE_INCOME => [
Expand Down Expand Up @@ -84,10 +84,10 @@ public function getChargeFlow(User $user, Currency $currency): array
public function getCounters(User $user): array
{
return [
'wallets' => $this->walletRepository->countAllByUserPK($user->id),
'walletsArchived' => $this->walletRepository->countArchivedByUserPK($user->id),
'charges' => $this->chargeRepository->countAllByUserPKByType($user->id),
'chargesIncome' => $this->chargeRepository->countAllByUserPKByType($user->id, Charge::TYPE_INCOME),
'wallets' => $this->walletRepository->countAllByUserPK((int) $user->id),
'walletsArchived' => $this->walletRepository->countArchivedByUserPK((int) $user->id),
'charges' => $this->chargeRepository->countAllByUserPKByType((int) $user->id),
'chargesIncome' => $this->chargeRepository->countAllByUserPKByType((int) $user->id, Charge::TYPE_INCOME),
];
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"checks": [
"./vendor/bin/phpunit",
"./vendor/bin/phpcs -p -n --standard=PSR12 --colors --report=code ./app/src",
"./vendor/bin/psalm --php-version=8.0 --show-info=true"
"./vendor/bin/psalm --php-version=8.0 --show-info=true --no-cache"
],
"phpunit": [
"./vendor/bin/phpunit"
Expand Down

0 comments on commit 201469c

Please sign in to comment.