Code Duplication    Length = 57-57 lines in 2 locations

src/Grid/Tools/Footer.php 1 location

@@ 10-66 (lines=57) @@
7
use Illuminate\Contracts\Support\Renderable;
8
use Illuminate\Database\Query\Builder;
9
10
class Footer extends AbstractTool
11
{
12
    /**
13
     * @var Builder
14
     */
15
    protected $queryBuilder;
16
17
    /**
18
     * Footer constructor.
19
     *
20
     * @param Grid $grid
21
     */
22
    public function __construct(Grid $grid)
23
    {
24
        $this->grid = $grid;
25
    }
26
27
    /**
28
     * Get model query builder.
29
     *
30
     * @return \Illuminate\Database\Eloquent\Builder
31
     */
32
    public function queryBuilder()
33
    {
34
        if (!$this->queryBuilder) {
35
            $this->queryBuilder = $this->grid->model()->getQueryBuilder();
36
        }
37
38
        return $this->queryBuilder;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function render()
45
    {
46
        $content = call_user_func($this->grid->footer(), $this->queryBuilder());
47
48
        if (empty($content)) {
49
            return '';
50
        }
51
52
        if ($content instanceof Renderable) {
53
            $content = $content->render();
54
        }
55
56
        if ($content instanceof Htmlable) {
57
            $content = $content->toHtml();
58
        }
59
60
        return <<<HTML
61
    <div class="box-footer clearfix">
62
        {$content}
63
    </div>
64
HTML;
65
    }
66
}
67

src/Grid/Tools/Header.php 1 location

@@ 10-66 (lines=57) @@
7
use Illuminate\Contracts\Support\Renderable;
8
use Illuminate\Database\Query\Builder;
9
10
class Header extends AbstractTool
11
{
12
    /**
13
     * @var Builder
14
     */
15
    protected $queryBuilder;
16
17
    /**
18
     * Header constructor.
19
     *
20
     * @param Grid $grid
21
     */
22
    public function __construct(Grid $grid)
23
    {
24
        $this->grid = $grid;
25
    }
26
27
    /**
28
     * Get model query builder.
29
     *
30
     * @return \Illuminate\Database\Eloquent\Builder
31
     */
32
    public function queryBuilder()
33
    {
34
        if (!$this->queryBuilder) {
35
            $this->queryBuilder = $this->grid->model()->getQueryBuilder();
36
        }
37
38
        return $this->queryBuilder;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function render()
45
    {
46
        $content = call_user_func($this->grid->header(), $this->queryBuilder());
47
48
        if (empty($content)) {
49
            return '';
50
        }
51
52
        if ($content instanceof Renderable) {
53
            $content = $content->render();
54
        }
55
56
        if ($content instanceof Htmlable) {
57
            $content = $content->toHtml();
58
        }
59
60
        return <<<HTML
61
    <div class="box-header with-border clearfix">
62
        {$content}
63
    </div>
64
HTML;
65
    }
66
}
67