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

Tokens::post()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 10
cp 0
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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\Wopi\Api\v2;
13
14
use Balloon\App\Wopi\SessionManager;
15
use Balloon\Filesystem;
16
use Balloon\Server;
17
use Micro\Http\Response;
18
19
class Tokens
20
{
21
    /**
22
     * Session manager.
23
     *
24
     * @var SessionManager
25
     */
26
    protected $manager;
27
28
    /**
29
     * Filesystem.
30
     *
31
     * @var Filesystem
32
     */
33
    protected $fs;
34
35
    /**
36
     * Constructor.
37
     */
38
    public function __construct(Server $server, SessionManager $manager)
39
    {
40
        $this->fs = $server->getFilesystem();
41
        $this->manager = $manager;
42
    }
43
44
    /**
45
     * Create session.
46
     */
47
    public function post(string $id): Response
48
    {
49
        $node = $this->fs->getNode($id);
50
        $session = $this->manager->create($node, $this->fs->getUser());
0 ignored issues
show
Compatibility introduced by
$node of type object<Balloon\Filesystem\Node\NodeInterface> is not a sub-type of object<Balloon\Filesystem\Node\File>. It seems like you assume a concrete implementation of the interface Balloon\Filesystem\Node\NodeInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
51
52
        return (new Response())->setCode(201)->setBody([
53
            'node' => (string) $node->getId(),
54
            'access_token' => $session->getAccessToken(),
55
            'ttl' => $session->getAccessTokenTTL(),
56
        ]);
57
    }
58
}
59