Completed
Push — master ( 2c4f4a...51d604 )
by Joseph
01:42
created

src/Models/Concerns/HasStorageAdapter.php (2 issues)

Labels

Upgrade to new PHP Analysis Engine

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
The property driver does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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 Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

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
}