Passed
Push — master ( b8999c...a2f941 )
by Curtis
09:12 queued 03:15
created

Index   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A tutorials() 0 4 1
A homeTutorials() 0 7 1
A routeTutorials() 0 7 2
A toResponse() 0 5 1
1
<?php
2
3
namespace App\Http\Response\enso\Tutorials;
4
5
use Illuminate\Contracts\Support\Responsable;
6
use Illuminate\Support\Collection;
7
use App\Models\enso\Permissions\Permission;
8
use LaravelEnso\Tutorials\Http\Resources\Tutorial as Resource;
9
use App\Models\enso\Tutorials\Tutorial;
10
11
class Index implements Responsable
12
{
13
    private $route;
14
15
    public function toResponse($request)
16
    {
17
        $this->route = $request->get('route');
18
19
        return Resource::collection($this->tutorials());
0 ignored issues
show
Bug Best Practice introduced by
The expression return LaravelEnso\Tutor...ion($this->tutorials()) returns the type Illuminate\Http\Resource...ymousResourceCollection which is incompatible with the return type mandated by Illuminate\Contracts\Sup...sponsable::toResponse() of Symfony\Component\HttpFoundation\Response.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
20
    }
21
22
    private function tutorials()
23
    {
24
        return $this->homeTutorials()
25
            ->merge($this->routeTutorials());
26
    }
27
28
    private function homeTutorials()
29
    {
30
        $home = Permission::whereName(config('enso.tutorials.homePermission'))->first();
31
32
        return Tutorial::wherePermissionId(optional($home)->id)
33
            ->orderBy('order_index')
34
            ->get();
35
    }
36
37
    private function routeTutorials()
38
    {
39
        $permission = Permission::whereName($this->route)->first();
40
41
        return $permission
42
            ? $permission->tutorials()->orderBy('order_index')->get()
43
            : new Collection();
44
    }
45
}
46