Code cleanup

This commit is contained in:
James Cole
2018-04-02 14:50:17 +02:00
parent 379b104778
commit fa7ab45a40
100 changed files with 440 additions and 517 deletions

View File

@@ -75,7 +75,7 @@ class TagRepository implements TagRepositoryInterface
* *
* @return bool * @return bool
* *
* @throws \Exception
*/ */
public function destroy(Tag $tag): bool public function destroy(Tag $tag): bool
{ {
@@ -98,9 +98,8 @@ class TagRepository implements TagRepositoryInterface
$collector->setUser($this->user); $collector->setUser($this->user);
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setAllAssetAccounts()->setTag($tag); $collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setAllAssetAccounts()->setTag($tag);
$set = $collector->getJournals(); $set = $collector->getJournals();
$sum = strval($set->sum('transaction_amount'));
return $sum; return strval($set->sum('transaction_amount'));
} }
/** /**
@@ -222,9 +221,8 @@ class TagRepository implements TagRepositoryInterface
$collector->setUser($this->user); $collector->setUser($this->user);
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setAllAssetAccounts()->setTag($tag); $collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setAllAssetAccounts()->setTag($tag);
$set = $collector->getJournals(); $set = $collector->getJournals();
$sum = strval($set->sum('transaction_amount'));
return $sum; return strval($set->sum('transaction_amount'));
} }
/** /**
@@ -268,10 +266,10 @@ class TagRepository implements TagRepositoryInterface
$journals = $collector->getJournals(); $journals = $collector->getJournals();
$sum = '0'; $sum = '0';
foreach ($journals as $journal) { foreach ($journals as $journal) {
$sum = bcadd($sum, app('steam')->positive(strval($journal->transaction_amount))); $sum = bcadd($sum, app('steam')->positive((string)$journal->transaction_amount));
} }
return strval($sum); return (string)$sum;
} }
/** /**
@@ -301,7 +299,7 @@ class TagRepository implements TagRepositoryInterface
]; ];
foreach ($journals as $journal) { foreach ($journals as $journal) {
$amount = app('steam')->positive(strval($journal->transaction_amount)); $amount = app('steam')->positive((string)$journal->transaction_amount);
$type = $journal->transaction_type_type; $type = $journal->transaction_type_type;
if (TransactionType::WITHDRAWAL === $type) { if (TransactionType::WITHDRAWAL === $type) {
$amount = bcmul($amount, '-1'); $amount = bcmul($amount, '-1');
@@ -350,7 +348,7 @@ class TagRepository implements TagRepositoryInterface
$tagsWithAmounts = []; $tagsWithAmounts = [];
/** @var Tag $tag */ /** @var Tag $tag */
foreach ($set as $tag) { foreach ($set as $tag) {
$tagsWithAmounts[$tag->id] = strval($tag->amount_sum); $tagsWithAmounts[$tag->id] = (string)$tag->amount_sum;
} }
$tags = $allTags->orderBy('tags.id', 'desc')->get(['tags.id', 'tags.tag']); $tags = $allTags->orderBy('tags.id', 'desc')->get(['tags.id', 'tags.tag']);
@@ -431,8 +429,8 @@ class TagRepository implements TagRepositoryInterface
$step = 1; $step = 1;
} }
$extra = $step / $amount; $extra = $step / $amount;
$result = (int)($range[0] + $extra);
return $result; return (int)($range[0] + $extra);
} }
} }

View File

@@ -77,8 +77,8 @@ class UserRepository implements UserRepositoryInterface
Preferences::setForUser($user, 'previous_email_' . date('Y-m-d-H-i-s'), $oldEmail); Preferences::setForUser($user, 'previous_email_' . date('Y-m-d-H-i-s'), $oldEmail);
// set undo and confirm token: // set undo and confirm token:
Preferences::setForUser($user, 'email_change_undo_token', strval(bin2hex(random_bytes(16)))); Preferences::setForUser($user, 'email_change_undo_token', (string)bin2hex(random_bytes(16)));
Preferences::setForUser($user, 'email_change_confirm_token', strval(bin2hex(random_bytes(16)))); Preferences::setForUser($user, 'email_change_confirm_token', (string)bin2hex(random_bytes(16)));
// update user // update user
$user->email = $newEmail; $user->email = $newEmail;
@@ -145,7 +145,7 @@ class UserRepository implements UserRepositoryInterface
* *
* @return bool * @return bool
* *
* @throws \Exception
*/ */
public function destroy(User $user): bool public function destroy(User $user): bool
{ {
@@ -231,7 +231,7 @@ class UserRepository implements UserRepositoryInterface
} }
$return['is_admin'] = $user->hasRole('owner'); $return['is_admin'] = $user->hasRole('owner');
$return['blocked'] = 1 === intval($user->blocked); $return['blocked'] = 1 === (int)$user->blocked;
$return['blocked_code'] = $user->blocked_code; $return['blocked_code'] = $user->blocked_code;
$return['accounts'] = $user->accounts()->count(); $return['accounts'] = $user->accounts()->count();
$return['journals'] = $user->transactionJournals()->count(); $return['journals'] = $user->transactionJournals()->count();

View File

@@ -103,17 +103,12 @@ interface UserRepositoryInterface
/** /**
* @param int $userId * @param int $userId
*
* @deprecated * @deprecated
* @return User * @return User
*/ */
public function find(int $userId): User; public function find(int $userId): User;
/**
* @param int $userId
* @return User|null
*/
public function findNull(int $userId): ?User;
/** /**
* @param string $email * @param string $email
* *
@@ -121,6 +116,13 @@ interface UserRepositoryInterface
*/ */
public function findByEmail(string $email): ?User; public function findByEmail(string $email): ?User;
/**
* @param int $userId
*
* @return User|null
*/
public function findNull(int $userId): ?User;
/** /**
* Returns the first user in the DB. Generally only works when there is just one. * Returns the first user in the DB. Generally only works when there is just one.
* *

View File

@@ -72,11 +72,11 @@ class BelongsUser implements Rule
if (!auth()->check()) { if (!auth()->check()) {
return true; // @codeCoverageIgnore return true; // @codeCoverageIgnore
} }
$attribute = strval($attribute); $attribute = (string)$attribute;
switch ($attribute) { switch ($attribute) {
case 'piggy_bank_id': case 'piggy_bank_id':
$count = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id') $count = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')
->where('piggy_banks.id', '=', intval($value)) ->where('piggy_banks.id', '=', (int)$value)
->where('accounts.user_id', '=', auth()->user()->id)->count(); ->where('accounts.user_id', '=', auth()->user()->id)->count();
return $count === 1; return $count === 1;
@@ -87,7 +87,7 @@ class BelongsUser implements Rule
return $count === 1; return $count === 1;
break; break;
case 'bill_id': case 'bill_id':
$count = Bill::where('id', '=', intval($value))->where('user_id', '=', auth()->user()->id)->count(); $count = Bill::where('id', '=', (int)$value)->where('user_id', '=', auth()->user()->id)->count();
return $count === 1; return $count === 1;
case 'bill_name': case 'bill_name':
@@ -96,12 +96,12 @@ class BelongsUser implements Rule
return $count === 1; return $count === 1;
break; break;
case 'budget_id': case 'budget_id':
$count = Budget::where('id', '=', intval($value))->where('user_id', '=', auth()->user()->id)->count(); $count = Budget::where('id', '=', (int)$value)->where('user_id', '=', auth()->user()->id)->count();
return $count === 1; return $count === 1;
break; break;
case 'category_id': case 'category_id':
$count = Category::where('id', '=', intval($value))->where('user_id', '=', auth()->user()->id)->count(); $count = Category::where('id', '=', (int)$value)->where('user_id', '=', auth()->user()->id)->count();
return $count === 1; return $count === 1;
break; break;
@@ -112,7 +112,7 @@ class BelongsUser implements Rule
break; break;
case 'source_id': case 'source_id':
case 'destination_id': case 'destination_id':
$count = Account::where('id', '=', intval($value))->where('user_id', '=', auth()->user()->id)->count(); $count = Account::where('id', '=', (int)$value)->where('user_id', '=', auth()->user()->id)->count();
return $count === 1; return $count === 1;
break; break;
@@ -143,7 +143,7 @@ class BelongsUser implements Rule
} }
$count = 0; $count = 0;
foreach ($objects as $object) { foreach ($objects as $object) {
if (trim(strval($object->$field)) === trim($value)) { if (trim((string)$object->$field) === trim($value)) {
$count++; $count++;
} }
} }

View File

@@ -76,7 +76,7 @@ class UniqueIban implements Rule
if (!auth()->check()) { if (!auth()->check()) {
return true; // @codeCoverageIgnore return true; // @codeCoverageIgnore
} }
if (is_null($this->expectedType)) { if (null === $this->expectedType) {
return true; return true;
} }
$maxCounts = [ $maxCounts = [
@@ -114,7 +114,7 @@ class UniqueIban implements Rule
->accounts() ->accounts()
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->where('account_types.type', $type); ->where('account_types.type', $type);
if (!is_null($this->account)) { if (null !== $this->account) {
$query->where('accounts.id', '!=', $this->account->id); $query->where('accounts.id', '!=', $this->account->id);
} }
$result = $query->get(['accounts.*']); $result = $query->get(['accounts.*']);

View File

@@ -38,7 +38,7 @@ class BunqId
*/ */
public function __construct($data = null) public function __construct($data = null)
{ {
if (!is_null($data)) { if (null !== $data) {
$this->id = $data['id']; $this->id = $data['id'];
} }
} }

View File

@@ -27,13 +27,4 @@ namespace FireflyIII\Services\Bunq\Id;
*/ */
class DeviceSessionId extends BunqId class DeviceSessionId extends BunqId
{ {
/**
* DeviceSessionId constructor.
*
* @param null $data
*/
public function __construct($data = null)
{
parent::__construct($data);
}
} }

View File

@@ -28,11 +28,11 @@ namespace FireflyIII\Services\Bunq\Object;
class Alias extends BunqObject class Alias extends BunqObject
{ {
/** @var string */ /** @var string */
private $name = ''; private $name;
/** @var string */ /** @var string */
private $type = ''; private $type;
/** @var string */ /** @var string */
private $value = ''; private $value;
/** /**
* Alias constructor. * Alias constructor.

View File

@@ -28,9 +28,9 @@ namespace FireflyIII\Services\Bunq\Object;
class Amount extends BunqObject class Amount extends BunqObject
{ {
/** @var string */ /** @var string */
private $currency = ''; private $currency;
/** @var string */ /** @var string */
private $value = ''; private $value;
/** /**
* Amount constructor. * Amount constructor.

View File

@@ -48,7 +48,6 @@ class DeviceServer extends BunqObject
* *
* @param array $data * @param array $data
* *
* @throws \InvalidArgumentException
*/ */
public function __construct(array $data) public function __construct(array $data)
{ {

View File

@@ -40,15 +40,6 @@ class LabelMonetaryAccount extends BunqObject
/** @var LabelUser */ /** @var LabelUser */
private $labelUser; private $labelUser;
/**
* @return LabelUser
*/
public function getLabelUser(): LabelUser
{
return $this->labelUser;
}
/** /**
* LabelMonetaryAccount constructor. * LabelMonetaryAccount constructor.
* *
@@ -71,6 +62,14 @@ class LabelMonetaryAccount extends BunqObject
return $this->iban; return $this->iban;
} }
/**
* @return LabelUser
*/
public function getLabelUser(): LabelUser
{
return $this->labelUser;
}
/** /**
* @return array * @return array
*/ */

View File

@@ -40,6 +40,20 @@ class LabelUser extends BunqObject
/** @var string */ /** @var string */
private $uuid; private $uuid;
/**
* LabelUser constructor.
*
* @param array $data
*/
public function __construct(array $data)
{
$this->uuid = $data['uuid'];
$this->displayName = $data['display_name'];
$this->country = $data['country'];
$this->publicNickName = $data['public_nick_name'];
$this->avatar = new Avatar($data['avatar']);
}
/** /**
* @return Avatar * @return Avatar
*/ */
@@ -64,22 +78,6 @@ class LabelUser extends BunqObject
return $this->publicNickName; return $this->publicNickName;
} }
/**
* LabelUser constructor.
*
* @param array $data
*/
public function __construct(array $data)
{
$this->uuid = $data['uuid'];
$this->displayName = $data['display_name'];
$this->country = $data['country'];
$this->publicNickName = $data['public_nick_name'];
$this->avatar = new Avatar($data['avatar']);
}
/** /**
* @return array * @return array
*/ */

View File

@@ -38,15 +38,15 @@ class MonetaryAccountBank extends BunqObject
/** @var Carbon */ /** @var Carbon */
private $created; private $created;
/** @var string */ /** @var string */
private $currency = ''; private $currency;
/** @var Amount */ /** @var Amount */
private $dailyLimit; private $dailyLimit;
/** @var Amount */ /** @var Amount */
private $dailySpent; private $dailySpent;
/** @var string */ /** @var string */
private $description = ''; private $description;
/** @var int */ /** @var int */
private $id = 0; private $id;
/** @var MonetaryAccountProfile */ /** @var MonetaryAccountProfile */
private $monetaryAccountProfile; private $monetaryAccountProfile;
/** @var array */ /** @var array */
@@ -54,28 +54,27 @@ class MonetaryAccountBank extends BunqObject
/** @var Amount */ /** @var Amount */
private $overdraftLimit; private $overdraftLimit;
/** @var string */ /** @var string */
private $publicUuid = ''; private $publicUuid;
/** @var string */ /** @var string */
private $reason = ''; private $reason;
/** @var string */ /** @var string */
private $reasonDescription = ''; private $reasonDescription;
/** @var MonetaryAccountSetting */ /** @var MonetaryAccountSetting */
private $setting; private $setting;
/** @var string */ /** @var string */
private $status = ''; private $status;
/** @var string */ /** @var string */
private $subStatus = ''; private $subStatus;
/** @var Carbon */ /** @var Carbon */
private $updated; private $updated;
/** @var int */ /** @var int */
private $userId = 0; private $userId;
/** /**
* MonetaryAccountBank constructor. * MonetaryAccountBank constructor.
* *
* @param array $data * @param array $data
* *
* @throws \InvalidArgumentException
*/ */
public function __construct(array $data) public function __construct(array $data)
{ {
@@ -106,8 +105,6 @@ class MonetaryAccountBank extends BunqObject
foreach ($data['notification_filters'] as $filter) { foreach ($data['notification_filters'] as $filter) {
$this->notificationFilters[] = new NotificationFilter($filter); $this->notificationFilters[] = new NotificationFilter($filter);
} }
return;
} }
/** /**

View File

@@ -28,7 +28,7 @@ namespace FireflyIII\Services\Bunq\Object;
class MonetaryAccountProfile extends BunqObject class MonetaryAccountProfile extends BunqObject
{ {
/** @var string */ /** @var string */
private $profileActionRequired = ''; private $profileActionRequired;
/** @var Amount */ /** @var Amount */
private $profileAmountRequired; private $profileAmountRequired;
/** /**

View File

@@ -28,11 +28,11 @@ namespace FireflyIII\Services\Bunq\Object;
class MonetaryAccountSetting extends BunqObject class MonetaryAccountSetting extends BunqObject
{ {
/** @var string */ /** @var string */
private $color = ''; private $color;
/** @var string */ /** @var string */
private $defaultAvatarStatus = ''; private $defaultAvatarStatus;
/** @var string */ /** @var string */
private $restrictionChat = ''; private $restrictionChat;
/** /**
* MonetaryAccountSetting constructor. * MonetaryAccountSetting constructor.

View File

@@ -34,7 +34,7 @@ class NotificationFilter extends BunqObject
*/ */
public function __construct(array $data) public function __construct(array $data)
{ {
unset($data);
} }
/** /**

View File

@@ -61,7 +61,6 @@ class Payment extends BunqObject
* *
* @param array $data * @param array $data
* *
* @throws \InvalidArgumentException
*/ */
public function __construct(array $data) public function __construct(array $data)
{ {

View File

@@ -28,7 +28,7 @@ namespace FireflyIII\Services\Bunq\Object;
class ServerPublicKey extends BunqObject class ServerPublicKey extends BunqObject
{ {
/** @var string */ /** @var string */
private $publicKey = ''; private $publicKey;
/** /**
* ServerPublicKey constructor. * ServerPublicKey constructor.

View File

@@ -44,9 +44,9 @@ class UserCompany extends BunqObject
*/ */
private $avatar; private $avatar;
/** @var string */ /** @var string */
private $cocNumber = ''; private $cocNumber;
/** @var string */ /** @var string */
private $counterBankIban = ''; private $counterBankIban;
/** @var Carbon */ /** @var Carbon */
private $created; private $created;
/** /**
@@ -58,48 +58,47 @@ class UserCompany extends BunqObject
*/ */
private $directorAlias; private $directorAlias;
/** @var string */ /** @var string */
private $displayName = ''; private $displayName;
/** @var int */ /** @var int */
private $id = 0; private $id;
/** @var string */ /** @var string */
private $language = ''; private $language;
/** @var string */ /** @var string */
private $name = ''; private $name;
/** @var array */ /** @var array */
private $notificationFilters = []; private $notificationFilters = [];
/** @var string */ /** @var string */
private $publicNickName = ''; private $publicNickName;
/** @var string */ /** @var string */
private $publicUuid = ''; private $publicUuid;
/** @var string */ /** @var string */
private $region = ''; private $region;
/** @var string */ /** @var string */
private $sectorOfIndustry = ''; private $sectorOfIndustry;
/** @var int */ /** @var int */
private $sessionTimeout = 0; private $sessionTimeout;
/** @var string */ /** @var string */
private $status = ''; private $status;
/** @var string */ /** @var string */
private $subStatus = ''; private $subStatus;
/** @var string */ /** @var string */
private $typeOfBusinessEntity = ''; private $typeOfBusinessEntity;
/** @var array */ /** @var array */
private $ubos = []; private $ubos = [];
/** @var Carbon */ /** @var Carbon */
private $updated; private $updated;
/** @var int */ /** @var int */
private $versionTos = 0; private $versionTos;
/** /**
* UserCompany constructor. * UserCompany constructor.
* *
* @param array $data * @param array $data
* *
* @throws \InvalidArgumentException
*/ */
public function __construct(array $data) public function __construct(array $data)
{ {
$this->id = intval($data['id']); $this->id = (int)$data['id'];
$this->created = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['created']); $this->created = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['created']);
$this->updated = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['updated']); $this->updated = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['updated']);
$this->status = $data['status']; $this->status = $data['status'];
@@ -109,8 +108,8 @@ class UserCompany extends BunqObject
$this->publicNickName = $data['public_nick_name']; $this->publicNickName = $data['public_nick_name'];
$this->language = $data['language']; $this->language = $data['language'];
$this->region = $data['region']; $this->region = $data['region'];
$this->sessionTimeout = intval($data['session_timeout']); $this->sessionTimeout = (int)$data['session_timeout'];
$this->versionTos = intval($data['version_terms_of_service']); $this->versionTos = (int)$data['version_terms_of_service'];
$this->cocNumber = $data['chamber_of_commerce_number']; $this->cocNumber = $data['chamber_of_commerce_number'];
$this->typeOfBusinessEntity = $data['type_of_business_entity'] ?? ''; $this->typeOfBusinessEntity = $data['type_of_business_entity'] ?? '';
$this->sectorOfIndustry = $data['sector_of_industry'] ?? ''; $this->sectorOfIndustry = $data['sector_of_industry'] ?? '';

View File

@@ -34,21 +34,21 @@ class UserLight extends BunqObject
/** @var Carbon */ /** @var Carbon */
private $created; private $created;
/** @var string */ /** @var string */
private $displayName = ''; private $displayName;
/** @var string */ /** @var string */
private $firstName = ''; private $firstName;
/** @var int */ /** @var int */
private $id = 0; private $id;
/** @var string */ /** @var string */
private $lastName = ''; private $lastName;
/** @var string */ /** @var string */
private $legalName = ''; private $legalName;
/** @var string */ /** @var string */
private $middleName = ''; private $middleName;
/** @var string */ /** @var string */
private $publicNickName = ''; private $publicNickName;
/** @var string */ /** @var string */
private $publicUuid = ''; private $publicUuid;
/** @var Carbon */ /** @var Carbon */
private $updated; private $updated;
@@ -57,14 +57,13 @@ class UserLight extends BunqObject
* *
* @param array $data * @param array $data
* *
* @throws \InvalidArgumentException
*/ */
public function __construct(array $data) public function __construct(array $data)
{ {
if (0 === count($data)) { if (0 === count($data)) {
return; return;
} }
$this->id = intval($data['id']); $this->id = (int)$data['id'];
$this->created = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['created']); $this->created = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['created']);
$this->updated = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['updated']); $this->updated = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['updated']);
$this->publicUuid = $data['public_uuid']; $this->publicUuid = $data['public_uuid'];

View File

@@ -46,7 +46,7 @@ class UserPerson extends BunqObject
/** @var array */ /** @var array */
private $billingContracts = []; private $billingContracts = [];
/** @var string */ /** @var string */
private $countryOfBirth = ''; private $countryOfBirth;
/** @var Carbon */ /** @var Carbon */
private $created; private $created;
/** /**
@@ -64,60 +64,59 @@ class UserPerson extends BunqObject
/** @var Carbon */ /** @var Carbon */
private $dateOfBirth; private $dateOfBirth;
/** @var string */ /** @var string */
private $displayName = ''; private $displayName;
/** @var string */ /** @var string */
private $documentCountry = ''; private $documentCountry;
/** @var string */ /** @var string */
private $documentNumber = ''; private $documentNumber;
/** @var string */ /** @var string */
private $documentType = ''; private $documentType;
/** @var string */ /** @var string */
private $firstName = ''; private $firstName;
/** @var string */ /** @var string */
private $gender = ''; private $gender;
/** @var int */ /** @var int */
private $id = 0; private $id;
/** @var string */ /** @var string */
private $language = ''; private $language;
/** @var string */ /** @var string */
private $lastName = ''; private $lastName;
/** @var string */ /** @var string */
private $legalName = ''; private $legalName;
/** @var string */ /** @var string */
private $middleName = ''; private $middleName;
/** @var string */ /** @var string */
private $nationality = ''; private $nationality;
/** @var array */ /** @var array */
private $notificationFilters = []; private $notificationFilters = [];
/** @var string */ /** @var string */
private $placeOfBirth = ''; private $placeOfBirth;
/** @var string */ /** @var string */
private $publicNickName = ''; private $publicNickName;
/** @var string */ /** @var string */
private $publicUuid = ''; private $publicUuid;
/** /**
* @var mixed * @var mixed
*/ */
private $region; private $region;
/** @var int */ /** @var int */
private $sessionTimeout = 0; private $sessionTimeout;
/** @var string */ /** @var string */
private $status = ''; private $status;
/** @var string */ /** @var string */
private $subStatus = ''; private $subStatus;
/** @var string */ /** @var string */
private $taxResident = ''; private $taxResident;
/** @var Carbon */ /** @var Carbon */
private $updated; private $updated;
/** @var int */ /** @var int */
private $versionTos = 0; private $versionTos;
/** /**
* UserPerson constructor. * UserPerson constructor.
* *
* @param array $data * @param array $data
* *
* @throws \InvalidArgumentException
*/ */
public function __construct(array $data) public function __construct(array $data)
{ {
@@ -129,7 +128,7 @@ class UserPerson extends BunqObject
return; return;
} }
$this->id = intval($data['id']); $this->id = (int)$data['id'];
$this->created = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['created']); $this->created = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['created']);
$this->updated = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['updated']); $this->updated = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['updated']);
$this->status = $data['status']; $this->status = $data['status'];
@@ -139,7 +138,7 @@ class UserPerson extends BunqObject
$this->publicNickName = $data['public_nick_name']; $this->publicNickName = $data['public_nick_name'];
$this->language = $data['language']; $this->language = $data['language'];
$this->region = $data['region']; $this->region = $data['region'];
$this->sessionTimeout = intval($data['session_timeout']); $this->sessionTimeout = (int)$data['session_timeout'];
$this->firstName = $data['first_name']; $this->firstName = $data['first_name'];
$this->middleName = $data['middle_name']; $this->middleName = $data['middle_name'];
$this->lastName = $data['last_name']; $this->lastName = $data['last_name'];
@@ -150,7 +149,7 @@ class UserPerson extends BunqObject
$this->countryOfBirth = $data['country_of_birth']; $this->countryOfBirth = $data['country_of_birth'];
$this->nationality = $data['nationality']; $this->nationality = $data['nationality'];
$this->gender = $data['gender']; $this->gender = $data['gender'];
$this->versionTos = intval($data['version_terms_of_service']); $this->versionTos = (int)$data['version_terms_of_service'];
$this->documentNumber = $data['document_number']; $this->documentNumber = $data['document_number'];
$this->documentType = $data['document_type']; $this->documentType = $data['document_type'];
$this->documentCountry = $data['document_country_of_issuance']; $this->documentCountry = $data['document_country_of_issuance'];

