Passed
Push — dependabot/npm_and_yarn/sass-l... ( 8020b5...8bd125 )
by
unknown
230:05 queued 222:10
created

BulkActionsController::download()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Thinktomorrow\Chief\Mediagallery\Http;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Http\Request;
7
use Thinktomorrow\Chief\MediaGallery\Application\ZipAction;
8
use Thinktomorrow\Chief\MediaGallery\Application\RemovalAction;
9
    use Thinktomorrow\Chief\App\Http\Controllers\Controller;
10
11
class BulkActionsController extends Controller
12
{
13
    /** @var ZipAction */
14
    private $zipAction;
15
16
    /** @var RemovalAction */
17
    private $removalAction;
18
19
    public function __construct(ZipAction $zipAction, RemovalAction $removalAction)
20
    {
21
        $this->zipAction = $zipAction;
22
        $this->removalAction = $removalAction;
23
    }
24
25
    public function bulk(Request $request)
26
    {
27
        if($request->input('type') == 'download') {
28
            return $this->download($request);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->download($request) targeting Thinktomorrow\Chief\Medi...sController::download() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
29
        }
30
31
        if($request->input('type') == 'remove') {
32
            return $this->remove($request);
33
        }
34
    }
35
36
    private function download(Request $request)
37
    {
38
        $filename = Str::slug(config('app.name')) . '_assets_' . date('YmdHis') . '.zip';
39
40
        // TODO: do the response here instead of the zip action itself
41
        return $this->zipAction->handle($filename, $request);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->zipAction->handle($filename, $request) targeting Thinktomorrow\Chief\Medi...ion\ZipAction::handle() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
42
    }
43
44
    private function remove(Request $request)
45
    {
46
        $result = $this->removalAction->handle($request);
47
48
        if($result) {
49
            return redirect()->back()->with('messages.success', 'De mediabestanden zijn verwijderd');
50
        }
51
52
        return redirect()->back()->with('messages.error', 'Er ging iets mis, er zijn geen bestanden verwijderd. Mogelijks probeerde je een bestand te verwijderen dat nog gebruikt wordt.');
53
    }
54
}
55