FeesController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 9
dl 0
loc 91
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A index() 0 8 1
A archive() 0 7 1
A create() 0 9 1
A store() 0 10 1
A destroy() 0 6 1
1
<?php
2
3
/**
4
 * Storgman - Student Organizations Management
5
 * Copyright (C) 2014-2016, Dejan Angelov <[email protected]>
6
 *
7
 * This file is part of Storgman.
8
 *
9
 * Storgman is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation, either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * Storgman 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 General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with Storgman.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 * @package Storgman
23
 * @copyright Copyright (C) 2014-2016, Dejan Angelov <[email protected]>
24
 * @license https://github.com/angelov/storgman/blob/master/LICENSE
25
 * @author Dejan Angelov <[email protected]>
26
 */
27
28
namespace Angelov\Storgman\Membership\Http\Controllers;
29
30
use Angelov\Storgman\Core\Http\Controllers\BaseController;
31
use Angelov\Storgman\Membership\Commands\DeleteFeeCommand;
32
use Angelov\Storgman\Membership\Commands\StoreFeeCommand;
33
use Angelov\Storgman\Membership\Http\Requests\StoreFeeRequest;
34
use Angelov\Storgman\Membership\FeesPaginator;
35
use Angelov\Storgman\Membership\MembershipService;
36
use Illuminate\Contracts\View\View;
37
use Illuminate\Http\JsonResponse;
38
use Illuminate\Http\Request;
39
use Angelov\Storgman\Membership\Repositories\FeesRepositoryInterface;
40
use Angelov\Storgman\Members\Repositories\MembersRepositoryInterface;
41
42
class FeesController extends BaseController
43
{
44
    protected $fees;
45
    protected $members;
46
    protected $paginator;
47
    protected $membership;
48
49
    public function __construct(FeesRepositoryInterface $fees, MembersRepositoryInterface $members, MembershipService $membership)
50
    {
51
        $this->fees = $fees;
52
        $this->members = $members;
53
        $this->membership = $membership;
54
    }
55
56
    /**
57
     * Display the main page for managing the fees
58
     *
59
     * @return View
60
     */
61
    public function index()
62
    {
63
        $latest = $this->fees->latest(5, ['member'], 'id');
64
        $toExpire = $this->fees->getSoonToExpire(5);
65
        $fees = json_encode($this->membership->getExpectedAndPaidFeesPerMonthLastYear());
66
67
        return view('fees.index', compact('latest', 'toExpire', 'fees'));
68
    }
69
70
    /**
71
     * List all paid fees
72
     *
73
     * @param Request $request
74
     * @param FeesPaginator $paginator
75
     * @return View
76
     */
77
    public function archive(Request $request, FeesPaginator $paginator)
78
    {
79
        $page = $request->get('page', 1);
80
        $fees = $paginator->get($page, ['member']);
81
82
        return view('fees.archive', compact('fees'));
83
    }
84
85
    /**
86
     * Show the form for creating a new fee.
87
     * Method available only via ajax.
88
     *
89
     * @param Request $request
90
     * @return string The rendered view
91
     */
92
    public function create(Request $request)
93
    {
94
        $memberId = $request->get('member_id');
95
        $member = $this->members->get($memberId);
96
97
        $suggestDates = $this->membership->suggestDates($member);
98
99
        return view('members.modals.renew-membership', compact('member', 'suggestDates'))->render();
0 ignored issues
show
Bug introduced by
The method render does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
100
    }
101
102
    /**
103
     * Store a newly created fee.
104
     *
105
     * @param StoreFeeRequest $request
106
     * @return JsonResponse
107
     */
108
    public function store(StoreFeeRequest $request)
109
    {
110
        $memberId = $request->get('member_id');
111
        $from = $request->get('from');
112
        $to = $request->get('to');
113
114
        dispatch(new StoreFeeCommand($memberId, $from, $to));
115
116
        return $this->successfulJsonResponse('The membership was renewed successfully.');
117
    }
118
119
    /**
120
     * Remove the specified fee from storage.
121
     * Method available only via ajax.
122
     *
123
     * @param  int      $id
124
     * @return JsonResponse
125
     */
126
    public function destroy($id)
127
    {
128
        dispatch(new DeleteFeeCommand($id));
129
130
        return $this->successfulJsonResponse('Fee deleted successfully.');
131
    }
132
}
133