Files   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 18
c 4
b 0
f 0
dl 0
loc 66
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A show() 0 13 2
A detail() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Polidog\Chatwork\Api\Rooms;
6
7
use Polidog\Chatwork\Client\ClientInterface;
8
use Polidog\Chatwork\Entity\Collection\CollectionInterface;
9
use Polidog\Chatwork\Entity\Factory\FileFactory;
10
use Polidog\Chatwork\Entity\File;
11
12
/**
13
 * Class Files.
14
 */
15
class Files
16
{
17
    /**
18
     * @var ClientInterface
19
     */
20
    private $client;
21
22
    /**
23
     * @var FileFactory
24
     */
25
    private $factory;
26
27
    /**
28
     * @var int
29
     */
30
    private $roomId;
31
32
    /**
33
     * Files constructor.
34
     *
35
     * @param ClientInterface $client
36
     * @param FileFactory     $factory
37
     * @param int             $roomId
38
     */
39
    public function __construct(ClientInterface $client, FileFactory $factory, int $roomId)
40
    {
41
        $this->client = $client;
42
        $this->factory = $factory;
43
        $this->roomId = $roomId;
44
    }
45
46
    /**
47
     * @param null $accountId
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $accountId is correct as it would always require null to be passed?
Loading history...
48
     *
49
     * @return CollectionInterface
50
     */
51
    public function show($accountId = null)
52
    {
53
        $options = [
54
        ];
55
56
        if (!is_null($accountId)) {
0 ignored issues
show
introduced by
The condition is_null($accountId) is always true.
Loading history...
57
            $options['account_id'] = $accountId;
58
        }
59
60
        return $this->factory->collection(
61
            $this->client->get(
62
                "rooms/{$this->roomId}/files",
63
                $options
64
            )
65
        );
66
    }
67
68
    /**
69
     * @param $id
70
     * @param $downloadLink
71
     *
72
     * @return File
73
     */
74
    public function detail($id, $downloadLink = false)
75
    {
76
        return $this->factory->entity(
77
            $this->client->get(
78
                "rooms/{$this->roomId}/files/{$id}",
79
                [
80
                    'create_download_url' => (int) $downloadLink,
81
                ]
82
            )
83
        );
84
    }
85
}
86