Completed
Push — master ( 7eba8f...c52d76 )
by Iman
18s queued 10s
created

IndexExport::pdf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
nc 1
nop 4
dl 0
loc 8
c 0
b 0
f 0
cc 1
rs 9.4285
1
<?php
2
3
namespace crocodicstudio\crudbooster\controllers\Helpers;
4
5
use Maatwebsite\Excel\Facades\Excel;
6
7
class IndexExport
8
{
9
    /**
10
     * @param $response
11
     * @param $papersize
12
     * @param $paperorientation
13
     * @param $filename
14
     * @return mixed
15
     */
16
    public function pdf($filename, $response, $paperorientation, $papersize)
17
    {
18
        $view = view('crudbooster::export', $response)->render();
19
        $pdf = app('dompdf.wrapper');
20
        $pdf->loadHTML($view);
0 ignored issues
show
Bug introduced by
The method loadHTML() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

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

20
        $pdf->/** @scrutinizer ignore-call */ 
21
              loadHTML($view);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
21
        $pdf->setPaper($papersize, $paperorientation);
0 ignored issues
show
Bug introduced by
The method setPaper() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

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

21
        $pdf->/** @scrutinizer ignore-call */ 
22
              setPaper($papersize, $paperorientation);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
23
        return $pdf->stream($filename.'.pdf');
0 ignored issues
show
Bug introduced by
The method stream() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

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

23
        return $pdf->/** @scrutinizer ignore-call */ stream($filename.'.pdf');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24
    }
25
26
    /**
27
     * @param $filename
28
     * @param $response
29
     * @param $orientation
30
     */
31
    public function xls($filename, $response, $orientation)
32
    {
33
        return $this->exportExcelAs($filename, $response, $orientation, 'xls');
34
    }
35
36
    /**
37
     * @param $filename
38
     * @param $response
39
     * @param $orientation
40
     */
41
    public function csv($filename, $response, $orientation)
42
    {
43
        return $this->exportExcelAs($filename, $response, $orientation, 'csv');
44
    }
45
46
    /**
47
     * @param $filename
48
     * @param $response
49
     * @param $orientation
50
     * @param $fmt
51
     * @return mixed
52
     */
53
    private function exportExcelAs($filename, $response, $orientation, $fmt)
54
    {
55
        return Excel::create($filename, function ($excel) use ($response, $orientation, $filename) {
56
            $excel->setTitle($filename)->setCreator("crudbooster.com")->setCompany(cbGetsetting('appname'));
57
            $excel->sheet($filename, function ($sheet) use ($response, $orientation) {
58
                $sheet->setOrientation($orientation);
59
                $sheet->loadview('crudbooster::export', $response);
60
            });
61
        })->export($fmt);
62
    }
63
}