Completed
Push — master ( b97427...e235cc )
by Raffael
30:35 queued 26:08
created

Tokens   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 40
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A post() 0 11 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\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());
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