These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\Office; |
||
13 | |||
14 | use Balloon\Filesystem\Node\File; |
||
15 | use MongoDB\BSON\UTCDateTime; |
||
16 | use MongoDB\Database; |
||
17 | |||
18 | class Document |
||
19 | { |
||
20 | /** |
||
21 | * Node. |
||
22 | * |
||
23 | * @var File |
||
24 | */ |
||
25 | protected $node; |
||
26 | |||
27 | /** |
||
28 | * Database. |
||
29 | * |
||
30 | * @var Database |
||
31 | */ |
||
32 | protected $db; |
||
33 | |||
34 | /** |
||
35 | * Get WOPI token. |
||
36 | */ |
||
37 | public function __construct(Database $db, File $node) |
||
38 | { |
||
39 | $this->node = $node; |
||
40 | $this->db = $db; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Get running sessions for document. |
||
45 | */ |
||
46 | public function getSessions(): Iterable |
||
47 | { |
||
48 | $result = $this->db->app_office_session->find([ |
||
49 | 'node' => $this->node->getId(), |
||
50 | 'ttl' => [ |
||
51 | '$gte' => new UTCDateTime(), |
||
52 | ], |
||
53 | ]); |
||
54 | |||
55 | return $result; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Get node. |
||
60 | */ |
||
61 | public function getNode(): File |
||
62 | { |
||
63 | return $this->node; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Get size. |
||
68 | */ |
||
69 | View Code Duplication | public function getSize(): int |
|
0 ignored issues
–
show
|
|||
70 | { |
||
71 | if (0 === $this->node->getSize()) { |
||
72 | return (new Template($this->node->getExtension()))->getSize(); |
||
73 | } |
||
74 | |||
75 | return $this->node->getSize(); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Get readable stream. |
||
80 | * |
||
81 | * @return resource |
||
82 | */ |
||
83 | View Code Duplication | public function get() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
84 | { |
||
85 | if (0 === $this->node->getSize()) { |
||
86 | return (new Template($this->node->getExtension()))->get(); |
||
87 | } |
||
88 | |||
89 | return $this->node->get(); |
||
90 | } |
||
91 | } |
||
92 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.