Passed
Push — master ( d63a45...8016ac )
by Iman
09:10
created

IndexExport   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A csv() 0 3 1
A pdf() 0 8 1
A xls() 0 3 1
A exportExcelAs() 0 9 1
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
     * @throws \Throwable
16
     */
17
    public function pdf($fileName, $response, $paperOrientation, $paperSize)
18
    {
19
        $view = view('crudbooster::export', $response)->render();
20
        $pdf = app('dompdf.wrapper');
21
        $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

21
        $pdf->/** @scrutinizer ignore-call */ 
22
              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...
22
        $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

22
        $pdf->/** @scrutinizer ignore-call */ 
23
              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...
23
24
        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

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