ProblemController::index()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 13
rs 10
1
<?php
2
3
namespace App\Http\Controllers\Web;
4
5
use App\Entities\Problem;
6
use App\Http\Controllers\Controller;
7
use App\Repositories\Criteria\SearchByColumn;
8
use App\Repositories\Criteria\Where;
9
use App\Repositories\ProblemRepository;
10
use App\Services\SummaryService;
11
12
class ProblemController extends Controller
13
{
14
    private $repository;
15
16
    /**
17
     * ProblemController constructor.
18
     *
19
     * @param ProblemRepository $repository
20
     */
21
    public function __construct(ProblemRepository $repository)
22
    {
23
        $this->repository = $repository;
24
    }
25
26
    public function show($id)
27
    {
28
        /** @var Problem $problem */
29
        $problem = $this->repository->findOrFail($id);
30
        if (! $problem->isAvailable()) {
31
            return back()->withErrors('Problem is not found!');
32
        }
33
34
        return view('web.problem.show', ['problem' => $problem]);
35
    }
36
37
    public function index()
38
    {
39
        if (request('text')) {
40
            $searchByColumn = new SearchByColumn(request('text'), request('area'));
41
            $this->repository->pushCriteria($searchByColumn);
42
        }
43
44
        $this->repository->pushCriteria(new Where('status', Problem::ST_NORMAL));
45
46
        $perPage = request('per_page', 100);
47
        $problems = $this->repository->paginate($perPage);
0 ignored issues
show
Bug introduced by
$perPage of type Illuminate\Http\Request|array|string is incompatible with the type integer expected by parameter $perPage of Czim\Repository\BaseRepository::paginate(). ( Ignorable by Annotation )

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

47
        $problems = $this->repository->paginate(/** @scrutinizer ignore-type */ $perPage);
Loading history...
48
49
        return view('web.problem.index', ['problems' => $problems]);
50
    }
51
52
    public function summary($id)
53
    {
54
        /** @var Problem $problem */
55
        $problem = $this->repository->findOrFail($id);
56
        if (! $problem->isAvailable()) {
57
            return back()->withErrors('Problem is not found!');
58
        }
59
60
        $summary = new SummaryService($problem);
61
62
        return view('web.problem.summary', ['summary' => $summary, 'perPage' => 50, 'problem' => $problem]);
63
    }
64
}
65