IntegrationsPolicy::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Integrations\Http\Policies;
4
5
use App\Models\User;
6
7
/**
8
 * Class IntegrationsPolicy.
9
 *
10
 * @package Finder\Http\Policies
11
 */
12
class IntegrationsPolicy
13
{
14
    /**
15
     * Create a integrations.
16
     *
17
     * @param  User   $authUser
18
     * @param  string $integrationsClass
19
     * @return bool
20
     */
21
    public function create(User $authUser, string $integrationsClass)
0 ignored issues
show
Unused Code introduced by
The parameter $integrationsClass is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22
    {
23
        if ($authUser->toEntity()->isAdministrator()) {
24
            return true;
25
        }
26
27
        return false;
28
    }
29
30
    /**
31
     * Get a integrations.
32
     *
33
     * @param  User  $authUser
34
     * @param  mixed $integrations
35
     * @return bool
36
     */
37
    public function get(User $authUser, $integrations)
38
    {
39
        return $this->hasAccessToIntegrations($authUser, $integrations);
40
    }
41
42
    /**
43
     * Determine if an authenticated user has access to a integrations.
44
     *
45
     * @param  User $authUser
46
     * @param  $integrations
47
     * @return bool
48
     */
49
    private function hasAccessToIntegrations(User $authUser, $integrations): bool
50
    {
51
        if ($authUser->toEntity()->isAdministrator()) {
52
            return true;
53
        }
54
55
        if ($integrations instanceof User && $authUser->id === optional($integrations)->id) {
0 ignored issues
show
Bug introduced by
The class App\Models\User 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...
56
            return true;
57
        }
58
59
        if ($authUser->id === optional($integrations)->created_by_user_id) {
60
            return true;
61
        }
62
63
        return false;
64
    }
65
66
    /**
67
     * Update a integrations.
68
     *
69
     * @param  User  $authUser
70
     * @param  mixed $integrations
71
     * @return bool
72
     */
73
    public function update(User $authUser, $integrations)
74
    {
75
        return $this->hasAccessToIntegrations($authUser, $integrations);
76
    }
77
78
    /**
79
     * Delete a integrations.
80
     *
81
     * @param  User  $authUser
82
     * @param  mixed $integrations
83
     * @return bool
84
     */
85
    public function delete(User $authUser, $integrations)
86
    {
87
        return $this->hasAccessToIntegrations($authUser, $integrations);
88
    }
89
}
90