Completed
Push — master ( e79a1a...3e0fb7 )
by Miguel
08:55
created

src/ConfigTrait.php (3 issues)

Labels
Severity

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
3
namespace SocialiteProviders\Manager;
4
5
use SocialiteProviders\Manager\Contracts\ConfigInterface;
6
7
trait ConfigTrait
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $config;
13
14
    /**
15
     * @param \SocialiteProviders\Manager\Contracts\OAuth1\ProviderInterface|\SocialiteProviders\Manager\Contracts\OAuth2\ProviderInterface $config
16
     */
17
    public function setConfig(ConfigInterface $config)
18
    {
19
        $config = $config->get();
20
21
        $this->config = $config;
22
        $this->clientId = $config['client_id'];
0 ignored issues
show
The property clientId 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...
23
        $this->clientSecret = $config['client_secret'];
0 ignored issues
show
The property clientSecret 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...
24
        $this->redirectUrl = $config['redirect'];
0 ignored issues
show
The property redirectUrl 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...
25
26
        return $this;
27
    }
28
29
    /**
30
     * @return array
31
     */
32
    public static function additionalConfigKeys()
33
    {
34
        return [];
35
    }
36
37
    /**
38
     * @param string $key
39
     * @param mixed  $default
40
     *
41
     * @return mixed|array
42
     */
43
    protected function getConfig($key = null, $default = null)
44
    {
45
        // check manually if a key is given and if it exists in the config
46
        // this has to be done to check for spoofed additional config keys so that null isn't returned
47
        if (!empty($key) && empty($this->config[$key])) {
48
            return $default;
49
        }
50
51
        return $key ? array_get($this->config, $key, $default) : $this->config;
52
    }
53
}
54