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

Documents   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 54
ccs 0
cts 11
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 17 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\Template;
15
use Balloon\Filesystem;
16
use Balloon\Filesystem\Node\AttributeDecorator;
17
use Balloon\Filesystem\Node\Collection;
18
use Balloon\Server;
19
use Micro\Http\Response;
20
21
class Documents
22
{
23
    /**
24
     * Filesystem.
25
     *
26
     * @var Filesystem
27
     */
28
    protected $fs;
29
30
    /**
31
     * Server.
32
     *
33
     * @var Server
34
     */
35
    protected $server;
36
37
    /**
38
     * Decorator.
39
     *
40
     * @var AttributeDecorator
41
     */
42
    protected $decorator;
43
44
    /**
45
     * Constructor.
46
     */
47
    public function __construct(Server $server, AttributeDecorator $decorator)
48
    {
49
        $this->server = $server;
50
        $this->fs = $server->getFilesystem();
51
        $this->decorator = $decorator;
52
    }
53
54
    /**
55
     * Create new empty document.
56
     */
57
    public function post(string $name, string $type, ?string $collection = null, int $conflict = 0, ?bool $readonly = null, ?array $meta = null): Response
0 ignored issues
show
Unused Code introduced by
The parameter $conflict is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
    {
59
        $parent = $this->fs->getNode($collection, Collection::class, false, true);
60
        $tpl = new Template($type);
61
62
        $attributes = compact('readonly', 'meta');
63
        $attributes = array_filter($attributes, function ($attribute) {return !is_null($attribute); });
64
65
        $stream = $tpl->get();
66
        $storage = $parent->getStorage();
67
        $session = $storage->storeTemporaryFile($stream, $this->server->getIdentity());
68
        $result = $parent->addFile($name, $session, $attributes);
69
        fclose($stream);
70
        $result = $this->decorator->decorate($result);
71
72
        return (new Response())->setCode(201)->setBody($result);
73
    }
74
}
75