Test Failed
Pull Request — master (#350)
by Raffael
26:39
created

Devices   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 50
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A post() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * balloon
7
 *
8
 * @copyright   Copryright (c) 2012-2019 gyselroth GmbH (https://gyselroth.com)
9
 * @license     GPL-3.0 https://opensource.org/licenses/GPL-3.0
10
 */
11
12
namespace Balloon\App\Webauthn\Api\v2;
13
14
use Balloon\App\Webauthn\CreationChallenge\CreationChallengeFactory;
15
use Balloon\App\Webauthn\Device\DeviceFactory;
16
use Balloon\Server;
17
use Micro\Http\Response;
18
use MongoDB\BSON\ObjectId;
19
20
class Devices
21
{
22
    /**
23
     * DeviceFactory.
24
     *
25
     * @var DeviceFactory
26
     */
27
    protected $device_factory;
28
29
    /**
30
     * CreationChallengeFactory.
31
     *
32
     * @var CreationChallengeFactory
33
     */
34
    protected $creation_challenge_factory;
35
36
    /**
37
     * Server.
38
     *
39
     * @var Server
40
     */
41
    protected $server;
42
43
    /**
44
     * Initialize.
45
     */
46
    public function __construct(DeviceFactory $device_factory, CreationChallengeFactory $creation_challenge_factory, Server $server)
47
    {
48
        $this->device_factory = $device_factory;
49
        $this->creation_challenge_factory = $creation_challenge_factory;
50
        $this->server = $server;
51
    }
52
53
    /**
54
     * Devices endpoint.
55
     */
56
    public function post(string $id, string $type, string $rawId, array $response, ObjectId $challenge): Response
57
    {
58
        $challenge = $this->creation_challenge_factory->getOne($challenge);
59
60
        $device = $this->device_factory->create($challenge, [
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $device is correct as $this->device_factory->c...esponse' => $response)) (which targets Balloon\App\Webauthn\Dev...DeviceFactory::create()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$device is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
61
            'id' => $id,
62
            'type' => $type,
63
            'rawId' => $rawId,
64
            'response' => $response,
65
        ]);
66
67
        return (new Response())->setCode(201)->setBody([]);
68
    }
69
}
70