Passed
Branch master (249862)
by Adam
07:51
created

LogController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 2
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
1
<?php
2
3
namespace Coyote\Http\Controllers\Wiki;
4
5
use Boduch\Grid\Source\EloquentSource;
6
use Coyote\Http\Grids\Wiki\LogGrid;
7
use Illuminate\Http\Request;
8
9
class LogController extends BaseController
10
{
11
    /**
12
     * @param \Coyote\Wiki $wiki
13
     * @param Request $request
14
     * @return \Illuminate\View\View
15
     */
16
    public function index($wiki, Request $request)
17
    {
18
        $this->breadcrumb->push('Historia zmian', route('wiki.log', [$wiki->id]));
19
20
        $source = new EloquentSource(
21
            $this
22
                ->wiki
23
                ->getLogBuilder()
24
                ->where('wiki_log.wiki_id', $wiki->wiki_id)
25
                ->where('wiki_paths.path_id', $wiki->id)
26
        );
27
28
        /** @var LogGrid $grid */
29
        $grid = $this
30
            ->gridBuilder()
31
            ->createGrid(LogGrid::class)
32
            ->setSource($source)
33
            ->setEnablePagination(false)
34
            ->addComparisionButtons();
0 ignored issues
show
Bug introduced by
The method addComparisionButtons() does not exist on Boduch\Grid\Grid. It seems like you code against a sub-type of Boduch\Grid\Grid such as Coyote\Http\Grids\Wiki\LogGrid. ( Ignorable by Annotation )

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

34
            ->/** @scrutinizer ignore-call */ addComparisionButtons();
Loading history...
35
36
        $diff = $this->diff($wiki, $request);
37
38
        return $this->view('wiki.log')->with(compact('grid', 'wiki', 'diff'));
39
    }
40
41
    /**
42
     * @param \Coyote\Wiki $wiki
43
     * @param Request $request
44
     * @return array
45
     */
46
    private function diff($wiki, Request $request)
47
    {
48
        if (!$request->has('r1') || !$request->has('r2')) {
49
            return [];
50
        }
51
52
        return [
53
            'before' => htmlspecialchars($wiki->logs->find($request->get('r1'), ['text'])->text),
0 ignored issues
show
Bug introduced by
It seems like $wiki->logs->find($reque...), array('text'))->text can also be of type Illuminate\Support\HigherOrderCollectionProxy and Illuminate\Database\Eloq...uent\Relations\Relation and Illuminate\Database\Eloquent\Relations\Relation; however, parameter $string of htmlspecialchars() 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
            'before' => htmlspecialchars(/** @scrutinizer ignore-type */ $wiki->logs->find($request->get('r1'), ['text'])->text),
Loading history...
54
            'after' => htmlspecialchars($wiki->logs->find($request->get('r2'), ['text'])->text)
55
        ];
56
    }
57
}
58