Completed
Push — master ( 7ef4f0...fad325 )
by Sebastian
17:53 queued 12:31
created

FragmentsController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 5

6 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 6 1
A hidden() 0 6 1
A create() 0 7 1
A edit() 0 6 1
A update() 0 19 2
A download() 0 4 1
1
<?php
2
3
namespace App\Http\Controllers\Back;
4
5
use App\Http\Requests\Back\FragmentRequest;
6
use App\Models\Fragment;
7
use Spatie\FragmentImporter\Exporter;
8
9
class FragmentsController
10
{
11
    public function index()
12
    {
13
        $fragments = Fragment::where('hidden', false)->get();
14
15
        return view('back.fragments.index')->with(compact('fragments'));
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
16
    }
17
18
    public function hidden()
19
    {
20
        $fragments = Fragment::where('hidden', true)->get();
21
22
        return view('back.fragments.index')->with(compact('fragments'));
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
23
    }
24
25
    public function create()
26
    {
27
        $fragment = new Fragment();
28
        $fragment->save();
29
30
        return redirect()->action('Back\FragmentsController@edit', [$fragment->id]);
31
    }
32
33
    public function edit($id)
34
    {
35
        $fragment = Fragment::find($id);
36
37
        return view('back.fragments.edit')->with(compact('fragment'));
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
38
    }
39
40
    public function update($id, FragmentRequest $request)
41
    {
42
        $fragment = Fragment::find($id);
43
44
        foreach (locales() as $locale) {
45
            $requestAttribute = "translated_{$locale}_text";
46
47
            $fragment->setTranslation($locale, $request->get($requestAttribute));
48
        }
49
50
        $fragment->save();
51
        app('cache')->flush();
52
53
        $eventDescription = fragment('back.events.updated', ['model' => 'Fragment', 'name' => $fragment->name]);
54
55
        flash()->success(strip_tags($eventDescription));
56
57
        return redirect()->action('Back\FragmentsController@index');
58
    }
59
60
    public function download()
61
    {
62
        Exporter::sendExportToBrowser();
63
    }
64
}
65