Completed
Push — master ( e6463a...a91b31 )
by Ryan
02:20
created

DashboardCollection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 46
c 3
b 1
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A allowed() 0 16 3
A find() 0 13 3
1
<?php namespace Anomaly\DashboardModule\Dashboard;
2
3
use Anomaly\DashboardModule\Dashboard\Contract\DashboardInterface;
4
use Anomaly\Streams\Platform\Entry\EntryCollection;
5
use Anomaly\UsersModule\User\Contract\UserInterface;
6
use Illuminate\Database\Eloquent\Model;
7
8
/**
9
 * Class DashboardCollection
10
 *
11
 * @link          http://pyrocms.com/
12
 * @author        PyroCMS, Inc. <[email protected]>
13
 * @author        Ryan Thompson <[email protected]>
14
 * @package       Anomaly\DashboardModule\Dashboard
15
 */
16
class DashboardCollection extends EntryCollection
17
{
18
19
    /**
20
     * Return only allowed dashboards.
21
     *
22
     * @return DashboardCollection
23
     */
24
    public function allowed()
25
    {
26
        /* @var UserInterface $user */
27
        if (!$user = app('auth')->user()) {
28
            return $this->make([]);
29
        }
30
31
        return $this->filter(
32
            function (DashboardInterface $dashboard) use ($user) {
33
34
                $roles = $dashboard->getAllowedRoles();
35
36
                return $roles->isEmpty() ?: $user->hasAnyRole($roles);
37
            }
38
        );
39
    }
40
41
    /**
42
     * Find a model in the collection by key.
43
     *
44
     * @param  mixed $key
45
     * @param  mixed $default
46
     * @return \Illuminate\Database\Eloquent\Model
47
     */
48
    public function find($key, $default = null)
49
    {
50
        if ($key instanceof Model) {
0 ignored issues
show
Bug introduced by
The class Illuminate\Database\Eloquent\Model does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
51
            $key = $key->getKey();
52
        }
53
54
        return $this->first(
55
            function ($index, DashboardInterface $model) use ($key) {
56
                return $model->getId() == $key || $model->getSlug() == $key;
57
            },
58
            $default
59
        );
60
    }
61
}
62