GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (724)

V1/Controllers/Chart/AvailableBudgetController.php (4 issues)

1
<?php
2
3
/**
4
 * AvailableBudgetController.php
5
 * Copyright (c) 2019 [email protected]
6
 *
7
 * This file is part of Firefly III (https://github.com/firefly-iii).
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
21
 */
22
23
declare(strict_types=1);
24
25
namespace FireflyIII\Api\V1\Controllers\Chart;
26
27
28
use FireflyIII\Api\V1\Controllers\Controller;
29
use FireflyIII\Models\AvailableBudget;
30
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
31
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
32
use FireflyIII\User;
33
use Illuminate\Http\JsonResponse;
34
use Illuminate\Support\Collection;
35
36
/**
37
 * Class AvailableBudgetController
38
 */
39
class AvailableBudgetController extends Controller
40
{
41
    /** @var OperationsRepositoryInterface */
42
    private $opsRepository;
43
    /** @var BudgetRepositoryInterface */
44
    private $repository;
45
46
    /**
47
     * AvailableBudgetController constructor.
48
     *
49
     * @codeCoverageIgnore
50
     */
51
    public function __construct()
52
    {
53
        parent::__construct();
54
        $this->middleware(
55
            function ($request, $next) {
56
                /** @var User $user */
57
                $user                = auth()->user();
58
                $this->repository    = app(BudgetRepositoryInterface::class);
59
                $this->opsRepository = app(OperationsRepositoryInterface::class);
60
                $this->repository->setUser($user);
61
                $this->opsRepository->setUser($user);
62
63
                return $next($request);
64
            }
65
        );
66
    }
67
68
    /**
69
     * @param AvailableBudget $availableBudget
70
     *
71
     * @return JsonResponse
72
     */
73
    public function overview(AvailableBudget $availableBudget): JsonResponse
74
    {
75
        $currency          = $availableBudget->transactionCurrency;
76
        $budgets           = $this->repository->getActiveBudgets();
77
        $budgetInformation = $this->opsRepository->spentInPeriodMc($budgets, new Collection, $availableBudget->start_date, $availableBudget->end_date);
0 ignored issues
show
$availableBudget->end_date of type string is incompatible with the type Carbon\Carbon expected by parameter $end of FireflyIII\Repositories\...face::spentInPeriodMc(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

77
        $budgetInformation = $this->opsRepository->spentInPeriodMc($budgets, new Collection, $availableBudget->start_date, /** @scrutinizer ignore-type */ $availableBudget->end_date);
Loading history...
Deprecated Code introduced by
The function FireflyIII\Repositories\...face::spentInPeriodMc() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

77
        $budgetInformation = /** @scrutinizer ignore-deprecated */ $this->opsRepository->spentInPeriodMc($budgets, new Collection, $availableBudget->start_date, $availableBudget->end_date);
Loading history...
$availableBudget->start_date of type string is incompatible with the type Carbon\Carbon expected by parameter $start of FireflyIII\Repositories\...face::spentInPeriodMc(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

77
        $budgetInformation = $this->opsRepository->spentInPeriodMc($budgets, new Collection, /** @scrutinizer ignore-type */ $availableBudget->start_date, $availableBudget->end_date);
Loading history...
78
        $spent             = 0.0;
79
80
        // get for current currency
81
        foreach ($budgetInformation as $spentInfo) {
82
            if ($spentInfo['currency_id'] === $availableBudget->transaction_currency_id) {
83
                $spent = $spentInfo['amount'];
84
            }
85
        }
86
        $left = bcadd($availableBudget->amount, (string) $spent);
87
        // left less than zero? Set to zero.
88
        if (-1 === bccomp($left, '0')) {
89
            $left = '0';
90
        }
91
92
        $chartData = [
93
            [
94
                'label'                   => trans('firefly.spent'),
95
                'currency_id'             => $currency->id,
96
                'currency_code'           => $currency->code,
97
                'currency_symbol'         => $currency->symbol,
98
                'currency_decimal_places' => $currency->decimal_places,
99
                'type'                    => 'pie',
100
                'yAxisID'                 => 0, // 0, 1, 2
101
                'entries'                 => [$spent * -1],
102
            ],
103
            [
104
                'label'                   => trans('firefly.left'),
105
                'currency_id'             => $currency->id,
106
                'currency_code'           => $currency->code,
107
                'currency_symbol'         => $currency->symbol,
108
                'currency_decimal_places' => $currency->decimal_places,
109
                'type'                    => 'line', // line, area or bar
110
                'yAxisID'                 => 0, // 0, 1, 2
111
                'entries'                 => [round($left, $currency->decimal_places)],
0 ignored issues
show
$left of type string is incompatible with the type double expected by parameter $val of round(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

111
                'entries'                 => [round(/** @scrutinizer ignore-type */ $left, $currency->decimal_places)],
Loading history...
112
            ],
113
        ];
114
115
        return response()->json($chartData);
116
    }
117
118
}
119