View File

@@ -27,7 +27,6 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Services\Bunq\Object\ServerPublicKey; use FireflyIII\Services\Bunq\Object\ServerPublicKey;
use Log; use Log;
use Requests; use Requests;
use Requests_Exception;
/** /**
* Class BunqRequest. * Class BunqRequest.
@@ -41,7 +40,7 @@ abstract class BunqRequest
/** @var string */ /** @var string */
private $privateKey = ''; private $privateKey = '';
/** @var string */ /** @var string */
private $server = ''; private $server;
/** /**
* @var array * @var array
*/ */
@@ -58,8 +57,8 @@ abstract class BunqRequest
*/ */
public function __construct() public function __construct()
{ {
$this->server = strval(config('import.options.bunq.server')); $this->server = (string)config('import.options.bunq.server');
$this->version = strval(config('import.options.bunq.version')); $this->version = (string)config('import.options.bunq.version');
Log::debug(sprintf('Created new BunqRequest with server "%s" and version "%s"', $this->server, $this->version)); Log::debug(sprintf('Created new BunqRequest with server "%s" and version "%s"', $this->server, $this->version));
} }
@@ -230,14 +229,14 @@ abstract class BunqRequest
try { try {
$response = Requests::delete($fullUri, $headers); $response = Requests::delete($fullUri, $headers);
} catch (Requests_Exception $e) { } catch (Exception $e) {
return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()]]]; return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()]]];
} }
$body = $response->body; $body = $response->body;
$array = json_decode($body, true); $array = json_decode($body, true);
$responseHeaders = $response->headers->getAll(); $responseHeaders = $response->headers->getAll();
$statusCode = intval($response->status_code); $statusCode = (int)$response->status_code;
$array['ResponseHeaders'] = $responseHeaders; $array['ResponseHeaders'] = $responseHeaders;
$array['ResponseStatusCode'] = $statusCode; $array['ResponseStatusCode'] = $statusCode;
@@ -277,14 +276,14 @@ abstract class BunqRequest
try { try {
$response = Requests::get($fullUri, $headers); $response = Requests::get($fullUri, $headers);
} catch (Requests_Exception $e) { } catch (Exception $e) {
return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()]]]; return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()]]];
} }
$body = $response->body; $body = $response->body;
$array = json_decode($body, true); $array = json_decode($body, true);
$responseHeaders = $response->headers->getAll(); $responseHeaders = $response->headers->getAll();
$statusCode = intval($response->status_code); $statusCode = (int)$response->status_code;
$array['ResponseHeaders'] = $responseHeaders; $array['ResponseHeaders'] = $responseHeaders;
$array['ResponseStatusCode'] = $statusCode; $array['ResponseStatusCode'] = $statusCode;
@@ -318,14 +317,14 @@ abstract class BunqRequest
try { try {
$response = Requests::post($fullUri, $headers, $body); $response = Requests::post($fullUri, $headers, $body);
} catch (Requests_Exception|Exception $e) { } catch (Exception $e) {
return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()]]]; return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()]]];
} }
Log::debug('Seems to have NO exceptions in Response'); Log::debug('Seems to have NO exceptions in Response');
$body = $response->body; $body = $response->body;
$array = json_decode($body, true); $array = json_decode($body, true);
$responseHeaders = $response->headers->getAll(); $responseHeaders = $response->headers->getAll();
$statusCode = intval($response->status_code); $statusCode = (int)$response->status_code;
$array['ResponseHeaders'] = $responseHeaders; $array['ResponseHeaders'] = $responseHeaders;
$array['ResponseStatusCode'] = $statusCode; $array['ResponseStatusCode'] = $statusCode;
@@ -355,7 +354,7 @@ abstract class BunqRequest
try { try {
$response = Requests::delete($fullUri, $headers); $response = Requests::delete($fullUri, $headers);
} catch (Requests_Exception|Exception $e) { } catch (Exception $e) {
return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()]]]; return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()]]];
} }
$body = $response->body; $body = $response->body;
@@ -389,7 +388,7 @@ abstract class BunqRequest
try { try {
$response = Requests::post($fullUri, $headers, $body); $response = Requests::post($fullUri, $headers, $body);
} catch (Requests_Exception|Exception $e) { } catch (Exception $e) {
return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()]]]; return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()]]];
} }
$body = $response->body; $body = $response->body;
@@ -465,7 +464,7 @@ abstract class BunqRequest
$message[] = $error['error_description']; $message[] = $error['error_description'];
} }
} }
throw new FireflyException('Bunq ERROR ' . $response['ResponseStatusCode'] . ': ' . join(', ', $message)); throw new FireflyException('Bunq ERROR ' . $response['ResponseStatusCode'] . ': ' . implode(', ', $message));
} }
/** /**

View File

@@ -34,7 +34,6 @@ class DeleteDeviceSessionRequest extends BunqRequest
private $sessionToken; private $sessionToken;
/** /**
* @throws \Exception
*/ */
public function call(): void public function call(): void
{ {

View File

@@ -46,14 +46,14 @@ class DeviceServerRequest extends BunqRequest
public function call(): void public function call(): void
{ {
Log::debug('Now in DeviceServerRequest::call()'); Log::debug('Now in DeviceServerRequest::call()');
$uri = 'device-server'; $uri = 'device-server';
$data = ['description' => $this->description, 'secret' => $this->secret, 'permitted_ips' => $this->permittedIps]; $data = ['description' => $this->description, 'secret' => $this->secret, 'permitted_ips' => $this->permittedIps];
$headers = $this->getDefaultHeaders(); $headers = $this->getDefaultHeaders();
$headers['X-Bunq-Client-Authentication'] = $this->installationToken->getToken(); $headers['X-Bunq-Client-Authentication'] = $this->installationToken->getToken();
$response = $this->sendSignedBunqPost($uri, $data, $headers); $response = $this->sendSignedBunqPost($uri, $data, $headers);
$deviceServerId = new DeviceServerId; $deviceServerId = new DeviceServerId;
$deviceServerId->setId(intval($response['Response'][0]['Id']['id'])); $deviceServerId->setId((int)$response['Response'][0]['Id']['id']);
$this->deviceServerId = $deviceServerId; $this->deviceServerId = $deviceServerId;
return; return;

View File

@@ -113,7 +113,7 @@ class DeviceSessionRequest extends BunqRequest
{ {
$data = $this->getKeyFromResponse('Id', $response); $data = $this->getKeyFromResponse('Id', $response);
$deviceSessionId = new DeviceSessionId; $deviceSessionId = new DeviceSessionId;
$deviceSessionId->setId(intval($data['id'])); $deviceSessionId->setId((int)$data['id']);
return $deviceSessionId; return $deviceSessionId;
} }
@@ -125,10 +125,9 @@ class DeviceSessionRequest extends BunqRequest
*/ */
private function extractSessionToken(array $response): SessionToken private function extractSessionToken(array $response): SessionToken
{ {
$data = $this->getKeyFromResponse('Token', $response); $data = $this->getKeyFromResponse('Token', $response);
$sessionToken = new SessionToken($data);
return $sessionToken; return new SessionToken($data);
} }
/** /**
@@ -138,10 +137,9 @@ class DeviceSessionRequest extends BunqRequest
*/ */
private function extractUserCompany($response): UserCompany private function extractUserCompany($response): UserCompany
{ {
$data = $this->getKeyFromResponse('UserCompany', $response); $data = $this->getKeyFromResponse('UserCompany', $response);
$userCompany = new UserCompany($data);
return $userCompany; return new UserCompany($data);
} }
/** /**
@@ -151,9 +149,8 @@ class DeviceSessionRequest extends BunqRequest
*/ */
private function extractUserPerson($response): UserPerson private function extractUserPerson($response): UserPerson
{ {
$data = $this->getKeyFromResponse('UserPerson', $response); $data = $this->getKeyFromResponse('UserPerson', $response);
$userPerson = new UserPerson($data);
return $userPerson; return new UserPerson($data);
} }
} }

View File

@@ -103,7 +103,7 @@ class InstallationTokenRequest extends BunqRequest
{ {
$installationId = new InstallationId; $installationId = new InstallationId;
$data = $this->getKeyFromResponse('Id', $response); $data = $this->getKeyFromResponse('Id', $response);
$installationId->setId(intval($data['id'])); $installationId->setId((int)$data['id']);
return $installationId; return $installationId;
} }
@@ -115,10 +115,9 @@ class InstallationTokenRequest extends BunqRequest
*/ */
private function extractInstallationToken(array $response): InstallationToken private function extractInstallationToken(array $response): InstallationToken
{ {
$data = $this->getKeyFromResponse('Token', $response); $data = $this->getKeyFromResponse('Token', $response);
$installationToken = new InstallationToken($data);
return $installationToken; return new InstallationToken($data);
} }
/** /**
@@ -128,9 +127,8 @@ class InstallationTokenRequest extends BunqRequest
*/ */
private function extractServerPublicKey(array $response): ServerPublicKey private function extractServerPublicKey(array $response): ServerPublicKey
{ {
$data = $this->getKeyFromResponse('ServerPublicKey', $response); $data = $this->getKeyFromResponse('ServerPublicKey', $response);
$serverPublicKey = new ServerPublicKey($data);
return $serverPublicKey; return new ServerPublicKey($data);
} }
} }

View File

