Completed
Push — master ( 6e52f0...d9a404 )
by Alexandre
02:29
created

NativeApplication::useImplicit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 0
cts 3
cp 0
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Alexandre
5
 * Date: 30/12/2017
6
 * Time: 17:02
7
 */
8
9
namespace OAuth2OLD\Role\Client;
10
11
use OAuth2OLD\Role\Client\Type\PublicClient;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, OAuth2OLD\Role\Client\PublicClient. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
12
13
14
/**
15
 * Class NativeApplication
16
 * @package OAuth2\roles\clients
17
 *
18
 * @see https://tools.ietf.org/html/rfc6749#section-2.1
19
 *
20
 * Client Types
21
 *
22
 *     A native application is a public client installed and executed on
23
 * the device used by the resource owner.  Protocol data and
24
 * credentials are accessible to the resource owner.  It is assumed
25
 * that any client authentication credentials included in the
26
 * application can be extracted.  On the other hand, dynamically
27
 * issued credentials such as access tokens or refresh tokens can
28
 * receive an acceptable level of protection.  At a minimum, these
29
 * credentials are protected from hostile servers with which the
30
 * application may interact.  On some platforms, these credentials
31
 * might be protected from other applications residing on the same
32
 * device.
33
 */
34
class NativeApplication extends PublicClient
35
{
36
37
    /**
38
     * @var bool
39
     */
40
    private $useImplicit;
41
42
    public function __construct($identifier, array $redirectUris = null, bool $useImplicit = false)
43
    {
44
        parent::__construct($identifier, $redirectUris);
0 ignored issues
show
Bug introduced by
The call to OAuth2OLD\Role\Client\Re...edClient::__construct() has too few arguments starting with supportedScopes. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
        parent::/** @scrutinizer ignore-call */ 
45
                __construct($identifier, $redirectUris);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
45
        $this->useImplicit = $useImplicit;
46
    }
47
48
    function useImplicit(): bool
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
49
    {
50
        return $this->useImplicit;
51
    }
52
}