Discussion   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 6
dl 0
loc 68
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A discussable() 0 4 1
A filesDir() 0 4 1
A getFileName() 0 6 1
A getImageDimensions() 0 4 1
A scopeApproved() 0 8 2
1
<?php
2
3
namespace Faithgen\Discussions\Models;
4
5
use FaithGen\SDK\Models\UuidModel;
6
use FaithGen\SDK\Traits\Relationships\Belongs\BelongsToMinistryTrait;
7
use FaithGen\SDK\Traits\Relationships\Morphs\CommentableTrait;
8
use FaithGen\SDK\Traits\Relationships\Morphs\ImageableTrait;
9
use FaithGen\SDK\Traits\StorageTrait;
10
use FaithGen\SDK\Traits\TitleTrait;
11
12
class Discussion extends UuidModel
13
{
14
    use BelongsToMinistryTrait;
15
    use CommentableTrait;
16
    use ImageableTrait;
17
    use StorageTrait;
18
    use TitleTrait;
19
20
    protected $table = 'fg_discussions';
21
22
    /**
23
     * Relates this discussion to models using it.
24
     *
25
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
26
     */
27
    public function discussable()
28
    {
29
        return $this->morphTo();
30
    }
31
32
    /**
33
     * The directory name for the folder holding images.
34
     *
35
     * @return string
36
     */
37
    public function filesDir()
38
    {
39
        return 'discussions';
40
    }
41
42
    /**
43
     * The name(s) of image(s).
44
     *
45
     * @return mixed
46
     */
47
    public function getFileName()
48
    {
49
        return $this->images()
50
            ->pluck('name')
51
            ->toArray();
52
    }
53
54
    /**
55
     * The dimensions the discussion images has.
56
     *
57
     * @return array
58
     */
59
    public function getImageDimensions()
60
    {
61
        return [0, 100];
62
    }
63
64
    /**
65
     * Returns only approved discussions if being called from the app API.
66
     *
67
     * @param $query
68
     *
69
     * @return mixed
70
     */
71
    public function scopeApproved($query)
72
    {
73
        if (auth('web')->user()) {
0 ignored issues
show
Bug introduced by
The method user does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\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...
74
            return $query->whereApproved(true);
75
        }
76
77
        return $query;
78
    }
79
}
80