TelefonicaPolicy   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 78
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 8 2
A get() 0 4 1
A hasAccessToTelefonica() 0 16 5
A update() 0 4 1
A delete() 0 4 1
1
<?php
2
3
namespace Telefonica\Http\Policies;
4
5
use App\Models\User;
6
7
/**
8
 * Class TelefonicaPolicy.
9
 *
10
 * @package Finder\Http\Policies
11
 */
12
class TelefonicaPolicy
13
{
14
    /**
15
     * Create a telefonica.
16
     *
17
     * @param  User   $authUser
18
     * @param  string $telefonicaClass
19
     * @return bool
20
     */
21
    public function create(User $authUser, string $telefonicaClass)
0 ignored issues
show
Unused Code introduced by
The parameter $telefonicaClass 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 telefonica.
32
     *
33
     * @param  User  $authUser
34
     * @param  mixed $telefonica
35
     * @return bool
36
     */
37
    public function get(User $authUser, $telefonica)
38
    {
39
        return $this->hasAccessToTelefonica($authUser, $telefonica);
40
    }
41
42
    /**
43
     * Determine if an authenticated user has access to a telefonica.
44
     *
45
     * @param  User $authUser
46
     * @param  $telefonica
47
     * @return bool
48
     */
49
    private function hasAccessToTelefonica(User $authUser, $telefonica): bool
50
    {
51
        if ($authUser->toEntity()->isAdministrator()) {
52
            return true;
53
        }
54
55
        if ($telefonica instanceof User && $authUser->id === optional($telefonica)->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($telefonica)->created_by_user_id) {
60
            return true;
61
        }
62
63
        return false;
64
    }
65
66
    /**
67
     * Update a telefonica.
68
     *
69
     * @param  User  $authUser
70
     * @param  mixed $telefonica
71
     * @return bool
72
     */
73
    public function update(User $authUser, $telefonica)
74
    {
75
        return $this->hasAccessToTelefonica($authUser, $telefonica);
76
    }
77
78
    /**
79
     * Delete a telefonica.
80
     *
81
     * @param  User  $authUser
82
     * @param  mixed $telefonica
83
     * @return bool
84
     */
85
    public function delete(User $authUser, $telefonica)
86
    {
87
        return $this->hasAccessToTelefonica($authUser, $telefonica);
88
    }
89
}
90