StatisticsController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Sausin\Signere\Http\Controllers\Admin;
4
5
use Carbon\Carbon;
6
use Illuminate\Http\Request;
7
use Sausin\Signere\Statistics;
8
use Sausin\Signere\Http\Controllers\Controller;
9
10
class StatisticsController extends Controller
11
{
12
    /** @var \Sausin\Signere\Statistics */
13
    protected $statistics;
14
15
    /**
16
     * Create a new controller instance.
17
     *
18
     * @param  \Sausin\Signere\Statistics $statistics
19
     */
20 2
    public function __construct(Statistics $statistics)
21
    {
22 2
        parent::__construct();
23
24 2
        $this->statistics = $statistics;
25 2
    }
26
27
    /**
28
     * Get the statistics contrained by the given parameters.
29
     *
30
     * @param  Request $request
31
     * @return \Illuminate\Http\Response
32
     */
33 2
    public function __invoke(Request $request)
34
    {
35 2
        $this->validate($request, [
36 2
            'year' => 'sometimes|numeric|nullable|min:2015|max:'.Carbon::now()->year,
37 2
            'month' => 'sometimes|numeric|nullable|min:1|max:12',
38 2
            'day' => 'sometimes|numeric|nullable|min:1|max:31',
39
        ]);
40
41 2
        $allowedStatus = ['All', 'Canceled', 'Signed', 'Expired', 'Unsigned', 'Changed', 'PartialSigned'];
42 2
        $status = in_array($request->status, $allowedStatus, true) ? $request->status : 'All';
43
44 2
        return $this->statistics->get($request->year, $request->month, $request->day, $status)
45 2
                ->getBody()
46 2
                ->getContents();
47
    }
48
}
49