Fix various phpstan issues.

This commit is contained in:
James Cole
2023-11-04 11:31:14 +01:00
parent ef428a0226
commit 0220cf9784
64 changed files with 195 additions and 153 deletions

View File

@@ -77,7 +77,7 @@ class StoreRequest extends FormRequest
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
*
* @return array|null
* @return array
*/
private function getTransactionData(): array
{

View File

@@ -198,6 +198,7 @@ class StoreRequest extends FormRequest
protected function atLeastOneActiveTrigger(Validator $validator): void
{
$data = $validator->getData();
/** @var string|int|array|null $triggers */
$triggers = $data['triggers'] ?? [];
// need at least one trigger
if (!is_countable($triggers) || 0 === count($triggers)) {
@@ -227,6 +228,7 @@ class StoreRequest extends FormRequest
protected function atLeastOneActiveAction(Validator $validator): void
{
$data = $validator->getData();
/** @var string|int|array|null $actions */
$actions = $data['actions'] ?? [];
// need at least one trigger
if (!is_countable($actions) || 0 === count($actions)) {

View File

@@ -66,7 +66,11 @@ class TestRequest extends FormRequest
*/
private function getDate(string $field): ?Carbon
{
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
$result = null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', substr((string)$this->query($field), 0, 10));
if(false === $result) {
return null;
}
return $result;
}
/**

View File

@@ -56,7 +56,11 @@ class TriggerRequest extends FormRequest
*/
private function getDate(string $field): ?Carbon
{
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', substr($this->query($field), 0, 10));
$result = null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', substr((string)$this->query($field), 0, 10));
if(false === $result) {
return null;
}
return $result;
}
/**

View File

@@ -56,7 +56,11 @@ class TriggerRequest extends FormRequest
*/
private function getDate(string $field): ?Carbon
{
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
$result = null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', substr((string)$this->query($field), 0, 10));
if(false === $result) {
return null;
}
return $result;
}
/**

View File

@@ -159,12 +159,15 @@ class UpdateRequest extends FormRequest
app('log')->debug(sprintf('Now in %s', __METHOD__));
$return = [];
if (!is_countable($this->get('transactions'))) {
/** @var array|null $transactions */
$transactions = $this->get('transactions');
if (!is_countable($transactions)) {
return $return;
}
/** @var array $transaction */
foreach ($this->get('transactions') as $transaction) {
foreach ($transactions as $transaction) {
if (!is_array($transaction)) {
throw new FireflyException('Invalid data submitted: transaction is not array.');
}