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
*
* @throws \Exception
*/
public function destroy(Tag $tag): bool
{
@@ -98,9 +98,8 @@ class TagRepository implements TagRepositoryInterface
$collector->setUser($this->user);
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setAllAssetAccounts()->setTag($tag);
$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->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setAllAssetAccounts()->setTag($tag);
$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();
$sum = '0';
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) {
$amount = app('steam')->positive(strval($journal->transaction_amount));
$amount = app('steam')->positive((string)$journal->transaction_amount);
$type = $journal->transaction_type_type;
if (TransactionType::WITHDRAWAL === $type) {
$amount = bcmul($amount, '-1');
@@ -350,7 +348,7 @@ class TagRepository implements TagRepositoryInterface
$tagsWithAmounts = [];
/** @var Tag $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']);
@@ -431,8 +429,8 @@ class TagRepository implements TagRepositoryInterface
$step = 1;
}
$extra = $step / $amount;
$result = (int)($range[0] + $extra);
return $result;
$extra = $step / $amount;
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);
// set undo and confirm token:
Preferences::setForUser($user, 'email_change_undo_token', strval(bin2hex(random_bytes(16))));
Preferences::setForUser($user, 'email_change_confirm_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', (string)bin2hex(random_bytes(16)));
// update user
$user->email = $newEmail;
@@ -145,7 +145,7 @@ class UserRepository implements UserRepositoryInterface
*
* @return bool
*
* @throws \Exception
*/
public function destroy(User $user): bool
{
@@ -231,7 +231,7 @@ class UserRepository implements UserRepositoryInterface
}
$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['accounts'] = $user->accounts()->count();
$return['journals'] = $user->transactionJournals()->count();

View File

@@ -103,17 +103,12 @@ interface UserRepositoryInterface
/**
* @param int $userId
*
* @deprecated
* @return User
*/
public function find(int $userId): User;
/**
* @param int $userId
* @return User|null
*/
public function findNull(int $userId): ?User;
/**
* @param string $email
*
@@ -121,6 +116,13 @@ interface UserRepositoryInterface
*/
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.
*

View File

@@ -72,11 +72,11 @@ class BelongsUser implements Rule
if (!auth()->check()) {
return true; // @codeCoverageIgnore
}
$attribute = strval($attribute);
$attribute = (string)$attribute;
switch ($attribute) {
case 'piggy_bank_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();
return $count === 1;
@@ -87,7 +87,7 @@ class BelongsUser implements Rule
return $count === 1;
break;
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;
case 'bill_name':
@@ -96,12 +96,12 @@ class BelongsUser implements Rule
return $count === 1;
break;
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;
break;
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;
break;
@@ -112,7 +112,7 @@ class BelongsUser implements Rule
break;
case 'source_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;
break;
@@ -143,7 +143,7 @@ class BelongsUser implements Rule
}
$count = 0;
foreach ($objects as $object) {
if (trim(strval($object->$field)) === trim($value)) {
if (trim((string)$object->$field) === trim($value)) {
$count++;
}
}

View File

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

View File

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

View File

@@ -27,13 +27,4 @@ namespace FireflyIII\Services\Bunq\Id;
*/
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
{
/** @var string */
private $name = '';
private $name;
/** @var string */
private $type = '';
private $type;
/** @var string */
private $value = '';
private $value;
/**
* Alias constructor.

View File

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

View File

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

View File

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

View File

@@ -40,6 +40,20 @@ class LabelUser extends BunqObject
/** @var string */
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
*/
@@ -64,22 +78,6 @@ class LabelUser extends BunqObject
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
*/

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -127,11 +127,10 @@ trait AccountServiceTrait
* @param array $data
*
* @return TransactionJournal|null
* @throws \FireflyIII\Exceptions\FireflyException
*/
public function storeIBJournal(Account $account, array $data): ?TransactionJournal
{
$amount = strval($data['openingBalance']);
$amount = (string)$data['openingBalance'];
Log::debug(sprintf('Submitted amount is %s', $amount));
if (0 === bccomp($amount, '0')) {
@@ -145,7 +144,7 @@ trait AccountServiceTrait
'type' => TransactionType::OPENING_BALANCE,
'user' => $account->user->id,
'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,
'date' => $data['openingBalanceDate'],
'bill_id' => null,
@@ -232,7 +231,6 @@ trait AccountServiceTrait
* @param array $data
*
* @return bool
* @throws \FireflyIII\Exceptions\FireflyException
*/
public function updateIB(Account $account, array $data): bool
{
@@ -268,9 +266,9 @@ trait AccountServiceTrait
public function updateIBJournal(Account $account, TransactionJournal $journal, array $data): bool
{
$date = $data['openingBalanceDate'];
$amount = strval($data['openingBalance']);
$amount = (string)$data['openingBalance'];
$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));
if (0 === bccomp($amount, '0')) {
@@ -291,13 +289,13 @@ trait AccountServiceTrait
// update transactions:
/** @var Transaction $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));
$transaction->amount = $amount;
$transaction->transaction_currency_id = $currencyId;
$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));
$transaction->amount = $negativeAmount;
$transaction->transaction_currency_id = $currencyId;
@@ -383,9 +381,8 @@ trait AccountServiceTrait
*/
public function validIBData(array $data): bool
{
$data['openingBalance'] = strval($data['openingBalance'] ?? '');
if (isset($data['openingBalance']) && null !== $data['openingBalance'] && strlen($data['openingBalance']) > 0
&& isset($data['openingBalanceDate'])) {
$data['openingBalance'] = (string)($data['openingBalance'] ?? '');
if (isset($data['openingBalance'], $data['openingBalanceDate']) && \strlen($data['openingBalance']) > 0) {
Log::debug('Array has valid opening balance data.');
return true;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -22,9 +22,9 @@ declare(strict_types=1);
namespace FireflyIII\Services\Password;
use Exception;
use Log;
use Requests;
use Requests_Exception;
/**
* Class PwndVerifier.
@@ -46,7 +46,7 @@ class PwndVerifier implements Verifier
try {
$result = Requests::get($uri, ['originalPasswordIsAHash' => 'true'], $opt);
} catch (Requests_Exception $e) {
} catch (Exception $e) {
return true;
}
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;
use Exception;
use Log;
use Requests;
use Requests_Exception;
/**
* Class PwndVerifierV2.
@@ -51,7 +51,7 @@ class PwndVerifierV2 implements Verifier
try {
$result = Requests::get($uri, $opt);
} catch (Requests_Exception $e) {
} catch (Exception $e) {
return true;
}
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)
{
$this->id = intval($data['id']);
$this->id = (int)$data['id'];
$this->identifier = $data['identifier'];
$this->secret = $data['secret'];
}

View File

@@ -84,7 +84,7 @@ class Transaction extends SpectreObject
*/
public function getAmount(): string
{
return strval($this->amount);
return (string)$this->amount;
}
/**
@@ -124,7 +124,7 @@ class Transaction extends SpectreObject
*/
public function getHash(): string
{
$array = [
$array = [
'id' => $this->id,
'mode' => $this->mode,
'status' => $this->status,
@@ -139,9 +139,8 @@ class Transaction extends SpectreObject
'created_at' => $this->createdAt->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,
'record_number' => $this->recordNumber,
'information' => $this->information,
'time' => is_null($this->time) ? null : $this->time->toIso8601String(),
'posting_date' => is_null($this->postingDate) ? null : $this->postingDate->toIso8601String(),
'posting_time' => is_null($this->postingTime) ? null : $this->postingTime->toIso8601String(),
'time' => null === $this->time ? null : $this->time->toIso8601String(),
'posting_date' => null === $this->postingDate ? null : $this->postingDate->toIso8601String(),
'posting_time' => null === $this->postingTime ? null : $this->postingTime->toIso8601String(),
'account_number' => $this->accountNumber,
'original_amount' => $this->originalAmount,
'original_currency_code' => $this->originalCurrencyCode,

View File

@@ -58,7 +58,7 @@ class ListAccountsRequest extends SpectreRequest
// extract next ID
$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;
$nextId = $response['meta']['next_id'];
Log::debug(sprintf('Next ID is now %d.', $nextId));

View File

@@ -55,7 +55,7 @@ class ListCustomersRequest extends SpectreRequest
// extract next ID
$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;
$nextId = $response['meta']['next_id'];
Log::debug(sprintf('Next ID is now %d.', $nextId));

View File

@@ -58,7 +58,7 @@ class ListLoginsRequest extends SpectreRequest
// extract next ID
$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;
$nextId = $response['meta']['next_id'];
Log::debug(sprintf('Next ID is now %d.', $nextId));

View File

@@ -58,7 +58,7 @@ class ListTransactionsRequest extends SpectreRequest
// extract next ID
$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;
$nextId = $response['meta']['next_id'];
Log::debug(sprintf('Next ID is now %d.', $nextId));

View File

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

View File

@@ -123,7 +123,7 @@ class Amount
setlocale(LC_MONETARY, $locale);
$float = round($amount, 12);
$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:
$precedes = $amount < 0 ? $info['n_cs_precedes'] : $info['p_cs_precedes'];

View File

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

View File

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

View File

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

View File

@@ -44,7 +44,7 @@ class JournalList implements BinderInterface
$list = [];
$incoming = explode(',', $value);
foreach ($incoming as $entry) {
$list[] = intval($entry);
$list[] = (int)$entry;
}
$list = array_unique($list);
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')
->where('completed', 0)
->where('user_id', auth()->user()->id)->first(['transaction_journals.*']);
if (!is_null($journal)) {
if (null !== $journal) {
return $journal;
}
}

View File

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

View File

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

View File

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

View File

@@ -102,7 +102,7 @@ class Initial implements ConfigurationInterface
Log::debug('Now in storeConfiguration for file Upload.');
$config = $this->getConfig();
$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:
$this->repository->setConfiguration($this->job, $config);
@@ -118,7 +118,7 @@ class Initial implements ConfigurationInterface
}
if (false === $uploaded) {
$this->warning = 'No valid upload.';
$this->warning = (string)trans('firefly.upload_error');
return true;
}

View File

@@ -159,12 +159,12 @@ class Map implements ConfigurationInterface
$config = $this->getConfig();
if (isset($data['mapping'])) {
foreach ($data['mapping'] as $index => $data) {
foreach ($data['mapping'] as $index => $array) {
$config['column-mapping-config'][$index] = [];
foreach ($data as $value => $mapId) {
$mapId = intval($mapId);
foreach ($array as $value => $mapId) {
$mapId = (int)$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');
$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:
$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:
$roles = $this->getRoles();
asort($roles);
@@ -274,14 +274,14 @@ class Roles implements ConfigurationInterface
}
// warn if has foreign amount but no currency code:
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.');
return false;
}
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.');
return false;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -166,11 +166,11 @@ class Modifier
{
$journalBudget = '';
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 = '';
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);
@@ -186,11 +186,11 @@ class Modifier
{
$journalCategory = '';
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 = '';
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);

View File

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

View File

@@ -51,32 +51,28 @@ class Steam
if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore
}
$currencyId = intval($account->getMeta('currency_id'));
$currencyId = (int)$account->getMeta('currency_id');
// use system default currency:
if (0 === $currencyId) {
$currency = app('amount')->getDefaultCurrencyByUser($account->user);
$currencyId = $currency->id;
}
// first part: get all balances in own currency:
$nativeBalance = strval(
$account->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.transaction_currency_id', $currencyId)
->sum('transactions.amount')
);
$nativeBalance = (string)$account->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.transaction_currency_id', $currencyId)
->sum('transactions.amount');
// get all balances in foreign currency:
$foreignBalance = strval(
$account->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->where('transactions.foreign_currency_id', $currencyId)
->where('transactions.transaction_currency_id', '!=', $currencyId)
->sum('transactions.foreign_amount')
);
$foreignBalance = (string)$account->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->where('transactions.foreign_currency_id', $currencyId)
->where('transactions.transaction_currency_id', '!=', $currencyId)
->sum('transactions.foreign_amount');
$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);
$cache->store($balance);
@@ -99,25 +95,21 @@ class Steam
if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore
}
$currencyId = intval($account->getMeta('currency_id'));
$currencyId = (int)$account->getMeta('currency_id');
$nativeBalance = strval(
$account->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->where('transactions.transaction_currency_id', $currencyId)
->sum('transactions.amount')
);
$nativeBalance = (string)$account->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->where('transactions.transaction_currency_id', $currencyId)
->sum('transactions.amount');
// get all balances in foreign currency:
$foreignBalance = strval(
$account->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->where('transactions.foreign_currency_id', $currencyId)
->where('transactions.transaction_currency_id', '!=', $currencyId)
->sum('transactions.foreign_amount')
);
$foreignBalance = (string)$account->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
->where('transactions.foreign_currency_id', $currencyId)
->where('transactions.transaction_currency_id', '!=', $currencyId)
->sum('transactions.foreign_amount');
$balance = bcadd($nativeBalance, $foreignBalance);
$cache->store($balance);
@@ -155,7 +147,7 @@ class Steam
$startBalance = $this->balance($account, $start);
$balances[$formatted] = $startBalance;
$currencyId = intval($account->getMeta('currency_id'));
$currencyId = (int)$account->getMeta('currency_id');
$start->addDay();
// query!
@@ -182,14 +174,14 @@ class Steam
/** @var Transaction $entry */
foreach ($set as $entry) {
// normal amount and foreign amount
$modified = null === $entry->modified ? '0' : strval($entry->modified);
$foreignModified = null === $entry->modified_foreign ? '0' : strval($entry->modified_foreign);
$modified = null === $entry->modified ? '0' : (string)$entry->modified;
$foreignModified = null === $entry->modified_foreign ? '0' : (string)$entry->modified_foreign;
$amount = '0';
if ($currencyId === intval($entry->transaction_currency_id) || 0 === $currencyId) {
if ($currencyId === (int)$entry->transaction_currency_id || 0 === $currencyId) {
// use normal amount:
$amount = $modified;
}
if ($currencyId === intval($entry->foreign_currency_id)) {
if ($currencyId === (int)$entry->foreign_currency_id) {
// use foreign amount:
$amount = $foreignModified;
}
@@ -268,7 +260,7 @@ class Steam
->get(['transactions.account_id', DB::raw('MAX(transaction_journals.date) AS max_date')]);
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;
@@ -295,7 +287,7 @@ class Steam
*/
public function opposite(string $amount = null): ?string
{
if (is_null($amount)) {
if (null === $amount) {
return null;
}
$amount = bcmul($amount, '-1');
@@ -316,24 +308,24 @@ class Steam
// has a K in it, remove the K and multiply by 1024.
$bytes = bcmul(rtrim($string, 'kK'), '1024');
return intval($bytes);
return (int)$bytes;
}
if (!(false === stripos($string, 'm'))) {
// has a M in it, remove the M and multiply by 1048576.
$bytes = bcmul(rtrim($string, 'mM'), '1048576');
return intval($bytes);
return (int)$bytes;
}
if (!(false === stripos($string, 'g'))) {
// has a G in it, remove the G and multiply by (1024)^3.
$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
{
$amount = bcmul(app('steam')->positive(strval($transaction->transaction_amount)), '-1');
$amount = bcmul(app('steam')->positive((string)$transaction->transaction_amount), '-1');
$format = '%s';
$coloured = true;
// 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');
}
@@ -64,7 +64,7 @@ class Transaction extends Twig_Extension
$format = '<span class="text-info">%s</span>';
}
if (TransactionType::OPENING_BALANCE === $transaction->transaction_type_type) {
$amount = strval($transaction->transaction_amount);
$amount = (string)$transaction->transaction_amount;
}
$currency = new TransactionCurrency;
@@ -73,7 +73,7 @@ class Transaction extends Twig_Extension
$str = sprintf($format, app('amount')->formatAnything($currency, $amount, $coloured));
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) {
$amount = bcmul($amount, '-1');
}
@@ -101,7 +101,7 @@ class Transaction extends Twig_Extension
public function amountArray(array $transaction): string
{
// first display amount:
$amount = strval($transaction['amount']);
$amount = (string)$transaction['amount'];
$fakeCurrency = new TransactionCurrency;
$fakeCurrency->decimal_places = $transaction['currency_dp'];
$fakeCurrency->symbol = $transaction['currency_symbol'];
@@ -109,7 +109,7 @@ class Transaction extends Twig_Extension
// then display (if present) the foreign amount:
if (null !== $transaction['foreign_amount']) {
$amount = strval($transaction['foreign_amount']);
$amount = (string)$transaction['foreign_amount'];
$fakeCurrency = new TransactionCurrency;
$fakeCurrency->decimal_places = $transaction['foreign_currency_dp'];
$fakeCurrency->symbol = $transaction['foreign_currency_symbol'];
@@ -205,7 +205,7 @@ class Transaction extends Twig_Extension
public function description(TransactionModel $transaction): string
{
$description = $transaction->description;
if (strlen(strval($transaction->transaction_description)) > 0) {
if (strlen((string)$transaction->transaction_description) > 0) {
$description = $transaction->transaction_description . ' (' . $transaction->description . ')';
}
@@ -226,13 +226,13 @@ class Transaction extends Twig_Extension
}
$name = app('steam')->tryDecrypt($transaction->account_name);
$transactionId = intval($transaction->account_id);
$transactionId = (int)$transaction->account_id;
$type = $transaction->account_type;
// name is present in object, use that one:
if (bccomp($transaction->transaction_amount, '0') === -1 && null !== $transaction->opposing_account_id) {
$name = $transaction->opposing_account_name;
$transactionId = intval($transaction->opposing_account_id);
$transactionId = (int)$transaction->opposing_account_id;
$type = $transaction->opposing_account_type;
}
@@ -249,7 +249,7 @@ class Transaction extends Twig_Extension
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->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));
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.
$name = app('steam')->tryDecrypt($transaction->account_name);
$transactionId = intval($transaction->account_id);
$transactionId = (int)$transaction->account_id;
$type = $transaction->account_type;
// name is present in object, use that one:
if (1 === bccomp($transaction->transaction_amount, '0') && null !== $transaction->opposing_account_id) {
$name = $transaction->opposing_account_name;
$transactionId = intval($transaction->opposing_account_id);
$transactionId = (int)$transaction->opposing_account_id;
$type = $transaction->opposing_account_type;
}
// Find the opposing account and use that one:

View File

@@ -59,7 +59,7 @@ class TransactionJournal extends Twig_Extension
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
$result = $repository->getMetaField($journal, $field);
if (is_null($result)) {
if (null === $result) {
return '';
}
@@ -80,10 +80,10 @@ class TransactionJournal extends Twig_Extension
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
$result = $repository->getMetaField($journal, $field);
if (is_null($result)) {
if (null === $result) {
return false;
}
if (strlen(strval($result)) === 0) {
if (strlen((string)$result) === 0) {
return false;
}
@@ -135,8 +135,7 @@ class TransactionJournal extends Twig_Extension
}
$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 = array_unique($array);
$result = join(', ', $array);
$result = implode(', ', $array);
$cache->store($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 = array_unique($array);
$result = join(', ', $array);
$result = implode(', ', $array);
$cache->store($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));
}
}
$string = join(', ', array_unique($budgets));
$string = implode(', ', array_unique($budgets));
$cache->store($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);
return $string;

View File

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

View File

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

View File

@@ -50,7 +50,7 @@ final class AmountMore extends AbstractTrigger implements TriggerInterface
public static function willMatchEverything($value = null)
{
if (null !== $value) {
$res = 0 === bccomp('0', strval($value));
$res = 0 === bccomp('0', (string)$value);
if (true === $res) {
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)
{
if (null !== $value) {
$res = '' === strval($value);
$res = '' === (string)$value;
if (true === $res) {
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)
{
if (null !== $value) {
$res = '' === strval($value);
$res = '' === (string)$value;
if (true === $res) {
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)
{
if (null !== $value) {
$res = '' === strval($value);
$res = '' === (string)$value;
if (true === $res) {
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)
{
if (null !== $value) {
$res = '' === strval($value);
$res = '' === (string)$value;
if (true === $res) {
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)
{
if (null !== $value) {
$res = '' === strval($value);
$res = '' === (string)$value;
if (true === $res) {
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)
{
if (null !== $value) {
$res = '' === strval($value);
$res = '' === (string)$value;
if (true === $res) {
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)
{
if (null !== $value) {
$res = '' === strval($value);
$res = '' === (string)$value;
if (true === $res) {
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)
{
$value = intval($value);
if ($value < 0) {
return true;
}
$value = (int)$value;
return false;
return $value < 0;
}
/**
@@ -65,7 +62,7 @@ class HasAttachment extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal): bool
{
$minimum = intval($this->triggerValue);
$minimum = (int)$this->triggerValue;
$attachments = $journal->attachments()->count();
if ($attachments >= $minimum) {
Log::debug(

View File

@@ -50,7 +50,7 @@ final class NotesContain extends AbstractTrigger implements TriggerInterface
public static function willMatchEverything($value = null)
{
if (null !== $value) {
$res = '' === strval($value);
$res = '' === (string)$value;
if (true === $res) {
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)
{
if (null !== $value) {
$res = '' === strval($value);
$res = '' === (string)$value;
if (true === $res) {
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)
{
if (null !== $value) {
$res = '' === strval($value);
$res = '' === (string)$value;
if (true === $res) {
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)
{
if (null !== $value) {
$res = '' === strval($value);
$res = '' === (string)$value;
if (true === $res) {
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)
{
if (null !== $value) {
$res = '' === strval($value);
$res = '' === (string)$value;
if (true === $res) {
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)
{
if (null !== $value) {
$res = '' === strval($value);
$res = '' === (string)$value;
if (true === $res) {
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)
{
if (null !== $value) {
$res = '' === strval($value);
$res = '' === (string)$value;
if (true === $res) {
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
{
$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);
if ($type === $search) {

View File

@@ -101,7 +101,7 @@ class AccountTransformer extends TransformerAbstract
*/
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.
$collector = app(JournalCollectorInterface::class);
@@ -112,7 +112,7 @@ class AccountTransformer extends TransformerAbstract
} else {
$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->setLimit($pageSize)->setPage($this->parameters->get('page'));
@@ -151,7 +151,7 @@ class AccountTransformer extends TransformerAbstract
if (strlen($role) === 0 || $type !== AccountType::ASSET) {
$role = null;
}
$currencyId = intval($this->repository->getMetaValue($account, 'currency_id'));
$currencyId = (int)$this->repository->getMetaValue($account, 'currency_id');
$currencyCode = null;
$decimalPlaces = 2;
if ($currencyId > 0) {
@@ -161,7 +161,7 @@ class AccountTransformer extends TransformerAbstract
}
$date = new Carbon;
if (!is_null($this->parameters->get('date'))) {
if (null !== $this->parameters->get('date')) {
$date = $this->parameters->get('date');
}
@@ -183,7 +183,7 @@ class AccountTransformer extends TransformerAbstract
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($account->user);
$amount = $repository->getOpeningBalanceAmount($account);
$openingBalance = is_null($amount) ? null : round($amount, $decimalPlaces);
$openingBalance = null === $amount ? null : round($amount, $decimalPlaces);
$openingBalanceDate = $repository->getOpeningBalanceDate($account);
}
@@ -192,7 +192,7 @@ class AccountTransformer extends TransformerAbstract
'updated_at' => $account->updated_at->toAtomString(),
'created_at' => $account->created_at->toAtomString(),
'name' => $account->name,
'active' => intval($account->active) === 1,
'active' => (int)$account->active === 1,
'type' => $type,
'currency_id' => $currencyId,
'currency_code' => $currencyCode,

View File

@@ -93,7 +93,7 @@ class BillTransformer extends TransformerAbstract
*/
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.
$collector = app(JournalCollectorInterface::class);
@@ -101,7 +101,7 @@ class BillTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setAllAssetAccounts();
$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->setLimit($pageSize)->setPage($this->parameters->get('page'));
@@ -145,8 +145,8 @@ class BillTransformer extends TransformerAbstract
'date' => $bill->date->format('Y-m-d'),
'repeat_freq' => $bill->repeat_freq,
'skip' => (int)$bill->skip,
'automatch' => intval($bill->automatch) === 1,
'active' => intval($bill->active) === 1,
'automatch' => (int)$bill->automatch === 1,
'active' => (int)$bill->active === 1,
'attachments_count' => $bill->attachments()->count(),
'pay_dates' => $payDates,
'paid_dates' => $paidData['paid_dates'],
@@ -161,7 +161,7 @@ class BillTransformer extends TransformerAbstract
];
/** @var Note $note */
$note = $bill->notes()->first();
if (!is_null($note)) {
if (null !== $note) {
$data['notes'] = $note->text;
}
@@ -222,7 +222,7 @@ class BillTransformer extends TransformerAbstract
protected function paidData(Bill $bill): array
{
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');
return [
@@ -267,7 +267,7 @@ class BillTransformer extends TransformerAbstract
*/
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 [];
}
$set = new Collection;

View File

@@ -75,7 +75,7 @@ class BudgetTransformer extends TransformerAbstract
*/
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.
$collector = app(JournalCollectorInterface::class);
@@ -83,7 +83,7 @@ class BudgetTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setAllAssetAccounts();
$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->setLimit($pageSize)->setPage($this->parameters->get('page'));
@@ -118,7 +118,7 @@ class BudgetTransformer extends TransformerAbstract
'id' => (int)$budget->id,
'updated_at' => $budget->updated_at->toAtomString(),
'created_at' => $budget->created_at->toAtomString(),
'active' => intval($budget->active) === 1,
'active' => (int)$budget->active === 1,
'name' => $budget->name,
'links' => [
[

View File

@@ -75,7 +75,7 @@ class CategoryTransformer extends TransformerAbstract
*/
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.
$collector = app(JournalCollectorInterface::class);
@@ -83,7 +83,7 @@ class CategoryTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
$collector->setAllAssetAccounts();
$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->setLimit($pageSize)->setPage($this->parameters->get('page'));

View File

@@ -75,7 +75,7 @@ class JournalMetaTransformer extends TransformerAbstract
public function includeTransactions(TransactionJournalMeta $meta): FractalCollection
{
$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.
$collector = app(JournalCollectorInterface::class);
@@ -83,7 +83,7 @@ class JournalMetaTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
$collector->setAllAssetAccounts();
$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->setLimit($pageSize)->setPage($this->parameters->get('page'));

View File

@@ -91,7 +91,7 @@ class PiggyBankEventTransformer extends TransformerAbstract
public function includeTransaction(PiggyBankEvent $event): Item
{
$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.
$collector = app(JournalCollectorInterface::class);
@@ -99,7 +99,7 @@ class PiggyBankEventTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
$collector->setAllAssetAccounts();
$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->setLimit($pageSize)->setPage($this->parameters->get('page'));
@@ -118,7 +118,7 @@ class PiggyBankEventTransformer extends TransformerAbstract
public function transform(PiggyBankEvent $event): array
{
$account = $event->piggyBank->account;
$currencyId = intval($account->getMeta('currency_id'));
$currencyId = (int)$account->getMeta('currency_id');
$decimalPlaces = 2;
if ($currencyId > 0) {
/** @var CurrencyRepositoryInterface $repository */

View File

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

View File

@@ -74,7 +74,7 @@ class TagTransformer extends TransformerAbstract
*/
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.
$collector = app(JournalCollectorInterface::class);
@@ -82,7 +82,7 @@ class TagTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
$collector->setAllAssetAccounts();
$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->setLimit($pageSize)->setPage($this->parameters->get('page'));
@@ -113,7 +113,7 @@ class TagTransformer extends TransformerAbstract
*/
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 = [
'id' => (int)$tag->id,
'updated_at' => $tag->updated_at->toAtomString(),

View File

@@ -157,21 +157,21 @@ class TransactionTransformer extends TransformerAbstract
$categoryName = null;
$budgetId = 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;
$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;
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;
$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;
}
/** @var Note $dbNote */
$dbNote = $transaction->transactionJournal->notes()->first();
$notes = null;
if (!is_null($dbNote)) {
if (null !== $dbNote) {
$notes = $dbNote->text;
}
@@ -186,7 +186,7 @@ class TransactionTransformer extends TransformerAbstract
'identifier' => $transaction->identifier,
'journal_id' => (int)$transaction->journal_id,
'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_code' => $transaction->transaction_currency_code,
'currency_symbol' => $transaction->transaction_currency_symbol,
@@ -212,8 +212,8 @@ class TransactionTransformer extends TransformerAbstract
];
// expand foreign amount:
if (!is_null($transaction->transaction_foreign_amount)) {
$data['foreign_amount'] = round($transaction->transaction_foreign_amount, intval($transaction->foreign_currency_dp));
if (null !== $transaction->transaction_foreign_amount) {
$data['foreign_amount'] = round($transaction->transaction_foreign_amount, (int)$transaction->foreign_currency_dp);
}
// switch on type for consistency
@@ -251,7 +251,7 @@ class TransactionTransformer extends TransformerAbstract
}
// expand description.
if (strlen(strval($transaction->transaction_description)) > 0) {
if (strlen((string)$transaction->transaction_description) > 0) {
$data['description'] = $transaction->transaction_description . ' (' . $transaction->description . ')';
}

View File

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

View File

@@ -37,7 +37,6 @@ use FireflyIII\TransactionRules\Triggers\TriggerInterface;
use FireflyIII\User;
use Google2FA;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Contracts\Translation\Translator;
use Illuminate\Validation\Validator;
/**
@@ -45,18 +44,6 @@ use Illuminate\Validation\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)
*
@@ -89,7 +76,7 @@ class FireflyValidator extends Validator
{
$field = $parameters[1] ?? 'id';
if (0 === intval($value)) {
if (0 === (int)$value) {
return true;
}
$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);
$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
{
$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';
if (0 === intval($value)) {
if (0 === (int)$value) {
return true;
}
$count = DB::table($parameters[0])->where($field, $value)->count();
@@ -333,7 +320,7 @@ class FireflyValidator extends Validator
{
$verify = false;
if (isset($this->data['verify_password'])) {
$verify = 1 === intval($this->data['verify_password']);
$verify = 1 === (int)$this->data['verify_password'];
}
if ($verify) {
/** @var Verifier $service */
@@ -389,9 +376,9 @@ class FireflyValidator extends Validator
*/
public function validateUniqueAccountNumberForUser($attribute, $value, $parameters): bool
{
$accountId = $this->data['id'] ?? 0;
$accountId = (int)($this->data['id'] ?? 0.0);
if ($accountId === 0) {
$accountId = $parameters[0] ?? 0;
$accountId = (int)($parameters[0] ?? 0.0);
}
$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('account_meta.name', 'accountNumber');
if (intval($accountId) > 0) {
if ((int)$accountId > 0) {
// 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.*']);
@@ -435,15 +422,15 @@ class FireflyValidator extends Validator
// exclude?
$table = $parameters[0];
$field = $parameters[1];
$exclude = $parameters[2] ?? 0;
$exclude = (int)($parameters[2] ?? 0.0);
/*
* If other data (in $this->getData()) contains
* ID field, set that field to be the $exclude.
*/
$data = $this->getData();
if (!isset($parameters[2]) && isset($data['id']) && intval($data['id']) > 0) {
$exclude = intval($data['id']);
if (!isset($parameters[2]) && isset($data['id']) && (int)$data['id'] > 0) {
$exclude = (int)$data['id'];
}
@@ -586,7 +573,7 @@ class FireflyValidator extends Validator
private function validateByAccountTypeId($value, $parameters): bool
{
$type = AccountType::find($this->data['account_type_id'])->first();
$ignore = $parameters[0] ?? 0;
$ignore = (int)($parameters[0] ?? 0.0);
$value = $this->tryDecrypt($value);
$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);
$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();
/** @var Account $entry */