Passed
Pull Request — master (#12)
by Marcin
04:13
created

Config   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 192
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 13
eloc 32
dl 0
loc 192
rs 10
c 0
b 0
f 0
ccs 33
cts 36
cp 0.9167

13 Methods

Rating   Name   Duplication   Size   Complexity  
A setPort() 0 5 1
A setDocType() 0 5 1
A setBinary() 0 5 1
A setFormat() 0 5 1
A getTimeout() 0 3 1
A getConnectionString() 0 3 1
A setTimeout() 0 5 1
A getDocType() 0 3 1
A __construct() 0 5 1
A setWebservice() 0 5 1
A setHost() 0 5 1
A getWebservice() 0 3 1
A getFormat() 0 3 1
1
<?php
2
3
/**
4
 * Created by Marcin.
5
 * Date: 03.03.2019
6
 * Time: 14:22
7
 */
8
9
namespace Mrcnpdlk\Api\Unoconv;
10
11
use Mrcnpdlk\Api\Unoconv\Enum\DocType;
12
use Mrcnpdlk\Api\Unoconv\Enum\FormatType;
13
use Mrcnpdlk\Lib\ConfigurationOptionsAbstract;
14
15
/**
16
 * Class Config
17
 */
18
class Config extends ConfigurationOptionsAbstract
19
{
20
    /**
21
     * @var string
22
     */
23
    protected $binary = '/usr/bin/unoconv';
24
    /**
25
     * @var string
26
     */
27
    protected $host = 'localhost';
28
    /**
29
     * Port to listen on (as listener) or to connect to (as client).
30
     *
31
     * @var int
32
     */
33
    protected $port = 2002;
34
    /**
35
     * Specify the LibreOffice document type of the backend format. Possible document types are: document, graphics, presentation,
36
     * spreadsheet.
37
     *
38
     * @var DocType
39
     */
40
    protected $docType;
41
    /**
42
     * Specify the output format for the document. You can get a list of possible output formats per document type by using the --show
43
     * option.
44
     *
45
     * @var FormatType
46
     */
47
    protected $format;
48
    /**
49
     * When unoconv starts its own listener, try to connect to it for an amount of seconds before giving up. Increasing this may help when
50
     * you receive random errors caused by the listener not being ready to accept conversion jobs.
51
     *
52
     * @var int
53
     */
54
    protected $timeout = 30;
55
    /**
56
     * @var string
57
     */
58
    protected $options = 'urp;StarOffice.ComponentContext';
59
    /** @noinspection PhpUndefinedClassInspection */
60
    /**
61
     * @var \Psr\Log\LoggerInterface
62
     */
63
    protected $logger;
64
    /**
65
     * Webservice url
66
     *
67
     * @see https://hub.docker.com/r/zrrrzzt/docker-unoconv-webservice
68
     *
69
     * @var string
70
     */
71
    protected $webservice = 'http://localhost:3000';
72
73
    /**
74
     * Config constructor.
75
     * Default values;
76
     *
77
     * @param array $config
78
     *
79
     * @throws \Mrcnpdlk\Lib\ConfigurationException
80
     */
81 10
    public function __construct(array $config = [])
82
    {
83 10
        $this->docType = DocType::DOCUMENT();
84 10
        $this->format  = FormatType::PDF();
85 10
        parent::__construct($config);
86 9
    }
87
88
    /**
89
     * @return string
90
     */
91 6
    public function getConnectionString(): string
92
    {
93 6
        return sprintf('%s --connection="socket,host=%s,port=%s;%s"', $this->binary, $this->host, $this->port, $this->options);
94
    }
95
96
    /**
97
     * @return DocType
98
     */
99 7
    public function getDocType(): DocType
100
    {
101 7
        return $this->docType;
102
    }
103
104
    /**
105
     * @return FormatType
106
     */
107 7
    public function getFormat(): FormatType
108
    {
109 7
        return $this->format;
110
    }
111
112
    /**
113
     * @return int
114
     */
115 7
    public function getTimeout(): int
116
    {
117 7
        return $this->timeout;
118
    }
119
120
    /**
121
     * @return string
122
     */
123 6
    public function getWebservice(): string
124
    {
125 6
        return $this->webservice;
126
    }
127
128
    /**
129
     * @param string $binary
130
     *
131
     * @return $this
132
     */
133 4
    public function setBinary(string $binary): self
134
    {
135 4
        $this->binary = $binary;
136
137 4
        return $this;
138
    }
139
140
    /**
141
     * @param DocType $docType
142
     *
143
     * @return $this
144
     */
145 1
    public function setDocType(DocType $docType): self
146
    {
147 1
        $this->docType = $docType;
148
149 1
        return $this;
150
    }
151
152
    /**
153
     * @param FormatType $format
154
     *
155
     * @return $this
156
     */
157 1
    public function setFormat(FormatType $format): self
158
    {
159 1
        $this->format = $format;
160
161 1
        return $this;
162
    }
163
164
    /**
165
     * @param string $host
166
     *
167
     * @return $this
168
     */
169 1
    public function setHost(string $host): self
170
    {
171 1
        $this->host = $host;
172
173 1
        return $this;
174
    }
175
176
    /**
177
     * @param int $port
178
     *
179
     * @return $this
180
     */
181 1
    public function setPort(int $port): self
182
    {
183 1
        $this->port = $port;
184
185 1
        return $this;
186
    }
187
188
    /**
189
     * @param int $timeout
190
     *
191
     * @return $this
192
     */
193 1
    public function setTimeout(int $timeout): self
194
    {
195 1
        $this->timeout = $timeout;
196
197 1
        return $this;
198
    }
199
200
    /**
201
     * @param string $webservice
202
     *
203
     * @return Config
204
     */
205
    public function setWebservice(string $webservice): Config
206
    {
207
        $this->webservice = $webservice;
208
209
        return $this;
210
    }
211
}
212