These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace STS\StorageConnect\Models\Concerns; |
||
3 | |||
4 | use STS\StorageConnect\Drivers\AbstractAdapter; |
||
5 | use STS\StorageConnect\StorageConnectFacade; |
||
6 | |||
7 | trait HasStorageAdapter |
||
8 | { |
||
9 | /** |
||
10 | * @var |
||
11 | */ |
||
12 | protected $adapter; |
||
13 | |||
14 | /** |
||
15 | * @param null $redirectUrl |
||
16 | * |
||
17 | * @return \Illuminate\Http\RedirectResponse |
||
18 | */ |
||
19 | public function authorize($redirectUrl = null) |
||
20 | { |
||
21 | return $this->adapter()->authorize($this, $redirectUrl); |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * @return AbstractAdapter |
||
26 | */ |
||
27 | public function adapter() |
||
28 | { |
||
29 | if (!$this->adapter) { |
||
30 | $this->adapter = StorageConnectFacade::adapter($this->driver)->setToken((array)$this->token, function ($token) { |
||
0 ignored issues
–
show
|
|||
31 | $this->update(['token' => $token]); |
||
0 ignored issues
–
show
It seems like
update() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the
Loading history...
|
|||
32 | }); |
||
33 | } |
||
34 | |||
35 | return $this->adapter; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @return array |
||
40 | */ |
||
41 | public function __sleep() |
||
42 | { |
||
43 | $this->adapter = null; |
||
44 | |||
45 | return array_keys(get_object_vars($this)); |
||
46 | } |
||
47 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: