Passed
Push — master ( 4a474d...df1b75 )
by Stephen
02:14
created

UserNotificationSubscriptionQuery::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 9
c 1
b 1
f 0
nc 2
nop 0
dl 0
loc 16
rs 9.9666
1
<?php
2
3
namespace Sfneal\Users\Queries;
4
5
use Sfneal\Users\Builders\UserNotificationBuilder;
6
use Sfneal\Users\Models\User;
7
use Illuminate\Database\Eloquent\Collection;
8
use Sfneal\Caching\Traits\Cacheable;
9
use Sfneal\PostOffice\Notifications\AbstractNotification;
0 ignored issues
show
Bug introduced by
The type Sfneal\PostOffice\Notifi...ns\AbstractNotification was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Sfneal\Queries\AbstractQuery;
11
12
class UserNotificationSubscriptionQuery extends AbstractQuery
13
{
14
    use Cacheable;
15
16
    /**
17
     * @var string
18
     */
19
    private $notification;
20
21
    /**
22
     * UserNotificationSubscriptionQuery constructor.
23
     *
24
     * @param AbstractNotification $notification
25
     */
26
    public function __construct(AbstractNotification $notification)
27
    {
28
        $this->notification = getClassName($notification);
0 ignored issues
show
Bug introduced by
The function getClassName was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        $this->notification = /** @scrutinizer ignore-call */ getClassName($notification);
Loading history...
29
    }
30
31
    /**
32
     * Retrieve a Collection of User's that are subscribed to a Notification.
33
     *
34
     *  - only return user 'Stephen Neal' if environment is not 'production'
35
     *
36
     * @return Collection|int|mixed
37
     */
38
    public function execute()
39
    {
40
        // Production environment
41
        if (env('APP_ENV') == 'production') {
0 ignored issues
show
introduced by
The condition env('APP_ENV') == 'production' is always false.
Loading history...
42
            return User::query()
43
                ->whereHas('notificationSubscriptions', function (UserNotificationBuilder $builder) {
44
                    $builder->whereType($this->notification);
45
                })
46
                ->get();
47
        }
48
49
        // Development environment
50
        else {
51
            return User::query()
52
                ->whereUser(38)
53
                ->get();
54
        }
55
    }
56
57
    /**
58
     * Retrieve the Query cache key.
59
     *
60
     * @return string
61
     */
62
    public function cacheKey(): string
63
    {
64
        return "user:notification:subscription#{$this->notification}";
65
    }
66
}
67