@@ -42,7 +42,6 @@ class ListUserRequest extends BunqRequest
private $userPerson; private $userPerson;
/** /**
* @throws \Exception
*/ */
public function call(): void public function call(): void
{ {

View File

@@ -96,7 +96,6 @@ class BunqToken
/** /**
* @param array $response * @param array $response
* *
* @throws \InvalidArgumentException
*/ */
protected function makeTokenFromResponse(array $response): void protected function makeTokenFromResponse(array $response): void
{ {

View File

@@ -23,12 +23,12 @@ declare(strict_types=1);
namespace FireflyIII\Services\Currency; namespace FireflyIII\Services\Currency;
use Carbon\Carbon; use Carbon\Carbon;
use Exception;
use FireflyIII\Models\CurrencyExchangeRate; use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\User; use FireflyIII\User;
use Log; use Log;
use Requests; use Requests;
use Requests_Exception;
/** /**
* Class FixerIO. * Class FixerIO.
@@ -53,7 +53,7 @@ class FixerIO implements ExchangeRateInterface
$result = Requests::get($uri); $result = Requests::get($uri);
$statusCode = $result->status_code; $statusCode = $result->status_code;
$body = $result->body; $body = $result->body;
} catch (Requests_Exception $e) { } catch (Exception $e) {
// don't care about error // don't care about error
$body = sprintf('Requests_Exception: %s', $e->getMessage()); $body = sprintf('Requests_Exception: %s', $e->getMessage());
} }
@@ -69,7 +69,7 @@ class FixerIO implements ExchangeRateInterface
} }
if (null !== $content) { if (null !== $content) {
$code = $toCurrency->code; $code = $toCurrency->code;
$rate = isset($content['rates'][$code]) ? $content['rates'][$code] : '1'; $rate = $content['rates'][$code] ?? '1';
} }
// create new currency exchange rate object: // create new currency exchange rate object:

View File

@@ -23,12 +23,12 @@ declare(strict_types=1);
namespace FireflyIII\Services\Currency; namespace FireflyIII\Services\Currency;
use Carbon\Carbon; use Carbon\Carbon;
use Exception;
use FireflyIII\Models\CurrencyExchangeRate; use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\User; use FireflyIII\User;
use Log; use Log;
use Requests; use Requests;
use Requests_Exception;
/** /**
* Class FixerIOv2. * Class FixerIOv2.
@@ -76,7 +76,7 @@ class FixerIOv2 implements ExchangeRateInterface
$statusCode = $result->status_code; $statusCode = $result->status_code;
$body = $result->body; $body = $result->body;
Log::debug(sprintf('Result status code is %d', $statusCode)); Log::debug(sprintf('Result status code is %d', $statusCode));
} catch (Requests_Exception $e) { } catch (Exception $e) {
// don't care about error // don't care about error
$body = sprintf('Requests_Exception: %s', $e->getMessage()); $body = sprintf('Requests_Exception: %s', $e->getMessage());
} }
@@ -92,11 +92,11 @@ class FixerIOv2 implements ExchangeRateInterface
} }
if (null !== $content) { if (null !== $content) {
$code = $toCurrency->code; $code = $toCurrency->code;
$rate = $content['rates'][$code] ?? 0; $rate = (float)($content['rates'][$code] ?? 0);
} }
Log::debug('Got the following rates from Fixer: ', $content['rates'] ?? []); Log::debug('Got the following rates from Fixer: ', $content['rates'] ?? []);
$exchangeRate->rate = $rate; $exchangeRate->rate = $rate;
if ($rate !== 0) { if ($rate !== 0.0) {
$exchangeRate->save(); $exchangeRate->save();
} }

View File

@@ -60,10 +60,10 @@ class UpdateRequest implements GithubRequest
if (isset($releaseXml->entry)) { if (isset($releaseXml->entry)) {
foreach ($releaseXml->entry as $entry) { foreach ($releaseXml->entry as $entry) {
$array = [ $array = [
'id' => strval($entry->id), 'id' => (string)$entry->id,
'updated' => strval($entry->updated), 'updated' => (string)$entry->updated,
'title' => strval($entry->title), 'title' => (string)$entry->title,
'content' => strval($entry->content), 'content' => (string)$entry->content,
]; ];
$this->releases[] = new Release($array); $this->releases[] = new Release($array);
} }

View File

@@ -127,11 +127,10 @@ trait AccountServiceTrait
* @param array $data * @param array $data
* *
* @return TransactionJournal|null * @return TransactionJournal|null
* @throws \FireflyIII\Exceptions\FireflyException
*/ */
public function storeIBJournal(Account $account, array $data): ?TransactionJournal public function storeIBJournal(Account $account, array $data): ?TransactionJournal
{ {
$amount = strval($data['openingBalance']); $amount = (string)$data['openingBalance'];
Log::debug(sprintf('Submitted amount is %s', $amount)); Log::debug(sprintf('Submitted amount is %s', $amount));
if (0 === bccomp($amount, '0')) { if (0 === bccomp($amount, '0')) {
@@ -145,7 +144,7 @@ trait AccountServiceTrait
'type' => TransactionType::OPENING_BALANCE, 'type' => TransactionType::OPENING_BALANCE,
'user' => $account->user->id, 'user' => $account->user->id,
'transaction_currency_id' => $currencyId, 'transaction_currency_id' => $currencyId,
'description' => strval(trans('firefly.initial_balance_description', ['account' => $account->name])), 'description' => (string)trans('firefly.initial_balance_description', ['account' => $account->name]),
'completed' => true, 'completed' => true,
'date' => $data['openingBalanceDate'], 'date' => $data['openingBalanceDate'],
'bill_id' => null, 'bill_id' => null,
@@ -232,7 +231,6 @@ trait AccountServiceTrait
* @param array $data * @param array $data
* *
* @return bool * @return bool
* @throws \FireflyIII\Exceptions\FireflyException
*/ */
public function updateIB(Account $account, array $data): bool public function updateIB(Account $account, array $data): bool
{ {
@@ -268,9 +266,9 @@ trait AccountServiceTrait
public function updateIBJournal(Account $account, TransactionJournal $journal, array $data): bool public function updateIBJournal(Account $account, TransactionJournal $journal, array $data): bool
{ {
$date = $data['openingBalanceDate']; $date = $data['openingBalanceDate'];
$amount = strval($data['openingBalance']); $amount = (string)$data['openingBalance'];
$negativeAmount = bcmul($amount, '-1'); $negativeAmount = bcmul($amount, '-1');
$currencyId = intval($data['currency_id']); $currencyId = (int)$data['currency_id'];
Log::debug(sprintf('Submitted amount for opening balance to update is "%s"', $amount)); Log::debug(sprintf('Submitted amount for opening balance to update is "%s"', $amount));
if (0 === bccomp($amount, '0')) { if (0 === bccomp($amount, '0')) {
@@ -291,13 +289,13 @@ trait AccountServiceTrait
// update transactions: // update transactions:
/** @var Transaction $transaction */ /** @var Transaction $transaction */
foreach ($journal->transactions()->get() as $transaction) { foreach ($journal->transactions()->get() as $transaction) {
if (intval($account->id) === intval($transaction->account_id)) { if ((int)$account->id === (int)$transaction->account_id) {
Log::debug(sprintf('Will (eq) change transaction #%d amount from "%s" to "%s"', $transaction->id, $transaction->amount, $amount)); Log::debug(sprintf('Will (eq) change transaction #%d amount from "%s" to "%s"', $transaction->id, $transaction->amount, $amount));
$transaction->amount = $amount; $transaction->amount = $amount;
$transaction->transaction_currency_id = $currencyId; $transaction->transaction_currency_id = $currencyId;
$transaction->save(); $transaction->save();
} }
if (!(intval($account->id) === intval($transaction->account_id))) { if (!((int)$account->id === (int)$transaction->account_id)) {
Log::debug(sprintf('Will (neq) change transaction #%d amount from "%s" to "%s"', $transaction->id, $transaction->amount, $negativeAmount)); Log::debug(sprintf('Will (neq) change transaction #%d amount from "%s" to "%s"', $transaction->id, $transaction->amount, $negativeAmount));
$transaction->amount = $negativeAmount; $transaction->amount = $negativeAmount;
$transaction->transaction_currency_id = $currencyId; $transaction->transaction_currency_id = $currencyId;
@@ -383,9 +381,8 @@ trait AccountServiceTrait
*/ */
public function validIBData(array $data): bool public function validIBData(array $data): bool
{ {
$data['openingBalance'] = strval($data['openingBalance'] ?? ''); $data['openingBalance'] = (string)($data['openingBalance'] ?? '');
if (isset($data['openingBalance']) && null !== $data['openingBalance'] && strlen($data['openingBalance']) > 0 if (isset($data['openingBalance'], $data['openingBalanceDate']) && \strlen($data['openingBalance']) > 0) {
&& isset($data['openingBalanceDate'])) {
Log::debug('Array has valid opening balance data.'); Log::debug('Array has valid opening balance data.');
return true; return true;

View File

@@ -72,7 +72,7 @@ trait JournalServiceTrait
$factory->setUser($journal->user); $factory->setUser($journal->user);
$bill = $factory->find($data['bill_id'], $data['bill_name']); $bill = $factory->find($data['bill_id'], $data['bill_name']);
if (!is_null($bill)) { if (null !== $bill) {
$journal->bill_id = $bill->id; $journal->bill_id = $bill->id;
$journal->save(); $journal->save();
@@ -110,10 +110,10 @@ trait JournalServiceTrait
*/ */
protected function storeNote(TransactionJournal $journal, ?string $notes): void protected function storeNote(TransactionJournal $journal, ?string $notes): void
{ {
$notes = strval($notes); $notes = (string)$notes;
if (strlen($notes) > 0) { if (strlen($notes) > 0) {
$note = $journal->notes()->first(); $note = $journal->notes()->first();
if (is_null($note)) { if (null === $note) {
$note = new Note; $note = new Note;
$note->noteable()->associate($journal); $note->noteable()->associate($journal);
} }
@@ -123,7 +123,7 @@ trait JournalServiceTrait
return; return;
} }
$note = $journal->notes()->first(); $note = $journal->notes()->first();
if (!is_null($note)) { if (null !== $note) {
$note->delete(); $note->delete();
} }

View File

@@ -104,12 +104,12 @@ trait TransactionServiceTrait
*/ */
public function findAccount(?string $expectedType, ?int $accountId, ?string $accountName): Account public function findAccount(?string $expectedType, ?int $accountId, ?string $accountName): Account
{ {
$accountId = intval($accountId); $accountId = (int)$accountId;
$accountName = strval($accountName); $accountName = (string)$accountName;
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user); $repository->setUser($this->user);
if (is_null($expectedType)) { if (null === $expectedType) {
return $repository->findNull($accountId); return $repository->findNull($accountId);
} }
@@ -215,7 +215,7 @@ trait TransactionServiceTrait
*/ */
protected function setBudget(Transaction $transaction, ?Budget $budget): void protected function setBudget(Transaction $transaction, ?Budget $budget): void
{ {
if (is_null($budget)) { if (null === $budget) {
$transaction->budgets()->sync([]); $transaction->budgets()->sync([]);
return; return;
@@ -232,7 +232,7 @@ trait TransactionServiceTrait
*/ */
protected function setCategory(Transaction $transaction, ?Category $category): void protected function setCategory(Transaction $transaction, ?Category $category): void
{ {
if (is_null($category)) { if (null === $category) {
$transaction->categories()->sync([]); $transaction->categories()->sync([]);
return; return;
@@ -259,7 +259,7 @@ trait TransactionServiceTrait
*/ */
protected function setForeignCurrency(Transaction $transaction, ?TransactionCurrency $currency): void protected function setForeignCurrency(Transaction $transaction, ?TransactionCurrency $currency): void
{ {
if (is_null($currency)) { if (null === $currency) {
$transaction->foreign_currency_id = null; $transaction->foreign_currency_id = null;
$transaction->save(); $transaction->save();

View File

@@ -41,7 +41,6 @@ class AccountUpdateService
* @param array $data * @param array $data
* *
* @return Account * @return Account
* @throws \FireflyIII\Exceptions\FireflyException
*/ */
public function update(Account $account, array $data): Account public function update(Account $account, array $data): Account
{ {
@@ -68,7 +67,7 @@ class AccountUpdateService
// update note: // update note:
if (isset($data['notes']) && null !== $data['notes']) { if (isset($data['notes']) && null !== $data['notes']) {
$this->updateNote($account, strval($data['notes'])); $this->updateNote($account, (string)$data['notes']);
} }
return $account; return $account;

View File

@@ -45,7 +45,7 @@ class BillUpdateService
$matchArray = explode(',', $data['match']); $matchArray = explode(',', $data['match']);
$matchArray = array_unique($matchArray); $matchArray = array_unique($matchArray);
$match = join(',', $matchArray); $match = implode(',', $matchArray);
$bill->name = $data['name']; $bill->name = $data['name'];
$bill->match = $match; $bill->match = $match;
@@ -60,7 +60,7 @@ class BillUpdateService
// update note: // update note:
if (isset($data['notes']) && null !== $data['notes']) { if (isset($data['notes']) && null !== $data['notes']) {
$this->updateNote($bill, strval($data['notes'])); $this->updateNote($bill, (string)$data['notes']);
} }
return $bill; return $bill;

View File

@@ -45,7 +45,7 @@ class TransactionUpdateService
public function reconcile(int $transactionId): ?Transaction public function reconcile(int $transactionId): ?Transaction
{ {
$transaction = Transaction::find($transactionId); $transaction = Transaction::find($transactionId);
if (!is_null($transaction)) { if (null !== $transaction) {
$transaction->reconciled = true; $transaction->reconciled = true;
$transaction->save(); $transaction->save();
@@ -79,20 +79,20 @@ class TransactionUpdateService
// update description: // update description:
$transaction->description = $description; $transaction->description = $description;
$foreignAmount = null; $foreignAmount = null;
if (floatval($transaction->amount) < 0) { if ((float)$transaction->amount < 0) {
// this is the source transaction. // this is the source transaction.
$type = $this->accountType($journal, 'source'); $type = $this->accountType($journal, 'source');
$account = $this->findAccount($type, $data['source_id'], $data['source_name']); $account = $this->findAccount($type, $data['source_id'], $data['source_name']);
$amount = app('steam')->negative(strval($data['amount'])); $amount = app('steam')->negative((string)$data['amount']);
$foreignAmount = app('steam')->negative(strval($data['foreign_amount'])); $foreignAmount = app('steam')->negative((string)$data['foreign_amount']);
} }
if (floatval($transaction->amount) > 0) { if ((float)$transaction->amount > 0) {
// this is the destination transaction. // this is the destination transaction.
$type = $this->accountType($journal, 'destination'); $type = $this->accountType($journal, 'destination');
$account = $this->findAccount($type, $data['destination_id'], $data['destination_name']); $account = $this->findAccount($type, $data['destination_id'], $data['destination_name']);
$amount = app('steam')->positive(strval($data['amount'])); $amount = app('steam')->positive((string)$data['amount']);
$foreignAmount = app('steam')->positive(strval($data['foreign_amount'])); $foreignAmount = app('steam')->positive((string)$data['foreign_amount']);
} }
// update the actual transaction: // update the actual transaction:
@@ -107,11 +107,11 @@ class TransactionUpdateService
// set foreign currency // set foreign currency
$foreign = $this->findCurrency($data['foreign_currency_id'], $data['foreign_currency_code']); $foreign = $this->findCurrency($data['foreign_currency_id'], $data['foreign_currency_code']);
// set foreign amount: // set foreign amount:
if (!is_null($data['foreign_amount']) && !is_null($foreign)) { if (null !== $data['foreign_amount'] && null !== $foreign) {
$this->setForeignCurrency($transaction, $foreign); $this->setForeignCurrency($transaction, $foreign);
$this->setForeignAmount($transaction, $foreignAmount); $this->setForeignAmount($transaction, $foreignAmount);
} }
if (is_null($data['foreign_amount']) || is_null($foreign)) { if (null === $data['foreign_amount'] || null === $foreign) {
$this->setForeignCurrency($transaction, null); $this->setForeignCurrency($transaction, null);
$this->setForeignAmount($transaction, null); $this->setForeignAmount($transaction, null);
} }

View File

@@ -22,9 +22,9 @@ declare(strict_types=1);
namespace FireflyIII\Services\Password; namespace FireflyIII\Services\Password;
use Exception;
use Log; use Log;
use Requests; use Requests;
use Requests_Exception;
/** /**
* Class PwndVerifier. * Class PwndVerifier.
@@ -46,7 +46,7 @@ class PwndVerifier implements Verifier
try { try {
$result = Requests::get($uri, ['originalPasswordIsAHash' => 'true'], $opt); $result = Requests::get($uri, ['originalPasswordIsAHash' => 'true'], $opt);
} catch (Requests_Exception $e) { } catch (Exception $e) {
return true; return true;
} }
Log::debug(sprintf('Status code returned is %d', $result->status_code)); Log::debug(sprintf('Status code returned is %d', $result->status_code));

View File

@@ -22,9 +22,9 @@ declare(strict_types=1);
namespace FireflyIII\Services\Password; namespace FireflyIII\Services\Password;
use Exception;
use Log; use Log;
use Requests; use Requests;
use Requests_Exception;
/** /**
* Class PwndVerifierV2. * Class PwndVerifierV2.
@@ -51,7 +51,7 @@ class PwndVerifierV2 implements Verifier
try { try {
$result = Requests::get($uri, $opt); $result = Requests::get($uri, $opt);
} catch (Requests_Exception $e) { } catch (Exception $e) {
return true; return true;
} }
Log::debug(sprintf('Status code returned is %d', $result->status_code)); Log::debug(sprintf('Status code returned is %d', $result->status_code));

View File

@@ -41,7 +41,7 @@ class Customer extends SpectreObject
*/ */
public function __construct(array $data) public function __construct(array $data)
{ {
$this->id = intval($data['id']); $this->id = (int)$data['id'];
$this->identifier = $data['identifier']; $this->identifier = $data['identifier'];
$this->secret = $data['secret']; $this->secret = $data['secret'];
} }

View File

@@ -84,7 +84,7 @@ class Transaction extends SpectreObject
*/ */
public function getAmount(): string public function getAmount(): string
{ {
return strval($this->amount); return (string)$this->amount;
} }
/** /**
@@ -124,7 +124,7 @@ class Transaction extends SpectreObject
*/ */
public function getHash(): string public function getHash(): string
{ {
$array = [ $array = [
'id' => $this->id, 'id' => $this->id,
'mode' => $this->mode, 'mode' => $this->mode,
'status' => $this->status, 'status' => $this->status,
@@ -139,9 +139,8 @@ class Transaction extends SpectreObject
'created_at' => $this->createdAt->toIso8601String(), 'created_at' => $this->createdAt->toIso8601String(),
'updated_at' => $this->updatedAt->toIso8601String(), 'updated_at' => $this->updatedAt->toIso8601String(),
]; ];
$hashed = hash('sha256', json_encode($array));
return $hashed; return hash('sha256', json_encode($array));
} }
/** /**

View File

@@ -136,9 +136,9 @@ class TransactionExtra extends SpectreObject
'id' => $this->id, 'id' => $this->id,
'record_number' => $this->recordNumber, 'record_number' => $this->recordNumber,
'information' => $this->information, 'information' => $this->information,
'time' => is_null($this->time) ? null : $this->time->toIso8601String(), 'time' => null === $this->time ? null : $this->time->toIso8601String(),
'posting_date' => is_null($this->postingDate) ? null : $this->postingDate->toIso8601String(), 'posting_date' => null === $this->postingDate ? null : $this->postingDate->toIso8601String(),
'posting_time' => is_null($this->postingTime) ? null : $this->postingTime->toIso8601String(), 'posting_time' => null === $this->postingTime ? null : $this->postingTime->toIso8601String(),
'account_number' => $this->accountNumber, 'account_number' => $this->accountNumber,
'original_amount' => $this->originalAmount, 'original_amount' => $this->originalAmount,
'original_currency_code' => $this->originalCurrencyCode, 'original_currency_code' => $this->originalCurrencyCode,

View File

@@ -58,7 +58,7 @@ class ListAccountsRequest extends SpectreRequest
// extract next ID // extract next ID
$hasNextPage = false; $hasNextPage = false;
if (isset($response['meta']['next_id']) && intval($response['meta']['next_id']) > $nextId) { if (isset($response['meta']['next_id']) && (int)$response['meta']['next_id'] > $nextId) {
$hasNextPage = true; $hasNextPage = true;
$nextId = $response['meta']['next_id']; $nextId = $response['meta']['next_id'];
Log::debug(sprintf('Next ID is now %d.', $nextId)); Log::debug(sprintf('Next ID is now %d.', $nextId));

View File

@@ -55,7 +55,7 @@ class ListCustomersRequest extends SpectreRequest
// extract next ID // extract next ID
$hasNextPage = false; $hasNextPage = false;
if (isset($response['meta']['next_id']) && intval($response['meta']['next_id']) > $nextId) { if (isset($response['meta']['next_id']) && (int)$response['meta']['next_id'] > $nextId) {
$hasNextPage = true; $hasNextPage = true;
$nextId = $response['meta']['next_id']; $nextId = $response['meta']['next_id'];
Log::debug(sprintf('Next ID is now %d.', $nextId)); Log::debug(sprintf('Next ID is now %d.', $nextId));

View File

@@ -58,7 +58,7 @@ class ListLoginsRequest extends SpectreRequest
// extract next ID // extract next ID
$hasNextPage = false; $hasNextPage = false;
if (isset($response['meta']['next_id']) && intval($response['meta']['next_id']) > $nextId) { if (isset($response['meta']['next_id']) && (int)$response['meta']['next_id'] > $nextId) {
$hasNextPage = true; $hasNextPage = true;
$nextId = $response['meta']['next_id']; $nextId = $response['meta']['next_id'];
Log::debug(sprintf('Next ID is now %d.', $nextId)); Log::debug(sprintf('Next ID is now %d.', $nextId));

View File

@@ -58,7 +58,7 @@ class ListTransactionsRequest extends SpectreRequest
// extract next ID // extract next ID
$hasNextPage = false; $hasNextPage = false;
if (isset($response['meta']['next_id']) && intval($response['meta']['next_id']) > $nextId) { if (isset($response['meta']['next_id']) && (int)$response['meta']['next_id'] > $nextId) {
$hasNextPage = true; $hasNextPage = true;
$nextId = $response['meta']['next_id']; $nextId = $response['meta']['next_id'];
Log::debug(sprintf('Next ID is now %d.', $nextId)); Log::debug(sprintf('Next ID is now %d.', $nextId));

View File

@@ -22,12 +22,11 @@ declare(strict_types=1);
namespace FireflyIII\Services\Spectre\Request; namespace FireflyIII\Services\Spectre\Request;
use Exception;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Services\Spectre\Exception\SpectreException;
use FireflyIII\User; use FireflyIII\User;
use Log; use Log;
use Requests; use Requests;
use Requests_Exception;
use Requests_Response; use Requests_Response;
/** /**
@@ -44,9 +43,9 @@ abstract class SpectreRequest
/** @var string */ /** @var string */
protected $serviceSecret = ''; protected $serviceSecret = '';
/** @var string */ /** @var string */
private $privateKey = ''; private $privateKey;
/** @var string */ /** @var string */
private $server = ''; private $server;
/** @var User */ /** @var User */
private $user; private $user;
@@ -198,11 +197,11 @@ abstract class SpectreRequest
Log::debug('Final headers for spectre signed get request:', $headers); Log::debug('Final headers for spectre signed get request:', $headers);
try { try {
$response = Requests::get($fullUri, $headers); $response = Requests::get($fullUri, $headers);
} catch (Requests_Exception $e) { } catch (Exception $e) {
throw new FireflyException(sprintf('Request Exception: %s', $e->getMessage())); throw new FireflyException(sprintf('Request Exception: %s', $e->getMessage()));
} }
$this->detectError($response); $this->detectError($response);
$statusCode = intval($response->status_code); $statusCode = (int)$response->status_code;
$body = $response->body; $body = $response->body;
$array = json_decode($body, true); $array = json_decode($body, true);
@@ -241,7 +240,7 @@ abstract class SpectreRequest
Log::debug('Final headers for spectre signed POST request:', $headers); Log::debug('Final headers for spectre signed POST request:', $headers);
try { try {
$response = Requests::post($fullUri, $headers, $body); $response = Requests::post($fullUri, $headers, $body);
} catch (Requests_Exception $e) { } catch (Exception $e) {
throw new FireflyException(sprintf('Request Exception: %s', $e->getMessage())); throw new FireflyException(sprintf('Request Exception: %s', $e->getMessage()));
} }
$this->detectError($response); $this->detectError($response);
@@ -274,7 +273,7 @@ abstract class SpectreRequest
throw new FireflyException(sprintf('Error of class %s: %s', $errorClass, $message)); throw new FireflyException(sprintf('Error of class %s: %s', $errorClass, $message));
} }
$statusCode = intval($response->status_code); $statusCode = (int)$response->status_code;
if (200 !== $statusCode) { if (200 !== $statusCode) {
throw new FireflyException(sprintf('Status code %d: %s', $statusCode, $response->body)); throw new FireflyException(sprintf('Status code %d: %s', $statusCode, $response->body));
} }

View File

@@ -123,7 +123,7 @@ class Amount
setlocale(LC_MONETARY, $locale); setlocale(LC_MONETARY, $locale);
$float = round($amount, 12); $float = round($amount, 12);
$info = localeconv(); $info = localeconv();
$formatted = number_format($float, intval($format->decimal_places), $info['mon_decimal_point'], $info['mon_thousands_sep']); $formatted = number_format($float, (int)$format->decimal_places, $info['mon_decimal_point'], $info['mon_thousands_sep']);
// some complicated switches to format the amount correctly: // some complicated switches to format the amount correctly:
$precedes = $amount < 0 ? $info['n_cs_precedes'] : $info['p_cs_precedes']; $precedes = $amount < 0 ? $info['n_cs_precedes'] : $info['p_cs_precedes'];

View File

@@ -47,7 +47,7 @@ class AccountList implements BinderInterface
$list = []; $list = [];
$incoming = explode(',', $value); $incoming = explode(',', $value);
foreach ($incoming as $entry) { foreach ($incoming as $entry) {
$list[] = intval($entry); $list[] = (int)$entry;
} }
$list = array_unique($list); $list = array_unique($list);
if (count($list) === 0) { if (count($list) === 0) {

View File

@@ -45,7 +45,7 @@ class BudgetList implements BinderInterface
$list = []; $list = [];
$incoming = explode(',', $value); $incoming = explode(',', $value);
foreach ($incoming as $entry) { foreach ($incoming as $entry) {
$list[] = intval($entry); $list[] = (int)$entry;
} }
$list = array_unique($list); $list = array_unique($list);
if (count($list) === 0) { if (count($list) === 0) {

View File

@@ -45,7 +45,7 @@ class CategoryList implements BinderInterface
$list = []; $list = [];
$incoming = explode(',', $value); $incoming = explode(',', $value);
foreach ($incoming as $entry) { foreach ($incoming as $entry) {
$list[] = intval($entry); $list[] = (int)$entry;
} }
$list = array_unique($list); $list = array_unique($list);
if (count($list) === 0) { if (count($list) === 0) {

View File

@@ -44,7 +44,7 @@ class JournalList implements BinderInterface
$list = []; $list = [];
$incoming = explode(',', $value); $incoming = explode(',', $value);
foreach ($incoming as $entry) { foreach ($incoming as $entry) {
$list[] = intval($entry); $list[] = (int)$entry;
} }
$list = array_unique($list); $list = array_unique($list);
if (count($list) === 0) { if (count($list) === 0) {

View File

@@ -45,7 +45,7 @@ class UnfinishedJournal implements BinderInterface
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->where('completed', 0) ->where('completed', 0)
->where('user_id', auth()->user()->id)->first(['transaction_journals.*']); ->where('user_id', auth()->user()->id)->first(['transaction_journals.*']);
if (!is_null($journal)) { if (null !== $journal) {
return $journal; return $journal;
} }
} }

View File

@@ -46,7 +46,6 @@ class ExpandedForm
* *
* @return string * @return string
* @throws \FireflyIII\Exceptions\FireflyException * @throws \FireflyIII\Exceptions\FireflyException
* @throws \Throwable
*/ */
public function amount(string $name, $value = null, array $options = []): string public function amount(string $name, $value = null, array $options = []): string
{ {
@@ -60,7 +59,6 @@ class ExpandedForm
* *
* @return string * @return string
* @throws \FireflyIII\Exceptions\FireflyException * @throws \FireflyIII\Exceptions\FireflyException
* @throws \Throwable
*/ */
public function amountSmall(string $name, $value = null, array $options = []): string public function amountSmall(string $name, $value = null, array $options = []): string
{ {
@@ -73,7 +71,6 @@ class ExpandedForm
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \Throwable
*/ */
public function assetAccountList(string $name, $value = null, array $options = []): string public function assetAccountList(string $name, $value = null, array $options = []): string
{ {
@@ -100,17 +97,17 @@ class ExpandedForm
/** @var Account $account */ /** @var Account $account */
foreach ($assetAccounts as $account) { foreach ($assetAccounts as $account) {
$balance = app('steam')->balance($account, new Carbon); $balance = app('steam')->balance($account, new Carbon);
$currencyId = intval($account->getMeta('currency_id')); $currencyId = (int)$account->getMeta('currency_id');
$currency = $currencyRepos->findNull($currencyId); $currency = $currencyRepos->findNull($currencyId);
$role = $account->getMeta('accountRole'); $role = $account->getMeta('accountRole');
if (0 === strlen($role)) { if (0 === strlen($role)) {
$role = 'no_account_type'; // @codeCoverageIgnore $role = 'no_account_type'; // @codeCoverageIgnore
} }
if (is_null($currency)) { if (null === $currency) {
$currency = $defaultCurrency; $currency = $defaultCurrency;
} }
$key = strval(trans('firefly.opt_group_' . $role)); $key = (string)trans('firefly.opt_group_' . $role);
$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')'; $grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';
} }
$res = $this->select($name, $grouped, $value, $options); $res = $this->select($name, $grouped, $value, $options);
@@ -126,7 +123,6 @@ class ExpandedForm
* *
* @return string * @return string
* @throws \FireflyIII\Exceptions\FireflyException * @throws \FireflyIII\Exceptions\FireflyException
* @throws \Throwable
*/ */
public function balance(string $name, $value = null, array $options = []): string public function balance(string $name, $value = null, array $options = []): string
{ {
@@ -141,7 +137,7 @@ class ExpandedForm
* *
* @return string * @return string
* *
* @throws \Throwable
*/ */
public function checkbox(string $name, $value = 1, $checked = null, $options = []): string public function checkbox(string $name, $value = 1, $checked = null, $options = []): string
{ {
@@ -165,7 +161,7 @@ class ExpandedForm
* *
* @return string * @return string
* *
* @throws \Throwable
*/ */
public function date(string $name, $value = null, array $options = []): string public function date(string $name, $value = null, array $options = []): string
{ {
@@ -185,7 +181,7 @@ class ExpandedForm
* *
* @return string * @return string
* *
* @throws \Throwable
*/ */
public function file(string $name, array $options = []): string public function file(string $name, array $options = []): string
{ {
@@ -204,7 +200,7 @@ class ExpandedForm
* *
* @return string * @return string
* *
* @throws \Throwable
*/ */
public function integer(string $name, $value = null, array $options = []): string public function integer(string $name, $value = null, array $options = []): string
{ {
@@ -225,7 +221,7 @@ class ExpandedForm
* *
* @return string * @return string
* *
* @throws \Throwable
*/ */
public function location(string $name, $value = null, array $options = []): string public function location(string $name, $value = null, array $options = []): string
{ {
@@ -251,7 +247,7 @@ class ExpandedForm
$fields = ['title', 'name', 'description']; $fields = ['title', 'name', 'description'];
/** @var Eloquent $entry */ /** @var Eloquent $entry */
foreach ($set as $entry) { foreach ($set as $entry) {
$entryId = intval($entry->id); $entryId = (int)$entry->id;
$title = null; $title = null;
foreach ($fields as $field) { foreach ($fields as $field) {
@@ -277,7 +273,7 @@ class ExpandedForm
$fields = ['title', 'name', 'description']; $fields = ['title', 'name', 'description'];
/** @var Eloquent $entry */ /** @var Eloquent $entry */
foreach ($set as $entry) { foreach ($set as $entry) {
$entryId = intval($entry->id); $entryId = (int)$entry->id;
$title = null; $title = null;
foreach ($fields as $field) { foreach ($fields as $field) {
@@ -299,7 +295,7 @@ class ExpandedForm
* *
* @return string * @return string
* *
* @throws \Throwable
*/ */
public function multiCheckbox(string $name, array $list = [], $selected = null, array $options = []): string public function multiCheckbox(string $name, array $list = [], $selected = null, array $options = []): string
{ {
@@ -322,7 +318,7 @@ class ExpandedForm
* *
* @return string * @return string
* *
* @throws \Throwable
*/ */
public function multiRadio(string $name, array $list = [], $selected = null, array $options = []): string public function multiRadio(string $name, array $list = [], $selected = null, array $options = []): string
{ {
@@ -344,7 +340,7 @@ class ExpandedForm
* *
* @return string * @return string
* *
* @throws \Throwable
*/ */
public function nonSelectableAmount(string $name, $value = null, array $options = []): string public function nonSelectableAmount(string $name, $value = null, array $options = []): string
{ {
@@ -353,7 +349,7 @@ class ExpandedForm
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
$value = $this->fillFieldValue($name, $value); $value = $this->fillFieldValue($name, $value);
$options['step'] = 'any'; $options['step'] = 'any';
$selectedCurrency = isset($options['currency']) ? $options['currency'] : Amt::getDefaultCurrency(); $selectedCurrency = $options['currency'] ?? Amt::getDefaultCurrency();
unset($options['currency'], $options['placeholder']); unset($options['currency'], $options['placeholder']);
// make sure value is formatted nicely: // make sure value is formatted nicely:
@@ -373,7 +369,7 @@ class ExpandedForm
* *
* @return string * @return string
* *
* @throws \Throwable
*/ */
public function nonSelectableBalance(string $name, $value = null, array $options = []): string public function nonSelectableBalance(string $name, $value = null, array $options = []): string
{ {
@@ -382,7 +378,7 @@ class ExpandedForm
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
$value = $this->fillFieldValue($name, $value); $value = $this->fillFieldValue($name, $value);
$options['step'] = 'any'; $options['step'] = 'any';
$selectedCurrency = isset($options['currency']) ? $options['currency'] : Amt::getDefaultCurrency(); $selectedCurrency = $options['currency'] ?? Amt::getDefaultCurrency();
unset($options['currency'], $options['placeholder']); unset($options['currency'], $options['placeholder']);
// make sure value is formatted nicely: // make sure value is formatted nicely:
@@ -403,7 +399,7 @@ class ExpandedForm
* *
* @return string * @return string
* *
* @throws \Throwable
*/ */
public function number(string $name, $value = null, array $options = []): string public function number(string $name, $value = null, array $options = []): string
{ {
@@ -425,7 +421,7 @@ class ExpandedForm
* *
* @return string * @return string
* *
* @throws \Throwable
*/ */
public function optionsList(string $type, string $name): string public function optionsList(string $type, string $name): string
{ {
@@ -437,7 +433,7 @@ class ExpandedForm
// don't care // don't care
} }
$previousValue = null === $previousValue ? 'store' : $previousValue; $previousValue = $previousValue ?? 'store';
$html = view('form.options', compact('type', 'name', 'previousValue'))->render(); $html = view('form.options', compact('type', 'name', 'previousValue'))->render();
return $html; return $html;
@@ -449,14 +445,14 @@ class ExpandedForm
* *
* @return string * @return string
* *
* @throws \Throwable
*/ */
public function password(string $name, array $options = []): string public function password(string $name, array $options = []): string
{ {
$label = $this->label($name, $options); $label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options); $options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
$html = view('form.password', compact('classes', 'name', 'label', 'value', 'options'))->render(); $html = view('form.password', compact('classes', 'name', 'label', 'options'))->render();
return $html; return $html;
} }
@@ -469,7 +465,7 @@ class ExpandedForm
* *
* @return string * @return string
* *
* @throws \Throwable
*/ */
public function select(string $name, array $list = [], $selected = null, array $options = []): string public function select(string $name, array $list = [], $selected = null, array $options = []): string
{ {
@@ -490,7 +486,7 @@ class ExpandedForm
* *
* @return string * @return string
* *
* @throws \Throwable
*/ */
public function staticText(string $name, $value, array $options = []): string public function staticText(string $name, $value, array $options = []): string
{ {
@@ -509,7 +505,7 @@ class ExpandedForm
* *
* @return string * @return string
* *
* @throws \Throwable
*/ */
public function tags(string $name, $value = null, array $options = []): string public function tags(string $name, $value = null, array $options = []): string
{ {
@@ -530,7 +526,7 @@ class ExpandedForm
* *
* @return string * @return string
* *
* @throws \Throwable
*/ */
public function text(string $name, $value = null, array $options = []): string public function text(string $name, $value = null, array $options = []): string
{ {
@@ -550,7 +546,7 @@ class ExpandedForm
* *
* @return string * @return string
* *
* @throws \Throwable
*/ */
public function textarea(string $name, $value = null, array $options = []): string public function textarea(string $name, $value = null, array $options = []): string
{ {
@@ -640,7 +636,7 @@ class ExpandedForm
} }
$name = str_replace('[]', '', $name); $name = str_replace('[]', '', $name);
return strval(trans('form.' . $name)); return (string)trans('form.' . $name);
} }
/** /**
@@ -652,7 +648,6 @@ class ExpandedForm
* @return string * @return string
* *
* @throws \FireflyIII\Exceptions\FireflyException * @throws \FireflyIII\Exceptions\FireflyException
* @throws \Throwable
*/ */
private function currencyField(string $name, string $view, $value = null, array $options = []): string private function currencyField(string $name, string $view, $value = null, array $options = []): string
{ {
@@ -661,14 +656,14 @@ class ExpandedForm
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
$value = $this->fillFieldValue($name, $value); $value = $this->fillFieldValue($name, $value);
$options['step'] = 'any'; $options['step'] = 'any';
$defaultCurrency = isset($options['currency']) ? $options['currency'] : Amt::getDefaultCurrency(); $defaultCurrency = $options['currency'] ?? Amt::getDefaultCurrency();
$currencies = app('amount')->getAllCurrencies(); $currencies = app('amount')->getAllCurrencies();
unset($options['currency'], $options['placeholder']); unset($options['currency'], $options['placeholder']);
// perhaps the currency has been sent to us in the field $amount_currency_id_$name (amount_currency_id_amount) // perhaps the currency has been sent to us in the field $amount_currency_id_$name (amount_currency_id_amount)
$preFilled = session('preFilled'); $preFilled = session('preFilled');
$key = 'amount_currency_id_' . $name; $key = 'amount_currency_id_' . $name;
$sentCurrencyId = isset($preFilled[$key]) ? intval($preFilled[$key]) : $defaultCurrency->id; $sentCurrencyId = isset($preFilled[$key]) ? (int)$preFilled[$key] : $defaultCurrency->id;
// find this currency in set of currencies: // find this currency in set of currencies:
foreach ($currencies as $currency) { foreach ($currencies as $currency) {

View File

@@ -36,7 +36,7 @@ class FireflyConfig
* *
* @return bool * @return bool
* *
* @throws \Exception
*/ */
public function delete($name): bool public function delete($name): bool
{ {

View File

@@ -57,11 +57,11 @@ class HaveAccounts implements ConfigurationInterface
/** @var Account $dbAccount */ /** @var Account $dbAccount */
foreach ($collection as $dbAccount) { foreach ($collection as $dbAccount) {
$id = $dbAccount->id; $id = $dbAccount->id;
$currencyId = intval($accountRepository->getMetaValue($dbAccount, 'currency_id')); $currencyId = (int)$accountRepository->getMetaValue($dbAccount, 'currency_id');
$currency = $currencyRepository->findNull($currencyId); $currency = $currencyRepository->findNull($currencyId);
$dbAccounts[$id] = [ $dbAccounts[$id] = [
'account' => $dbAccount, 'account' => $dbAccount,
'currency' => is_null($currency) ? $defaultCurrency : $currency, 'currency' => null === $currency ? $defaultCurrency : $currency,
]; ];
} }
@@ -78,11 +78,9 @@ class HaveAccounts implements ConfigurationInterface
} }
$data = [ return [
'config' => $config, 'config' => $config,
]; ];
return $data;
} }
/** /**
@@ -119,9 +117,9 @@ class HaveAccounts implements ConfigurationInterface
$accounts = $data['bunq_account_id'] ?? []; $accounts = $data['bunq_account_id'] ?? [];
$mapping = []; $mapping = [];
foreach ($accounts as $bunqId) { foreach ($accounts as $bunqId) {
$bunqId = intval($bunqId); $bunqId = (int)$bunqId;
$doImport = intval($data['do_import'][$bunqId] ?? 0) === 1; $doImport = (int)($data['do_import'][$bunqId] ?? 0.0) === 1;
$account = intval($data['import'][$bunqId] ?? 0); $account = (int)($data['import'][$bunqId] ?? 0.0);
if ($doImport) { if ($doImport) {
$mapping[$bunqId] = $account; $mapping[$bunqId] = $account;
} }

View File

@@ -102,7 +102,7 @@ class Initial implements ConfigurationInterface
Log::debug('Now in storeConfiguration for file Upload.'); Log::debug('Now in storeConfiguration for file Upload.');
$config = $this->getConfig(); $config = $this->getConfig();
$type = $data['import_file_type'] ?? 'csv'; // assume it's a CSV file. $type = $data['import_file_type'] ?? 'csv'; // assume it's a CSV file.
$config['file-type'] = in_array($type, config('import.options.file.import_formats')) ? $type : 'csv'; $config['file-type'] = \in_array($type, config('import.options.file.import_formats'), true) ? $type : 'csv';
// update config: // update config:
$this->repository->setConfiguration($this->job, $config); $this->repository->setConfiguration($this->job, $config);
@@ -118,7 +118,7 @@ class Initial implements ConfigurationInterface
} }
if (false === $uploaded) { if (false === $uploaded) {
$this->warning = 'No valid upload.'; $this->warning = (string)trans('firefly.upload_error');
return true; return true;
} }

View File

@@ -159,12 +159,12 @@ class Map implements ConfigurationInterface
$config = $this->getConfig(); $config = $this->getConfig();
if (isset($data['mapping'])) { if (isset($data['mapping'])) {
foreach ($data['mapping'] as $index => $data) { foreach ($data['mapping'] as $index => $array) {
$config['column-mapping-config'][$index] = []; $config['column-mapping-config'][$index] = [];
foreach ($data as $value => $mapId) { foreach ($array as $value => $mapId) {
$mapId = intval($mapId); $mapId = (int)$mapId;
if (0 !== $mapId) { if (0 !== $mapId) {
$config['column-mapping-config'][$index][$value] = intval($mapId); $config['column-mapping-config'][$index][$value] = $mapId;
} }
} }
} }
@@ -186,10 +186,8 @@ class Map implements ConfigurationInterface
{ {
$mapperClass = config('csv.import_roles.' . $column . '.mapper'); $mapperClass = config('csv.import_roles.' . $column . '.mapper');
$mapperName = sprintf('\\FireflyIII\\Import\Mapper\\%s', $mapperClass); $mapperName = sprintf('\\FireflyIII\\Import\Mapper\\%s', $mapperClass);
/** @var MapperInterface $mapper */
$mapper = app($mapperName);
return $mapper; return app($mapperName);
} }
/** /**

View File

@@ -73,7 +73,7 @@ class Roles implements ConfigurationInterface
} }
// example rows: // example rows:
$stmt = (new Statement)->limit(intval(config('csv.example_rows', 5)))->offset($offset); $stmt = (new Statement)->limit((int)config('csv.example_rows', 5))->offset($offset);
// set data: // set data:
$roles = $this->getRoles(); $roles = $this->getRoles();
asort($roles); asort($roles);
@@ -274,14 +274,14 @@ class Roles implements ConfigurationInterface
} }
// warn if has foreign amount but no currency code: // warn if has foreign amount but no currency code:
if ($hasForeignAmount && !$hasForeignCode) { if ($hasForeignAmount && !$hasForeignCode) {
$this->warning = strval(trans('import.foreign_amount_warning')); $this->warning = (string)trans('import.foreign_amount_warning');
Log::debug('isRolesComplete() returns FALSE because foreign amount present without foreign code.'); Log::debug('isRolesComplete() returns FALSE because foreign amount present without foreign code.');
return false; return false;
} }
if (0 === $assigned || !$hasAmount) { if (0 === $assigned || !$hasAmount) {
$this->warning = strval(trans('import.roles_warning')); $this->warning = (string)trans('import.roles_warning');
Log::debug('isRolesComplete() returns FALSE because no amount present.'); Log::debug('isRolesComplete() returns FALSE because no amount present.');
return false; return false;

View File

@@ -114,16 +114,16 @@ class UploadConfig implements ConfigurationInterface
{ {
Log::debug('Now in Initial::storeConfiguration()'); Log::debug('Now in Initial::storeConfiguration()');
$config = $this->getConfig(); $config = $this->getConfig();
$importId = intval($data['csv_import_account'] ?? 0); $importId = (int)($data['csv_import_account'] ?? 0.0);
$account = $this->accountRepository->find($importId); $account = $this->accountRepository->find($importId);
$delimiter = strval($data['csv_delimiter']); $delimiter = (string)$data['csv_delimiter'];
// set "headers": // set "headers":
$config['has-headers'] = intval($data['has_headers'] ?? 0) === 1; $config['has-headers'] = (int)($data['has_headers'] ?? 0.0) === 1;
$config['date-format'] = strval($data['date_format']); $config['date-format'] = (string)$data['date_format'];
$config['delimiter'] = 'tab' === $delimiter ? "\t" : $delimiter; $config['delimiter'] = 'tab' === $delimiter ? "\t" : $delimiter;
$config['apply-rules'] = intval($data['apply_rules'] ?? 0) === 1; $config['apply-rules'] = (int)($data['apply_rules'] ?? 0.0) === 1;
$config['match-bills'] = intval($data['match_bills'] ?? 0) === 1; $config['match-bills'] = (int)($data['match_bills'] ?? 0.0) === 1;
Log::debug('Entered import account.', ['id' => $importId]); Log::debug('Entered import account.', ['id' => $importId]);

View File

@@ -58,11 +58,11 @@ class HaveAccounts implements ConfigurationInterface
/** @var Account $dbAccount */ /** @var Account $dbAccount */
foreach ($collection as $dbAccount) { foreach ($collection as $dbAccount) {
$id = $dbAccount->id; $id = $dbAccount->id;
$currencyId = intval($dbAccount->getMeta('currency_id')); $currencyId = (int)$dbAccount->getMeta('currency_id');
$currency = $currencyRepository->find($currencyId); $currency = $currencyRepository->find($currencyId);
$dbAccounts[$id] = [ $dbAccounts[$id] = [
'account' => $dbAccount, 'account' => $dbAccount,
'currency' => is_null($currency->id) ? $defaultCurrency : $currency, 'currency' => null === $currency->id ? $defaultCurrency : $currency,
]; ];
} }
@@ -79,12 +79,9 @@ class HaveAccounts implements ConfigurationInterface
} }
$data = [ return [
'config' => $config, 'config' => $config,
]; ];
return $data;
} }
/** /**
@@ -121,9 +118,9 @@ class HaveAccounts implements ConfigurationInterface
$accounts = $data['spectre_account_id'] ?? []; $accounts = $data['spectre_account_id'] ?? [];
$mapping = []; $mapping = [];
foreach ($accounts as $spectreId) { foreach ($accounts as $spectreId) {
$spectreId = intval($spectreId); $spectreId = (int)$spectreId;
$doImport = intval($data['do_import'][$spectreId] ?? 0) === 1; $doImport = (int)($data['do_import'][$spectreId] ?? 0.0) === 1;
$account = intval($data['import'][$spectreId] ?? 0); $account = (int)($data['import'][$spectreId] ?? 0.0);
if ($doImport) { if ($doImport) {
$mapping[$spectreId] = $account; $mapping[$spectreId] = $account;
} }

View File

@@ -63,7 +63,6 @@ class BunqInformation implements InformationInterface
* @return array * @return array
* *
* @throws FireflyException * @throws FireflyException
* @throws \Exception
*/ */
public function getAccounts(): array public function getAccounts(): array
{ {
@@ -117,7 +116,7 @@ class BunqInformation implements InformationInterface
/** /**
* @param SessionToken $sessionToken * @param SessionToken $sessionToken
* *
* @throws \Exception
*/ */
private function closeSession(SessionToken $sessionToken): void private function closeSession(SessionToken $sessionToken): void
{ {
@@ -141,7 +140,7 @@ class BunqInformation implements InformationInterface
* *
* @return Collection * @return Collection
* *
* @throws \Exception
*/ */
private function getMonetaryAccounts(SessionToken $sessionToken, int $userId): Collection private function getMonetaryAccounts(SessionToken $sessionToken, int $userId): Collection
{ {
@@ -166,7 +165,6 @@ class BunqInformation implements InformationInterface
* @return int * @return int
* *
* @throws FireflyException * @throws FireflyException
* @throws \Exception
*/ */
private function getUserInformation(SessionToken $sessionToken): int private function getUserInformation(SessionToken $sessionToken): int
{ {
@@ -194,7 +192,7 @@ class BunqInformation implements InformationInterface
/** /**
* @return SessionToken * @return SessionToken
* *
* @throws \Exception
*/ */
private function startSession(): SessionToken private function startSession(): SessionToken
{ {

View File

@@ -91,7 +91,7 @@ class Navigation
public function blockPeriods(\Carbon\Carbon $start, \Carbon\Carbon $end, string $range): array public function blockPeriods(\Carbon\Carbon $start, \Carbon\Carbon $end, string $range): array
{ {
if ($end < $start) { if ($end < $start) {
list($start, $end) = [$end, $start]; [$start, $end] = [$end, $start];
} }
$periods = []; $periods = [];
/* /*
@@ -262,17 +262,17 @@ class Navigation
// define period to increment // define period to increment
$increment = 'addDay'; $increment = 'addDay';
$format = $this->preferredCarbonFormat($start, $end); $format = $this->preferredCarbonFormat($start, $end);
$displayFormat = strval(trans('config.month_and_day')); $displayFormat = (string)trans('config.month_and_day');
// increment by month (for year) // increment by month (for year)
if ($start->diffInMonths($end) > 1) { if ($start->diffInMonths($end) > 1) {
$increment = 'addMonth'; $increment = 'addMonth';
$displayFormat = strval(trans('config.month')); $displayFormat = (string)trans('config.month');
} }
// increment by year (for multi year) // increment by year (for multi year)
if ($start->diffInMonths($end) > 12) { if ($start->diffInMonths($end) > 12) {
$increment = 'addYear'; $increment = 'addYear';
$displayFormat = strval(trans('config.year')); $displayFormat = (string)trans('config.year');
} }
$begin = clone $start; $begin = clone $start;
@@ -316,7 +316,7 @@ class Navigation
]; ];
if (isset($formatMap[$repeatFrequency])) { if (isset($formatMap[$repeatFrequency])) {
return $date->formatLocalized(strval($formatMap[$repeatFrequency])); return $date->formatLocalized((string)$formatMap[$repeatFrequency]);
} }
if ('3M' === $repeatFrequency || 'quarter' === $repeatFrequency) { if ('3M' === $repeatFrequency || 'quarter' === $repeatFrequency) {
$quarter = ceil($theDate->month / 3); $quarter = ceil($theDate->month / 3);
@@ -362,13 +362,13 @@ class Navigation
*/ */
public function preferredCarbonLocalizedFormat(Carbon $start, Carbon $end): string public function preferredCarbonLocalizedFormat(Carbon $start, Carbon $end): string
{ {
$format = strval(trans('config.month_and_day')); $format = (string)trans('config.month_and_day');
if ($start->diffInMonths($end) > 1) { if ($start->diffInMonths($end) > 1) {
$format = strval(trans('config.month')); $format = (string)trans('config.month');
} }
if ($start->diffInMonths($end) > 12) { if ($start->diffInMonths($end) > 12) {
$format = strval(trans('config.year')); $format = (string)trans('config.year');
} }
return $format; return $format;

View File

@@ -75,9 +75,7 @@ class Preferences
*/ */
public function findByName(string $name): Collection public function findByName(string $name): Collection
{ {
$set = Preference::where('name', $name)->get(); return Preference::where('name', $name)->get();
return $set;
} }
/** /**
@@ -168,7 +166,7 @@ class Preferences
if (null !== $preference && null !== $preference->data) { if (null !== $preference && null !== $preference->data) {
$lastActivity = $preference->data; $lastActivity = $preference->data;
} }
if (is_array($lastActivity)) { if (\is_array($lastActivity)) {
$lastActivity = implode(',', $lastActivity); $lastActivity = implode(',', $lastActivity);
} }

View File

@@ -166,11 +166,11 @@ class Modifier
{ {
$journalBudget = ''; $journalBudget = '';
if (null !== $transaction->transaction_journal_budget_name) { if (null !== $transaction->transaction_journal_budget_name) {
$journalBudget = Steam::decrypt(intval($transaction->transaction_journal_budget_encrypted), $transaction->transaction_journal_budget_name); $journalBudget = Steam::decrypt((int)$transaction->transaction_journal_budget_encrypted, $transaction->transaction_journal_budget_name);
} }
$transactionBudget = ''; $transactionBudget = '';
if (null !== $transaction->transaction_budget_name) { if (null !== $transaction->transaction_budget_name) {
$journalBudget = Steam::decrypt(intval($transaction->transaction_budget_encrypted), $transaction->transaction_budget_name); $journalBudget = Steam::decrypt((int)$transaction->transaction_budget_encrypted, $transaction->transaction_budget_name);
} }
return self::stringCompare($journalBudget, $search) || self::stringCompare($transactionBudget, $search); return self::stringCompare($journalBudget, $search) || self::stringCompare($transactionBudget, $search);
@@ -186,11 +186,11 @@ class Modifier
{ {
$journalCategory = ''; $journalCategory = '';
if (null !== $transaction->transaction_journal_category_name) { if (null !== $transaction->transaction_journal_category_name) {
$journalCategory = Steam::decrypt(intval($transaction->transaction_journal_category_encrypted), $transaction->transaction_journal_category_name); $journalCategory = Steam::decrypt((int)$transaction->transaction_journal_category_encrypted, $transaction->transaction_journal_category_name);
} }
$transactionCategory = ''; $transactionCategory = '';
if (null !== $transaction->transaction_category_name) { if (null !== $transaction->transaction_category_name) {
$journalCategory = Steam::decrypt(intval($transaction->transaction_category_encrypted), $transaction->transaction_category_name); $journalCategory = Steam::decrypt((int)$transaction->transaction_category_encrypted, $transaction->transaction_category_name);
} }
return self::stringCompare($journalCategory, $search) || self::stringCompare($transactionCategory, $search); return self::stringCompare($journalCategory, $search) || self::stringCompare($transactionCategory, $search);

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Support\Search; namespace FireflyIII\Support\Search;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter; use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
@@ -45,7 +44,7 @@ class Search implements SearchInterface
/** @var User */ /** @var User */
private $user; private $user;
/** @var array */ /** @var array */
private $validModifiers = []; private $validModifiers;
/** @var array */ /** @var array */
private $words = []; private $words = [];
@@ -63,7 +62,7 @@ class Search implements SearchInterface
*/ */
public function getWordsAsString(): string public function getWordsAsString(): string
{ {
$string = join(' ', $this->words); $string = implode(' ', $this->words);
if (0 === strlen($string)) { if (0 === strlen($string)) {
return is_string($this->originalQuery) ? $this->originalQuery : ''; return is_string($this->originalQuery) ? $this->originalQuery : '';
} }
@@ -196,19 +195,19 @@ class Search implements SearchInterface
switch ($modifier['type']) { switch ($modifier['type']) {
case 'amount_is': case 'amount_is':
case 'amount': case 'amount':
$amount = app('steam')->positive(strval($modifier['value'])); $amount = app('steam')->positive((string)$modifier['value']);
Log::debug(sprintf('Set "%s" using collector with value "%s"', $modifier['type'], $amount)); Log::debug(sprintf('Set "%s" using collector with value "%s"', $modifier['type'], $amount));
$collector->amountIs($amount); $collector->amountIs($amount);
break; break;
case 'amount_max': case 'amount_max':
case 'amount_less': case 'amount_less':
$amount = app('steam')->positive(strval($modifier['value'])); $amount = app('steam')->positive((string)$modifier['value']);
Log::debug(sprintf('Set "%s" using collector with value "%s"', $modifier['type'], $amount)); Log::debug(sprintf('Set "%s" using collector with value "%s"', $modifier['type'], $amount));
$collector->amountLess($amount); $collector->amountLess($amount);
break; break;
case 'amount_min': case 'amount_min':
case 'amount_more': case 'amount_more':
$amount = app('steam')->positive(strval($modifier['value'])); $amount = app('steam')->positive((string)$modifier['value']);
Log::debug(sprintf('Set "%s" using collector with value "%s"', $modifier['type'], $amount)); Log::debug(sprintf('Set "%s" using collector with value "%s"', $modifier['type'], $amount));
$collector->amountMore($amount); $collector->amountMore($amount);
break; break;
@@ -246,9 +245,9 @@ class Search implements SearchInterface
private function extractModifier(string $string) private function extractModifier(string $string)
{ {
$parts = explode(':', $string); $parts = explode(':', $string);
if (2 === count($parts) && strlen(trim(strval($parts[0]))) > 0 && strlen(trim(strval($parts[1])))) { if (2 === count($parts) && strlen(trim((string)$parts[0])) > 0 && strlen(trim((string)$parts[1]))) {
$type = trim(strval($parts[0])); $type = trim((string)$parts[0]);
$value = trim(strval($parts[1])); $value = trim((string)$parts[1]);
if (in_array($type, $this->validModifiers)) { if (in_array($type, $this->validModifiers)) {
// filter for valid type // filter for valid type
$this->modifiers->push(['type' => $type, 'value' => $value]); $this->modifiers->push(['type' => $type, 'value' => $value]);
@@ -268,8 +267,8 @@ class Search implements SearchInterface
// first "modifier" is always the text of the search: // first "modifier" is always the text of the search:
// check descr of journal: // check descr of journal:
if (count($this->words) > 0 if (count($this->words) > 0
&& !$this->strposArray(strtolower(strval($transaction->description)), $this->words) && !$this->strposArray(strtolower((string)$transaction->description), $this->words)
&& !$this->strposArray(strtolower(strval($transaction->transaction_description)), $this->words) && !$this->strposArray(strtolower((string)$transaction->transaction_description), $this->words)
) { ) {
Log::debug('Description does not match', $this->words); Log::debug('Description does not match', $this->words);

View File

@@ -51,32 +51,28 @@ class Steam
if ($cache->has()) { if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore return $cache->get(); // @codeCoverageIgnore
} }
$currencyId = intval($account->getMeta('currency_id')); $currencyId = (int)$account->getMeta('currency_id');
// use system default currency: // use system default currency:
if (0 === $currencyId) { if (0 === $currencyId) {
$currency = app('amount')->getDefaultCurrencyByUser($account->user); $currency = app('amount')->getDefaultCurrencyByUser($account->user);
$currencyId = $currency->id; $currencyId = $currency->id;
} }
// first part: get all balances in own currency: // first part: get all balances in own currency:
$nativeBalance = strval( $nativeBalance = (string)$account->transactions()
$account->transactions() ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) ->where('transactions.transaction_currency_id', $currencyId)
->where('transactions.transaction_currency_id', $currencyId) ->sum('transactions.amount');
->sum('transactions.amount')
);
// get all balances in foreign currency: // get all balances in foreign currency:
$foreignBalance = strval( $foreignBalance = (string)$account->transactions()
$account->transactions() ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->where('transaction_journals.date', '<=', $date->format('Y-m-d')) ->where('transactions.foreign_currency_id', $currencyId)
->where('transactions.foreign_currency_id', $currencyId) ->where('transactions.transaction_currency_id', '!=', $currencyId)
->where('transactions.transaction_currency_id', '!=', $currencyId) ->sum('transactions.foreign_amount');
->sum('transactions.foreign_amount')
);
$balance = bcadd($nativeBalance, $foreignBalance); $balance = bcadd($nativeBalance, $foreignBalance);
$virtual = null === $account->virtual_balance ? '0' : strval($account->virtual_balance); $virtual = null === $account->virtual_balance ? '0' : (string)$account->virtual_balance;
$balance = bcadd($balance, $virtual); $balance = bcadd($balance, $virtual);
$cache->store($balance); $cache->store($balance);
@@ -99,25 +95,21 @@ class Steam
if ($cache->has()) { if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore return $cache->get(); // @codeCoverageIgnore
} }
$currencyId = intval($account->getMeta('currency_id')); $currencyId = (int)$account->getMeta('currency_id');
$nativeBalance = strval( $nativeBalance = (string)$account->transactions()
$account->transactions() ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->where('transaction_journals.date', '<=', $date->format('Y-m-d')) ->where('transactions.transaction_currency_id', $currencyId)
->where('transactions.transaction_currency_id', $currencyId) ->sum('transactions.amount');
->sum('transactions.amount')
);
// get all balances in foreign currency: // get all balances in foreign currency:
$foreignBalance = strval( $foreignBalance = (string)$account->transactions()
$account->transactions() ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->where('transaction_journals.date', '<=', $date->format('Y-m-d')) ->where('transactions.foreign_currency_id', $currencyId)
->where('transactions.foreign_currency_id', $currencyId) ->where('transactions.transaction_currency_id', '!=', $currencyId)
->where('transactions.transaction_currency_id', '!=', $currencyId) ->sum('transactions.foreign_amount');
->sum('transactions.foreign_amount')
);
$balance = bcadd($nativeBalance, $foreignBalance); $balance = bcadd($nativeBalance, $foreignBalance);
$cache->store($balance); $cache->store($balance);
@@ -155,7 +147,7 @@ class Steam
$startBalance = $this->balance($account, $start); $startBalance = $this->balance($account, $start);
$balances[$formatted] = $startBalance; $balances[$formatted] = $startBalance;
$currencyId = intval($account->getMeta('currency_id')); $currencyId = (int)$account->getMeta('currency_id');
$start->addDay(); $start->addDay();
// query! // query!
@@ -182,14 +174,14 @@ class Steam
/** @var Transaction $entry */ /** @var Transaction $entry */
foreach ($set as $entry) { foreach ($set as $entry) {
// normal amount and foreign amount // normal amount and foreign amount
$modified = null === $entry->modified ? '0' : strval($entry->modified); $modified = null === $entry->modified ? '0' : (string)$entry->modified;
$foreignModified = null === $entry->modified_foreign ? '0' : strval($entry->modified_foreign); $foreignModified = null === $entry->modified_foreign ? '0' : (string)$entry->modified_foreign;
$amount = '0'; $amount = '0';
if ($currencyId === intval($entry->transaction_currency_id) || 0 === $currencyId) { if ($currencyId === (int)$entry->transaction_currency_id || 0 === $currencyId) {
// use normal amount: // use normal amount:
$amount = $modified; $amount = $modified;
} }
if ($currencyId === intval($entry->foreign_currency_id)) { if ($currencyId === (int)$entry->foreign_currency_id) {
// use foreign amount: // use foreign amount:
$amount = $foreignModified; $amount = $foreignModified;
} }
@@ -268,7 +260,7 @@ class Steam
->get(['transactions.account_id', DB::raw('MAX(transaction_journals.date) AS max_date')]); ->get(['transactions.account_id', DB::raw('MAX(transaction_journals.date) AS max_date')]);
foreach ($set as $entry) { foreach ($set as $entry) {
$list[intval($entry->account_id)] = new Carbon($entry->max_date); $list[(int)$entry->account_id] = new Carbon($entry->max_date);
} }
return $list; return $list;
@@ -295,7 +287,7 @@ class Steam
*/ */
public function opposite(string $amount = null): ?string public function opposite(string $amount = null): ?string
{ {
if (is_null($amount)) { if (null === $amount) {
return null; return null;
} }
$amount = bcmul($amount, '-1'); $amount = bcmul($amount, '-1');
@@ -316,24 +308,24 @@ class Steam
// has a K in it, remove the K and multiply by 1024. // has a K in it, remove the K and multiply by 1024.
$bytes = bcmul(rtrim($string, 'kK'), '1024'); $bytes = bcmul(rtrim($string, 'kK'), '1024');
return intval($bytes); return (int)$bytes;
} }
if (!(false === stripos($string, 'm'))) { if (!(false === stripos($string, 'm'))) {
// has a M in it, remove the M and multiply by 1048576. // has a M in it, remove the M and multiply by 1048576.
$bytes = bcmul(rtrim($string, 'mM'), '1048576'); $bytes = bcmul(rtrim($string, 'mM'), '1048576');
return intval($bytes); return (int)$bytes;
} }
if (!(false === stripos($string, 'g'))) { if (!(false === stripos($string, 'g'))) {
// has a G in it, remove the G and multiply by (1024)^3. // has a G in it, remove the G and multiply by (1024)^3.
$bytes = bcmul(rtrim($string, 'gG'), '1073741824'); $bytes = bcmul(rtrim($string, 'gG'), '1073741824');
return intval($bytes); return (int)$bytes;
} }
return intval($string); return (int)$string;
} }
/** /**

View File

@@ -45,12 +45,12 @@ class Transaction extends Twig_Extension
*/ */
public function amount(TransactionModel $transaction): string public function amount(TransactionModel $transaction): string
{ {
$amount = bcmul(app('steam')->positive(strval($transaction->transaction_amount)), '-1'); $amount = bcmul(app('steam')->positive((string)$transaction->transaction_amount), '-1');
$format = '%s'; $format = '%s';
$coloured = true; $coloured = true;
// at this point amount is always negative. // at this point amount is always negative.
if (TransactionType::RECONCILIATION === $transaction->transaction_type_type && 1 === bccomp(strval($transaction->transaction_amount), '0')) { if (TransactionType::RECONCILIATION === $transaction->transaction_type_type && 1 === bccomp((string)$transaction->transaction_amount, '0')) {
$amount = bcmul($amount, '-1'); $amount = bcmul($amount, '-1');
} }
@@ -64,7 +64,7 @@ class Transaction extends Twig_Extension
$format = '<span class="text-info">%s</span>'; $format = '<span class="text-info">%s</span>';
} }
if (TransactionType::OPENING_BALANCE === $transaction->transaction_type_type) { if (TransactionType::OPENING_BALANCE === $transaction->transaction_type_type) {
$amount = strval($transaction->transaction_amount); $amount = (string)$transaction->transaction_amount;
} }
$currency = new TransactionCurrency; $currency = new TransactionCurrency;
@@ -73,7 +73,7 @@ class Transaction extends Twig_Extension
$str = sprintf($format, app('amount')->formatAnything($currency, $amount, $coloured)); $str = sprintf($format, app('amount')->formatAnything($currency, $amount, $coloured));
if (null !== $transaction->transaction_foreign_amount) { if (null !== $transaction->transaction_foreign_amount) {
$amount = bcmul(app('steam')->positive(strval($transaction->transaction_foreign_amount)), '-1'); $amount = bcmul(app('steam')->positive((string)$transaction->transaction_foreign_amount), '-1');
if (TransactionType::DEPOSIT === $transaction->transaction_type_type) { if (TransactionType::DEPOSIT === $transaction->transaction_type_type) {
$amount = bcmul($amount, '-1'); $amount = bcmul($amount, '-1');
} }
@@ -101,7 +101,7 @@ class Transaction extends Twig_Extension
public function amountArray(array $transaction): string public function amountArray(array $transaction): string
{ {
// first display amount: // first display amount:
$amount = strval($transaction['amount']); $amount = (string)$transaction['amount'];
$fakeCurrency = new TransactionCurrency; $fakeCurrency = new TransactionCurrency;
$fakeCurrency->decimal_places = $transaction['currency_dp']; $fakeCurrency->decimal_places = $transaction['currency_dp'];
$fakeCurrency->symbol = $transaction['currency_symbol']; $fakeCurrency->symbol = $transaction['currency_symbol'];
@@ -109,7 +109,7 @@ class Transaction extends Twig_Extension
// then display (if present) the foreign amount: // then display (if present) the foreign amount:
if (null !== $transaction['foreign_amount']) { if (null !== $transaction['foreign_amount']) {
$amount = strval($transaction['foreign_amount']); $amount = (string)$transaction['foreign_amount'];
$fakeCurrency = new TransactionCurrency; $fakeCurrency = new TransactionCurrency;
$fakeCurrency->decimal_places = $transaction['foreign_currency_dp']; $fakeCurrency->decimal_places = $transaction['foreign_currency_dp'];
$fakeCurrency->symbol = $transaction['foreign_currency_symbol']; $fakeCurrency->symbol = $transaction['foreign_currency_symbol'];
@@ -205,7 +205,7 @@ class Transaction extends Twig_Extension
public function description(TransactionModel $transaction): string public function description(TransactionModel $transaction): string
{ {
$description = $transaction->description; $description = $transaction->description;
if (strlen(strval($transaction->transaction_description)) > 0) { if (strlen((string)$transaction->transaction_description) > 0) {
$description = $transaction->transaction_description . ' (' . $transaction->description . ')'; $description = $transaction->transaction_description . ' (' . $transaction->description . ')';
} }
@@ -226,13 +226,13 @@ class Transaction extends Twig_Extension
} }
$name = app('steam')->tryDecrypt($transaction->account_name); $name = app('steam')->tryDecrypt($transaction->account_name);
$transactionId = intval($transaction->account_id); $transactionId = (int)$transaction->account_id;
$type = $transaction->account_type; $type = $transaction->account_type;
// name is present in object, use that one: // name is present in object, use that one:
if (bccomp($transaction->transaction_amount, '0') === -1 && null !== $transaction->opposing_account_id) { if (bccomp($transaction->transaction_amount, '0') === -1 && null !== $transaction->opposing_account_id) {
$name = $transaction->opposing_account_name; $name = $transaction->opposing_account_name;
$transactionId = intval($transaction->opposing_account_id); $transactionId = (int)$transaction->opposing_account_id;
$type = $transaction->opposing_account_type; $type = $transaction->opposing_account_type;
} }
@@ -249,7 +249,7 @@ class Transaction extends Twig_Extension
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']); ->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
if (is_null($other)) { if (null === $other) {
Log::error(sprintf('Cannot find other transaction for journal #%d', $journalId)); Log::error(sprintf('Cannot find other transaction for journal #%d', $journalId));
return ''; return '';
@@ -384,13 +384,13 @@ class Transaction extends Twig_Extension
// if the amount is negative, assume that the current account (the one in $transaction) is indeed the source account. // if the amount is negative, assume that the current account (the one in $transaction) is indeed the source account.
$name = app('steam')->tryDecrypt($transaction->account_name); $name = app('steam')->tryDecrypt($transaction->account_name);
$transactionId = intval($transaction->account_id); $transactionId = (int)$transaction->account_id;
$type = $transaction->account_type; $type = $transaction->account_type;
// name is present in object, use that one: // name is present in object, use that one:
if (1 === bccomp($transaction->transaction_amount, '0') && null !== $transaction->opposing_account_id) { if (1 === bccomp($transaction->transaction_amount, '0') && null !== $transaction->opposing_account_id) {
$name = $transaction->opposing_account_name; $name = $transaction->opposing_account_name;
$transactionId = intval($transaction->opposing_account_id); $transactionId = (int)$transaction->opposing_account_id;
$type = $transaction->opposing_account_type; $type = $transaction->opposing_account_type;
} }
// Find the opposing account and use that one: // Find the opposing account and use that one:

View File

@@ -59,7 +59,7 @@ class TransactionJournal extends Twig_Extension
/** @var JournalRepositoryInterface $repository */ /** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class); $repository = app(JournalRepositoryInterface::class);
$result = $repository->getMetaField($journal, $field); $result = $repository->getMetaField($journal, $field);
if (is_null($result)) { if (null === $result) {
return ''; return '';
} }
@@ -80,10 +80,10 @@ class TransactionJournal extends Twig_Extension
/** @var JournalRepositoryInterface $repository */ /** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class); $repository = app(JournalRepositoryInterface::class);
$result = $repository->getMetaField($journal, $field); $result = $repository->getMetaField($journal, $field);
if (is_null($result)) { if (null === $result) {
return false; return false;
} }
if (strlen(strval($result)) === 0) { if (strlen((string)$result) === 0) {
return false; return false;
} }
@@ -135,8 +135,7 @@ class TransactionJournal extends Twig_Extension
} }
$array[] = app('amount')->formatAnything($total['currency'], $total['amount']); $array[] = app('amount')->formatAnything($total['currency'], $total['amount']);
} }
$txt = join(' / ', $array);
return $txt; return join(' / ', $array);
} }
} }

View File

@@ -64,7 +64,7 @@ class Journal extends Twig_Extension
$array[] = sprintf('<a title="%1$s" href="%2$s">%1$s</a>', e($entry->name), route('accounts.show', $entry->id)); $array[] = sprintf('<a title="%1$s" href="%2$s">%1$s</a>', e($entry->name), route('accounts.show', $entry->id));
} }
$array = array_unique($array); $array = array_unique($array);
$result = join(', ', $array); $result = implode(', ', $array);
$cache->store($result); $cache->store($result);
return $result; return $result;
@@ -129,7 +129,7 @@ class Journal extends Twig_Extension
$array[] = sprintf('<a title="%1$s" href="%2$s">%1$s</a>', e($entry->name), route('accounts.show', $entry->id)); $array[] = sprintf('<a title="%1$s" href="%2$s">%1$s</a>', e($entry->name), route('accounts.show', $entry->id));
} }
$array = array_unique($array); $array = array_unique($array);
$result = join(', ', $array); $result = implode(', ', $array);
$cache->store($result); $cache->store($result);
return $result; return $result;
@@ -164,7 +164,7 @@ class Journal extends Twig_Extension
$budgets[] = sprintf('<a title="%1$s" href="%2$s">%1$s</a>', e($budget->name), route('budgets.show', $budget->id)); $budgets[] = sprintf('<a title="%1$s" href="%2$s">%1$s</a>', e($budget->name), route('budgets.show', $budget->id));
} }
} }
$string = join(', ', array_unique($budgets)); $string = implode(', ', array_unique($budgets));
$cache->store($string); $cache->store($string);
return $string; return $string;
@@ -205,7 +205,7 @@ class Journal extends Twig_Extension
} }
} }
$string = join(', ', array_unique($categories)); $string = implode(', ', array_unique($categories));
$cache->store($string); $cache->store($string);
return $string; return $string;

View File

@@ -52,7 +52,7 @@ class ClearNotes implements ActionInterface
* *
* @return bool * @return bool
* *
* @throws \Exception
*/ */
public function act(TransactionJournal $journal): bool public function act(TransactionJournal $journal): bool
{ {

View File

@@ -128,7 +128,7 @@ final class Processor
{ {
$self = new self; $self = new self;
foreach ($triggers as $entry) { foreach ($triggers as $entry) {
$entry['value'] = null === $entry['value'] ? '' : $entry['value']; $entry['value'] = $entry['value'] ?? '';
$trigger = TriggerFactory::makeTriggerFromStrings($entry['type'], $entry['value'], $entry['stopProcessing']); $trigger = TriggerFactory::makeTriggerFromStrings($entry['type'], $entry['value'], $entry['stopProcessing']);
$self->triggers->push($trigger); $self->triggers->push($trigger);
} }

View File

@@ -50,7 +50,7 @@ final class AmountMore extends AbstractTrigger implements TriggerInterface
public static function willMatchEverything($value = null) public static function willMatchEverything($value = null)
{ {
if (null !== $value) { if (null !== $value) {
$res = 0 === bccomp('0', strval($value)); $res = 0 === bccomp('0', (string)$value);
if (true === $res) { if (true === $res) {
Log::error(sprintf('Cannot use %s with a value equal to 0.', self::class)); Log::error(sprintf('Cannot use %s with a value equal to 0.', self::class));
} }

View File

@@ -49,7 +49,7 @@ final class DescriptionContains extends AbstractTrigger implements TriggerInterf
public static function willMatchEverything($value = null) public static function willMatchEverything($value = null)
{ {
if (null !== $value) { if (null !== $value) {
$res = '' === strval($value); $res = '' === (string)$value;
if (true === $res) { if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
} }

View File

@@ -49,7 +49,7 @@ final class DescriptionEnds extends AbstractTrigger implements TriggerInterface
public static function willMatchEverything($value = null) public static function willMatchEverything($value = null)
{ {
if (null !== $value) { if (null !== $value) {
$res = '' === strval($value); $res = '' === (string)$value;
if (true === $res) { if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
} }

View File

@@ -49,7 +49,7 @@ final class DescriptionStarts extends AbstractTrigger implements TriggerInterfac
public static function willMatchEverything($value = null) public static function willMatchEverything($value = null)
{ {
if (null !== $value) { if (null !== $value) {
$res = '' === strval($value); $res = '' === (string)$value;
if (true === $res) { if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
} }

View File

@@ -50,7 +50,7 @@ final class FromAccountContains extends AbstractTrigger implements TriggerInterf
public static function willMatchEverything($value = null) public static function willMatchEverything($value = null)
{ {
if (null !== $value) { if (null !== $value) {
$res = '' === strval($value); $res = '' === (string)$value;
if (true === $res) { if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
} }

View File

@@ -50,7 +50,7 @@ final class FromAccountEnds extends AbstractTrigger implements TriggerInterface
public static function willMatchEverything($value = null) public static function willMatchEverything($value = null)
{ {
if (null !== $value) { if (null !== $value) {
$res = '' === strval($value); $res = '' === (string)$value;
if (true === $res) { if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
} }

View File

@@ -50,7 +50,7 @@ final class FromAccountIs extends AbstractTrigger implements TriggerInterface
public static function willMatchEverything($value = null) public static function willMatchEverything($value = null)
{ {
if (null !== $value) { if (null !== $value) {
$res = '' === strval($value); $res = '' === (string)$value;
if (true === $res) { if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
} }

View File

@@ -50,7 +50,7 @@ final class FromAccountStarts extends AbstractTrigger implements TriggerInterfac
public static function willMatchEverything($value = null) public static function willMatchEverything($value = null)
{ {
if (null !== $value) { if (null !== $value) {
$res = '' === strval($value); $res = '' === (string)$value;
if (true === $res) { if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
} }

View File

@@ -48,12 +48,9 @@ class HasAttachment extends AbstractTrigger implements TriggerInterface
*/ */
public static function willMatchEverything($value = null) public static function willMatchEverything($value = null)
{ {
$value = intval($value); $value = (int)$value;
if ($value < 0) {
return true;
}
return false; return $value < 0;
} }
/** /**
@@ -65,7 +62,7 @@ class HasAttachment extends AbstractTrigger implements TriggerInterface
*/ */
public function triggered(TransactionJournal $journal): bool public function triggered(TransactionJournal $journal): bool
{ {
$minimum = intval($this->triggerValue); $minimum = (int)$this->triggerValue;
$attachments = $journal->attachments()->count(); $attachments = $journal->attachments()->count();
if ($attachments >= $minimum) { if ($attachments >= $minimum) {
Log::debug( Log::debug(

View File

@@ -50,7 +50,7 @@ final class NotesContain extends AbstractTrigger implements TriggerInterface
public static function willMatchEverything($value = null) public static function willMatchEverything($value = null)
{ {
if (null !== $value) { if (null !== $value) {
$res = '' === strval($value); $res = '' === (string)$value;
if (true === $res) { if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
} }

View File

@@ -50,7 +50,7 @@ final class NotesEnd extends AbstractTrigger implements TriggerInterface
public static function willMatchEverything($value = null) public static function willMatchEverything($value = null)
{ {
if (null !== $value) { if (null !== $value) {
$res = '' === strval($value); $res = '' === (string)$value;
if (true === $res) { if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
} }

View File

@@ -50,7 +50,7 @@ final class NotesStart extends AbstractTrigger implements TriggerInterface
public static function willMatchEverything($value = null) public static function willMatchEverything($value = null)
{ {
if (null !== $value) { if (null !== $value) {
$res = '' === strval($value); $res = '' === (string)$value;
if (true === $res) { if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
} }

View File

@@ -50,7 +50,7 @@ final class ToAccountContains extends AbstractTrigger implements TriggerInterfac
public static function willMatchEverything($value = null) public static function willMatchEverything($value = null)
{ {
if (null !== $value) { if (null !== $value) {
$res = '' === strval($value); $res = '' === (string)$value;
if (true === $res) { if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
} }

View File

@@ -50,7 +50,7 @@ final class ToAccountEnds extends AbstractTrigger implements TriggerInterface
public static function willMatchEverything($value = null) public static function willMatchEverything($value = null)
{ {
if (null !== $value) { if (null !== $value) {
$res = '' === strval($value); $res = '' === (string)$value;
if (true === $res) { if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
} }

View File

@@ -50,7 +50,7 @@ final class ToAccountIs extends AbstractTrigger implements TriggerInterface
public static function willMatchEverything($value = null) public static function willMatchEverything($value = null)
{ {
if (null !== $value) { if (null !== $value) {
$res = '' === strval($value); $res = '' === (string)$value;
if (true === $res) { if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
} }

View File

@@ -50,7 +50,7 @@ final class ToAccountStarts extends AbstractTrigger implements TriggerInterface
public static function willMatchEverything($value = null) public static function willMatchEverything($value = null)
{ {
if (null !== $value) { if (null !== $value) {
$res = '' === strval($value); $res = '' === (string)$value;
if (true === $res) { if (true === $res) {
Log::error(sprintf('Cannot use %s with "" as a value.', self::class)); Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
} }

View File

@@ -65,7 +65,7 @@ final class TransactionType extends AbstractTrigger implements TriggerInterface
*/ */
public function triggered(TransactionJournal $journal): bool public function triggered(TransactionJournal $journal): bool
{ {
$type = null !== $journal->transaction_type_type ? $journal->transaction_type_type : strtolower($journal->transactionType->type); $type = $journal->transaction_type_type ?? strtolower($journal->transactionType->type);
$search = strtolower($this->triggerValue); $search = strtolower($this->triggerValue);
if ($type === $search) { if ($type === $search) {

View File

@@ -101,7 +101,7 @@ class AccountTransformer extends TransformerAbstract
*/ */
public function includeTransactions(Account $account): FractalCollection public function includeTransactions(Account $account): FractalCollection
{ {
$pageSize = intval(app('preferences')->getForUser($account->user, 'listPageSize', 50)->data); $pageSize = (int)app('preferences')->getForUser($account->user, 'listPageSize', 50)->data;
// journals always use collector and limited using URL parameters. // journals always use collector and limited using URL parameters.
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -112,7 +112,7 @@ class AccountTransformer extends TransformerAbstract
} else { } else {
$collector->setOpposingAccounts(new Collection([$account])); $collector->setOpposingAccounts(new Collection([$account]));
} }
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) { if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); $collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
} }
$collector->setLimit($pageSize)->setPage($this->parameters->get('page')); $collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
@@ -151,7 +151,7 @@ class AccountTransformer extends TransformerAbstract
if (strlen($role) === 0 || $type !== AccountType::ASSET) { if (strlen($role) === 0 || $type !== AccountType::ASSET) {
$role = null; $role = null;
} }
$currencyId = intval($this->repository->getMetaValue($account, 'currency_id')); $currencyId = (int)$this->repository->getMetaValue($account, 'currency_id');
$currencyCode = null; $currencyCode = null;
$decimalPlaces = 2; $decimalPlaces = 2;
if ($currencyId > 0) { if ($currencyId > 0) {
@@ -161,7 +161,7 @@ class AccountTransformer extends TransformerAbstract
} }
$date = new Carbon; $date = new Carbon;
if (!is_null($this->parameters->get('date'))) { if (null !== $this->parameters->get('date')) {
$date = $this->parameters->get('date'); $date = $this->parameters->get('date');
} }
@@ -183,7 +183,7 @@ class AccountTransformer extends TransformerAbstract
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
$repository->setUser($account->user); $repository->setUser($account->user);
$amount = $repository->getOpeningBalanceAmount($account); $amount = $repository->getOpeningBalanceAmount($account);
$openingBalance = is_null($amount) ? null : round($amount, $decimalPlaces); $openingBalance = null === $amount ? null : round($amount, $decimalPlaces);
$openingBalanceDate = $repository->getOpeningBalanceDate($account); $openingBalanceDate = $repository->getOpeningBalanceDate($account);
} }
@@ -192,7 +192,7 @@ class AccountTransformer extends TransformerAbstract
'updated_at' => $account->updated_at->toAtomString(), 'updated_at' => $account->updated_at->toAtomString(),
'created_at' => $account->created_at->toAtomString(), 'created_at' => $account->created_at->toAtomString(),
'name' => $account->name, 'name' => $account->name,
'active' => intval($account->active) === 1, 'active' => (int)$account->active === 1,
'type' => $type, 'type' => $type,
'currency_id' => $currencyId, 'currency_id' => $currencyId,
'currency_code' => $currencyCode, 'currency_code' => $currencyCode,

View File

@@ -93,7 +93,7 @@ class BillTransformer extends TransformerAbstract
*/ */
public function includeTransactions(Bill $bill): FractalCollection public function includeTransactions(Bill $bill): FractalCollection
{ {
$pageSize = intval(app('preferences')->getForUser($bill->user, 'listPageSize', 50)->data); $pageSize = (int)app('preferences')->getForUser($bill->user, 'listPageSize', 50)->data;
// journals always use collector and limited using URL parameters. // journals always use collector and limited using URL parameters.
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -101,7 +101,7 @@ class BillTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation(); $collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setAllAssetAccounts(); $collector->setAllAssetAccounts();
$collector->setBills(new Collection([$bill])); $collector->setBills(new Collection([$bill]));
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) { if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); $collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
} }
$collector->setLimit($pageSize)->setPage($this->parameters->get('page')); $collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
@@ -145,8 +145,8 @@ class BillTransformer extends TransformerAbstract
'date' => $bill->date->format('Y-m-d'), 'date' => $bill->date->format('Y-m-d'),
'repeat_freq' => $bill->repeat_freq, 'repeat_freq' => $bill->repeat_freq,
'skip' => (int)$bill->skip, 'skip' => (int)$bill->skip,
'automatch' => intval($bill->automatch) === 1, 'automatch' => (int)$bill->automatch === 1,
'active' => intval($bill->active) === 1, 'active' => (int)$bill->active === 1,
'attachments_count' => $bill->attachments()->count(), 'attachments_count' => $bill->attachments()->count(),
'pay_dates' => $payDates, 'pay_dates' => $payDates,
'paid_dates' => $paidData['paid_dates'], 'paid_dates' => $paidData['paid_dates'],
@@ -161,7 +161,7 @@ class BillTransformer extends TransformerAbstract
]; ];
/** @var Note $note */ /** @var Note $note */
$note = $bill->notes()->first(); $note = $bill->notes()->first();
if (!is_null($note)) { if (null !== $note) {
$data['notes'] = $note->text; $data['notes'] = $note->text;
} }
@@ -222,7 +222,7 @@ class BillTransformer extends TransformerAbstract
protected function paidData(Bill $bill): array protected function paidData(Bill $bill): array
{ {
Log::debug(sprintf('Now in paidData for bill #%d', $bill->id)); Log::debug(sprintf('Now in paidData for bill #%d', $bill->id));
if (is_null($this->parameters->get('start')) || is_null($this->parameters->get('end'))) { if (null === $this->parameters->get('start') || null === $this->parameters->get('end')) {
Log::debug('parameters are NULL, return empty array'); Log::debug('parameters are NULL, return empty array');
return [ return [
@@ -267,7 +267,7 @@ class BillTransformer extends TransformerAbstract
*/ */
protected function payDates(Bill $bill): array protected function payDates(Bill $bill): array
{ {
if (is_null($this->parameters->get('start')) || is_null($this->parameters->get('end'))) { if (null === $this->parameters->get('start') || null === $this->parameters->get('end')) {
return []; return [];
} }
$set = new Collection; $set = new Collection;

View File

@@ -75,7 +75,7 @@ class BudgetTransformer extends TransformerAbstract
*/ */
public function includeTransactions(Budget $budget): FractalCollection public function includeTransactions(Budget $budget): FractalCollection
{ {
$pageSize = intval(app('preferences')->getForUser($budget->user, 'listPageSize', 50)->data); $pageSize = (int)app('preferences')->getForUser($budget->user, 'listPageSize', 50)->data;
// journals always use collector and limited using URL parameters. // journals always use collector and limited using URL parameters.
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -83,7 +83,7 @@ class BudgetTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation(); $collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setAllAssetAccounts(); $collector->setAllAssetAccounts();
$collector->setBudgets(new Collection([$budget])); $collector->setBudgets(new Collection([$budget]));
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) { if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); $collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
} }
$collector->setLimit($pageSize)->setPage($this->parameters->get('page')); $collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
@@ -118,7 +118,7 @@ class BudgetTransformer extends TransformerAbstract
'id' => (int)$budget->id, 'id' => (int)$budget->id,
'updated_at' => $budget->updated_at->toAtomString(), 'updated_at' => $budget->updated_at->toAtomString(),
'created_at' => $budget->created_at->toAtomString(), 'created_at' => $budget->created_at->toAtomString(),
'active' => intval($budget->active) === 1, 'active' => (int)$budget->active === 1,
'name' => $budget->name, 'name' => $budget->name,
'links' => [ 'links' => [
[ [

View File

@@ -75,7 +75,7 @@ class CategoryTransformer extends TransformerAbstract
*/ */
public function includeTransactions(Category $category): FractalCollection public function includeTransactions(Category $category): FractalCollection
{ {
$pageSize = intval(app('preferences')->getForUser($category->user, 'listPageSize', 50)->data); $pageSize = (int)app('preferences')->getForUser($category->user, 'listPageSize', 50)->data;
// journals always use collector and limited using URL parameters. // journals always use collector and limited using URL parameters.
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -83,7 +83,7 @@ class CategoryTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation(); $collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
$collector->setAllAssetAccounts(); $collector->setAllAssetAccounts();
$collector->setCategories(new Collection([$category])); $collector->setCategories(new Collection([$category]));
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) { if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); $collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
} }
$collector->setLimit($pageSize)->setPage($this->parameters->get('page')); $collector->setLimit($pageSize)->setPage($this->parameters->get('page'));

View File

@@ -75,7 +75,7 @@ class JournalMetaTransformer extends TransformerAbstract
public function includeTransactions(TransactionJournalMeta $meta): FractalCollection public function includeTransactions(TransactionJournalMeta $meta): FractalCollection
{ {
$journal = $meta->transactionJournal; $journal = $meta->transactionJournal;
$pageSize = intval(app('preferences')->getForUser($journal->user, 'listPageSize', 50)->data); $pageSize = (int)app('preferences')->getForUser($journal->user, 'listPageSize', 50)->data;
// journals always use collector and limited using URL parameters. // journals always use collector and limited using URL parameters.
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -83,7 +83,7 @@ class JournalMetaTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation(); $collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
$collector->setAllAssetAccounts(); $collector->setAllAssetAccounts();
$collector->setJournals(new Collection([$journal])); $collector->setJournals(new Collection([$journal]));
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) { if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); $collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
} }
$collector->setLimit($pageSize)->setPage($this->parameters->get('page')); $collector->setLimit($pageSize)->setPage($this->parameters->get('page'));

View File

@@ -91,7 +91,7 @@ class PiggyBankEventTransformer extends TransformerAbstract
public function includeTransaction(PiggyBankEvent $event): Item public function includeTransaction(PiggyBankEvent $event): Item
{ {
$journal = $event->transactionJournal; $journal = $event->transactionJournal;
$pageSize = intval(app('preferences')->getForUser($journal->user, 'listPageSize', 50)->data); $pageSize = (int)app('preferences')->getForUser($journal->user, 'listPageSize', 50)->data;
// journals always use collector and limited using URL parameters. // journals always use collector and limited using URL parameters.
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -99,7 +99,7 @@ class PiggyBankEventTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation(); $collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
$collector->setAllAssetAccounts(); $collector->setAllAssetAccounts();
$collector->setJournals(new Collection([$journal])); $collector->setJournals(new Collection([$journal]));
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) { if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); $collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
} }
$collector->setLimit($pageSize)->setPage($this->parameters->get('page')); $collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
@@ -118,7 +118,7 @@ class PiggyBankEventTransformer extends TransformerAbstract
public function transform(PiggyBankEvent $event): array public function transform(PiggyBankEvent $event): array
{ {
$account = $event->piggyBank->account; $account = $event->piggyBank->account;
$currencyId = intval($account->getMeta('currency_id')); $currencyId = (int)$account->getMeta('currency_id');
$decimalPlaces = 2; $decimalPlaces = 2;
if ($currencyId > 0) { if ($currencyId > 0) {
/** @var CurrencyRepositoryInterface $repository */ /** @var CurrencyRepositoryInterface $repository */

View File

@@ -117,7 +117,7 @@ class PiggyBankTransformer extends TransformerAbstract
public function transform(PiggyBank $piggyBank): array public function transform(PiggyBank $piggyBank): array
{ {
$account = $piggyBank->account; $account = $piggyBank->account;
$currencyId = intval($account->getMeta('currency_id')); $currencyId = (int)$account->getMeta('currency_id');
$decimalPlaces = 2; $decimalPlaces = 2;
if ($currencyId > 0) { if ($currencyId > 0) {
/** @var CurrencyRepositoryInterface $repository */ /** @var CurrencyRepositoryInterface $repository */
@@ -133,8 +133,8 @@ class PiggyBankTransformer extends TransformerAbstract
$piggyRepos->setUser($account->user); $piggyRepos->setUser($account->user);
$currentAmount = round($piggyRepos->getCurrentAmount($piggyBank), $decimalPlaces); $currentAmount = round($piggyRepos->getCurrentAmount($piggyBank), $decimalPlaces);
$startDate = is_null($piggyBank->startdate) ? null : $piggyBank->startdate->format('Y-m-d'); $startDate = null === $piggyBank->startdate ? null : $piggyBank->startdate->format('Y-m-d');
$targetDate = is_null($piggyBank->targetdate) ? null : $piggyBank->targetdate->format('Y-m-d'); $targetDate = null === $piggyBank->targetdate ? null : $piggyBank->targetdate->format('Y-m-d');
$targetAmount = round($piggyBank->targetamount, $decimalPlaces); $targetAmount = round($piggyBank->targetamount, $decimalPlaces);
$data = [ $data = [
'id' => (int)$piggyBank->id, 'id' => (int)$piggyBank->id,
@@ -146,7 +146,7 @@ class PiggyBankTransformer extends TransformerAbstract
'startdate' => $startDate, 'startdate' => $startDate,
'targetdate' => $targetDate, 'targetdate' => $targetDate,
'order' => (int)$piggyBank->order, 'order' => (int)$piggyBank->order,
'active' => intval($piggyBank->active) === 1, 'active' => (int)$piggyBank->active === 1,
'notes' => null, 'notes' => null,
'links' => [ 'links' => [
[ [
@@ -157,7 +157,7 @@ class PiggyBankTransformer extends TransformerAbstract
]; ];
/** @var Note $note */ /** @var Note $note */
$note = $piggyBank->notes()->first(); $note = $piggyBank->notes()->first();
if (!is_null($note)) { if (null !== $note) {
$data['notes'] = $note->text; $data['notes'] = $note->text;
} }

View File

@@ -74,7 +74,7 @@ class TagTransformer extends TransformerAbstract
*/ */
public function includeTransactions(Tag $tag): FractalCollection public function includeTransactions(Tag $tag): FractalCollection
{ {
$pageSize = intval(app('preferences')->getForUser($tag->user, 'listPageSize', 50)->data); $pageSize = (int)app('preferences')->getForUser($tag->user, 'listPageSize', 50)->data;
// journals always use collector and limited using URL parameters. // journals always use collector and limited using URL parameters.
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -82,7 +82,7 @@ class TagTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation(); $collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
$collector->setAllAssetAccounts(); $collector->setAllAssetAccounts();
$collector->setTag($tag); $collector->setTag($tag);
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) { if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); $collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
} }
$collector->setLimit($pageSize)->setPage($this->parameters->get('page')); $collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
@@ -113,7 +113,7 @@ class TagTransformer extends TransformerAbstract
*/ */
public function transform(Tag $tag): array public function transform(Tag $tag): array
{ {
$date = is_null($tag->date) ? null : $tag->date->format('Y-m-d'); $date = null === $tag->date ? null : $tag->date->format('Y-m-d');
$data = [ $data = [
'id' => (int)$tag->id, 'id' => (int)$tag->id,
'updated_at' => $tag->updated_at->toAtomString(), 'updated_at' => $tag->updated_at->toAtomString(),

View File

@@ -157,21 +157,21 @@ class TransactionTransformer extends TransformerAbstract
$categoryName = null; $categoryName = null;
$budgetId = null; $budgetId = null;
$budgetName = null; $budgetName = null;
$categoryId = is_null($transaction->transaction_category_id) ? $transaction->transaction_journal_category_id $categoryId = null === $transaction->transaction_category_id ? $transaction->transaction_journal_category_id
: $transaction->transaction_category_id; : $transaction->transaction_category_id;
$categoryName = is_null($transaction->transaction_category_name) ? $transaction->transaction_journal_category_name $categoryName = null === $transaction->transaction_category_name ? $transaction->transaction_journal_category_name
: $transaction->transaction_category_name; : $transaction->transaction_category_name;
if ($transaction->transaction_type_type === TransactionType::WITHDRAWAL) { if ($transaction->transaction_type_type === TransactionType::WITHDRAWAL) {
$budgetId = is_null($transaction->transaction_budget_id) ? $transaction->transaction_journal_budget_id $budgetId = null === $transaction->transaction_budget_id ? $transaction->transaction_journal_budget_id
: $transaction->transaction_budget_id; : $transaction->transaction_budget_id;
$budgetName = is_null($transaction->transaction_budget_name) ? $transaction->transaction_journal_budget_name $budgetName = null === $transaction->transaction_budget_name ? $transaction->transaction_journal_budget_name
: $transaction->transaction_budget_name; : $transaction->transaction_budget_name;
} }
/** @var Note $dbNote */ /** @var Note $dbNote */
$dbNote = $transaction->transactionJournal->notes()->first(); $dbNote = $transaction->transactionJournal->notes()->first();
$notes = null; $notes = null;
if (!is_null($dbNote)) { if (null !== $dbNote) {
$notes = $dbNote->text; $notes = $dbNote->text;
} }
@@ -186,7 +186,7 @@ class TransactionTransformer extends TransformerAbstract
'identifier' => $transaction->identifier, 'identifier' => $transaction->identifier,
'journal_id' => (int)$transaction->journal_id, 'journal_id' => (int)$transaction->journal_id,
'reconciled' => (bool)$transaction->reconciled, 'reconciled' => (bool)$transaction->reconciled,
'amount' => round($transaction->transaction_amount, intval($transaction->transaction_currency_dp)), 'amount' => round($transaction->transaction_amount, (int)$transaction->transaction_currency_dp),
'currency_id' => $transaction->transaction_currency_id, 'currency_id' => $transaction->transaction_currency_id,
'currency_code' => $transaction->transaction_currency_code, 'currency_code' => $transaction->transaction_currency_code,
'currency_symbol' => $transaction->transaction_currency_symbol, 'currency_symbol' => $transaction->transaction_currency_symbol,
@@ -212,8 +212,8 @@ class TransactionTransformer extends TransformerAbstract
]; ];
// expand foreign amount: // expand foreign amount:
if (!is_null($transaction->transaction_foreign_amount)) { if (null !== $transaction->transaction_foreign_amount) {
$data['foreign_amount'] = round($transaction->transaction_foreign_amount, intval($transaction->foreign_currency_dp)); $data['foreign_amount'] = round($transaction->transaction_foreign_amount, (int)$transaction->foreign_currency_dp);
} }
// switch on type for consistency // switch on type for consistency
@@ -251,7 +251,7 @@ class TransactionTransformer extends TransformerAbstract
} }
// expand description. // expand description.
if (strlen(strval($transaction->transaction_description)) > 0) { if (strlen((string)$transaction->transaction_description) > 0) {
$data['description'] = $transaction->transaction_description . ' (' . $transaction->description . ')'; $data['description'] = $transaction->transaction_description . ' (' . $transaction->description . ')';
} }

View File

@@ -184,7 +184,7 @@ class UserTransformer extends TransformerAbstract
{ {
/** @var Role $role */ /** @var Role $role */
$role = $user->roles()->first(); $role = $user->roles()->first();
if (!is_null($role)) { if (null !== $role) {
$role = $role->name; $role = $role->name;
} }
@@ -193,7 +193,7 @@ class UserTransformer extends TransformerAbstract
'updated_at' => $user->updated_at->toAtomString(), 'updated_at' => $user->updated_at->toAtomString(),
'created_at' => $user->created_at->toAtomString(), 'created_at' => $user->created_at->toAtomString(),
'email' => $user->email, 'email' => $user->email,
'blocked' => intval($user->blocked) === 1, 'blocked' => (int)$user->blocked === 1,
'blocked_code' => $user->blocked_code, 'blocked_code' => $user->blocked_code,
'role' => $role, 'role' => $role,
'links' => [ 'links' => [

View File

@@ -37,7 +37,6 @@ use FireflyIII\TransactionRules\Triggers\TriggerInterface;
use FireflyIII\User; use FireflyIII\User;
use Google2FA; use Google2FA;
use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Contracts\Translation\Translator;
use Illuminate\Validation\Validator; use Illuminate\Validation\Validator;
/** /**
@@ -45,18 +44,6 @@ use Illuminate\Validation\Validator;
*/ */
class FireflyValidator extends Validator class FireflyValidator extends Validator
{ {
/**
* @param Translator $translator
* @param array $data
* @param array $rules
* @param array $messages
* @param array $customAttributes
*/
public function __construct(Translator $translator, array $data, array $rules, array $messages = [], array $customAttributes = [])
{
parent::__construct($translator, $data, $rules, $messages, $customAttributes);
}
/** /**
* @SuppressWarnings(PHPMD.UnusedFormalParameter) * @SuppressWarnings(PHPMD.UnusedFormalParameter)
* *
@@ -89,7 +76,7 @@ class FireflyValidator extends Validator
{ {
$field = $parameters[1] ?? 'id'; $field = $parameters[1] ?? 'id';
if (0 === intval($value)) { if (0 === (int)$value) {
return true; return true;
} }
$count = DB::table($parameters[0])->where('user_id', auth()->user()->id)->where($field, $value)->count(); $count = DB::table($parameters[0])->where('user_id', auth()->user()->id)->where($field, $value)->count();
@@ -196,7 +183,7 @@ class FireflyValidator extends Validator
$iban = str_replace($search, $replace, $iban); $iban = str_replace($search, $replace, $iban);
$checksum = bcmod($iban, '97'); $checksum = bcmod($iban, '97');
return 1 === intval($checksum); return 1 === (int)$checksum;
} }
/** /**
@@ -209,9 +196,9 @@ class FireflyValidator extends Validator
*/ */
public function validateMore($attribute, $value, $parameters): bool public function validateMore($attribute, $value, $parameters): bool
{ {
$compare = strval($parameters[0] ?? '0'); $compare = (string)$parameters[0] ?? '0';
return bccomp(strval($value), $compare) > 0; return bccomp((string)$value, $compare) > 0;
} }
/** /**
@@ -227,7 +214,7 @@ class FireflyValidator extends Validator
{ {
$field = $parameters[1] ?? 'id'; $field = $parameters[1] ?? 'id';
if (0 === intval($value)) { if (0 === (int)$value) {
return true; return true;
} }
$count = DB::table($parameters[0])->where($field, $value)->count(); $count = DB::table($parameters[0])->where($field, $value)->count();
@@ -333,7 +320,7 @@ class FireflyValidator extends Validator
{ {
$verify = false; $verify = false;
if (isset($this->data['verify_password'])) { if (isset($this->data['verify_password'])) {
$verify = 1 === intval($this->data['verify_password']); $verify = 1 === (int)$this->data['verify_password'];
} }
if ($verify) { if ($verify) {
/** @var Verifier $service */ /** @var Verifier $service */
@@ -389,9 +376,9 @@ class FireflyValidator extends Validator
*/ */
public function validateUniqueAccountNumberForUser($attribute, $value, $parameters): bool public function validateUniqueAccountNumberForUser($attribute, $value, $parameters): bool
{ {
$accountId = $this->data['id'] ?? 0; $accountId = (int)($this->data['id'] ?? 0.0);
if ($accountId === 0) { if ($accountId === 0) {
$accountId = $parameters[0] ?? 0; $accountId = (int)($parameters[0] ?? 0.0);
} }
$query = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id') $query = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
@@ -399,9 +386,9 @@ class FireflyValidator extends Validator
->where('accounts.user_id', auth()->user()->id) ->where('accounts.user_id', auth()->user()->id)
->where('account_meta.name', 'accountNumber'); ->where('account_meta.name', 'accountNumber');
if (intval($accountId) > 0) { if ((int)$accountId > 0) {
// exclude current account from check. // exclude current account from check.
$query->where('account_meta.account_id', '!=', intval($accountId)); $query->where('account_meta.account_id', '!=', (int)$accountId);
} }
$set = $query->get(['account_meta.*']); $set = $query->get(['account_meta.*']);
@@ -435,15 +422,15 @@ class FireflyValidator extends Validator
// exclude? // exclude?
$table = $parameters[0]; $table = $parameters[0];
$field = $parameters[1]; $field = $parameters[1];
$exclude = $parameters[2] ?? 0; $exclude = (int)($parameters[2] ?? 0.0);
/* /*
* If other data (in $this->getData()) contains * If other data (in $this->getData()) contains
* ID field, set that field to be the $exclude. * ID field, set that field to be the $exclude.
*/ */
$data = $this->getData(); $data = $this->getData();
if (!isset($parameters[2]) && isset($data['id']) && intval($data['id']) > 0) { if (!isset($parameters[2]) && isset($data['id']) && (int)$data['id'] > 0) {
$exclude = intval($data['id']); $exclude = (int)$data['id'];
} }
@@ -586,7 +573,7 @@ class FireflyValidator extends Validator
private function validateByAccountTypeId($value, $parameters): bool private function validateByAccountTypeId($value, $parameters): bool
{ {
$type = AccountType::find($this->data['account_type_id'])->first(); $type = AccountType::find($this->data['account_type_id'])->first();
$ignore = $parameters[0] ?? 0; $ignore = (int)($parameters[0] ?? 0.0);
$value = $this->tryDecrypt($value); $value = $this->tryDecrypt($value);
$set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get(); $set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get();
@@ -611,7 +598,7 @@ class FireflyValidator extends Validator
{ {
$search = Config::get('firefly.accountTypeByIdentifier.' . $type); $search = Config::get('firefly.accountTypeByIdentifier.' . $type);
$accountType = AccountType::whereType($search)->first(); $accountType = AccountType::whereType($search)->first();
$ignore = $parameters[0] ?? 0; $ignore = (int)($parameters[0] ?? 0.0);
$set = auth()->user()->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $ignore)->get(); $set = auth()->user()->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $ignore)->get();
/** @var Account $entry */ /** @var Account $entry */