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)

Api/V1/Controllers/Search/TransferController.php (5 issues)

1
<?php
2
declare(strict_types=1);
3
/**
4
 * TransferController.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
namespace FireflyIII\Api\V1\Controllers\Search;
24
25
use FireflyIII\Api\V1\Controllers\Controller;
26
use FireflyIII\Api\V1\Requests\Search\TransferRequest;
27
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
28
use FireflyIII\Support\Search\TransferSearch;
29
use FireflyIII\Transformers\TransactionGroupTransformer;
30
use FireflyIII\User;
31
use Illuminate\Http\JsonResponse;
32
use Illuminate\Http\Response;
33
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
34
use League\Fractal\Resource\Collection as FractalCollection;
35
36
/**
37
 * Class TransferController
38
 */
39
class TransferController extends Controller
40
{
41
    /**
42
     * @param TransferRequest $request
43
     *
44
     * @return JsonResponse|Response
45
     */
46
    public function search(TransferRequest $request)
47
    {
48
        // configure transfer search to search for a > b
49
        $search = app(TransferSearch::class);
50
        $search->setSource($request->get('source'));
0 ignored issues
show
It seems like $request->get('source') can also be of type null; however, parameter $source of FireflyIII\Support\Searc...sferSearch::setSource() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

50
        $search->setSource(/** @scrutinizer ignore-type */ $request->get('source'));
Loading history...
51
        $search->setDestination($request->get('destination'));
0 ignored issues
show
It seems like $request->get('destination') can also be of type null; however, parameter $destination of FireflyIII\Support\Searc...earch::setDestination() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

51
        $search->setDestination(/** @scrutinizer ignore-type */ $request->get('destination'));
Loading history...
52
        $search->setAmount($request->get('amount'));
0 ignored issues
show
It seems like $request->get('amount') can also be of type null; however, parameter $amount of FireflyIII\Support\Searc...sferSearch::setAmount() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

52
        $search->setAmount(/** @scrutinizer ignore-type */ $request->get('amount'));
Loading history...
53
        $search->setDescription($request->get('description'));
0 ignored issues
show
It seems like $request->get('description') can also be of type null; however, parameter $description of FireflyIII\Support\Searc...earch::setDescription() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

53
        $search->setDescription(/** @scrutinizer ignore-type */ $request->get('description'));
Loading history...
54
        $search->setDate($request->get('date'));
0 ignored issues
show
It seems like $request->get('date') can also be of type null; however, parameter $date of FireflyIII\Support\Searc...ansferSearch::setDate() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

54
        $search->setDate(/** @scrutinizer ignore-type */ $request->get('date'));
Loading history...
55
56
        $left = $search->search();
57
58
        // configure transfer search to search for b > a
59
        $search->setSource($request->get('destination'));
60
        $search->setDestination($request->get('source'));
61
        $search->setAmount($request->get('amount'));
62
        $search->setDescription($request->get('description'));
63
        $search->setDate($request->get('date'));
64
65
        $right = $search->search();
66
67
        // add parameters to URL:
68
        $this->parameters->set('source', $request->get('source'));
69
        $this->parameters->set('destination', $request->get('destination'));
70
        $this->parameters->set('amount', $request->get('amount'));
71
        $this->parameters->set('description', $request->get('description'));
72
        $this->parameters->set('date', $request->get('date'));
73
74
        // get all journal ID's.
75
        $total = $left->merge($right)->unique('id')->pluck('id')->toArray();
76
        if (0 === count($total)) {
77
            // forces search to be empty.
78
            $total = [-1];
79
        }
80
81
        // collector to return results.
82
        $pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
83
        $manager  = $this->getManager();
84
        /** @var User $admin */
85
        $admin = auth()->user();
86
87
        // use new group collector:
88
        /** @var GroupCollectorInterface $collector */
89
        $collector = app(GroupCollectorInterface::class);
90
        $collector
91
            ->setUser($admin)
92
            // all info needed for the API:
93
            ->withAPIInformation()
94
            // set page size:
95
            ->setLimit($pageSize)
96
            // set page to retrieve
97
            ->setPage(1)
98
            ->setJournalIds($total);
99
100
        $paginator = $collector->getPaginatedGroups();
101
        $paginator->setPath(route('api.v1.search.transfers') . $this->buildParams());
102
        $transactions = $paginator->getCollection();
103
104
        /** @var TransactionGroupTransformer $transformer */
105
        $transformer = app(TransactionGroupTransformer::class);
106
        $transformer->setParameters($this->parameters);
107
108
        $resource = new FractalCollection($transactions, $transformer, 'transactions');
109
        $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
110
111
        return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
112
    }
113
}
114