Config   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 220
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 15
eloc 36
c 5
b 0
f 0
dl 0
loc 220
ccs 33
cts 36
cp 0.9167
rs 10

15 Methods

Rating   Name   Duplication   Size   Complexity  
A setDocType() 0 5 1
A setPort() 0 5 1
A getMaxLoop() 0 3 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 setMaxLoop() 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
     * For unoconv webservice this value is the timeout [sec] for curl request
53
     *
54
     * @var int
55
     */
56
    protected $timeout = 30;
57
    /**
58
     * @var string
59
     */
60
    protected $options = 'urp;StarOffice.ComponentContext';
61
    /** @noinspection PhpUndefinedClassInspection */
62
    /**
63
     * @var \Psr\Log\LoggerInterface
64
     */
65
    protected $logger;
66
    /**
67
     * Webservice url
68
     *
69
     * @see https://hub.docker.com/r/zrrrzzt/docker-unoconv-webservice
70
     *
71
     * @var string
72
     */
73
    protected $webservice = 'http://localhost:3000';
74
    /**
75
     * Max loop couter for
76
     *
77
     * @var int
78
     */
79
    protected $maxLoop = 3;
80
81
    /**
82
     * Config constructor.
83 10
     * Default values;
84
     *
85 10
     * @param array $config
86 10
     *
87 10
     * @throws \Mrcnpdlk\Lib\ConfigurationException
88 9
     */
89
    public function __construct(array $config = [])
90
    {
91
        $this->docType = DocType::DOCUMENT();
92
        $this->format  = FormatType::PDF();
93 6
        parent::__construct($config);
94
    }
95 6
96
    /**
97
     * @return string
98
     */
99
    public function getConnectionString(): string
100
    {
101 7
        return sprintf('%s --connection="socket,host=%s,port=%s;%s"', $this->binary, $this->host, $this->port, $this->options);
102
    }
103 7
104
    /**
105
     * @return DocType
106
     */
107
    public function getDocType(): DocType
108
    {
109 7
        return $this->docType;
110
    }
111 7
112
    /**
113
     * @param DocType $docType
114
     *
115
     * @return $this
116
     */
117 7
    public function setDocType(DocType $docType): self
118
    {
119 7
        $this->docType = $docType;
120
121
        return $this;
122
    }
123
124
    /**
125 6
     * @return FormatType
126
     */
127 6
    public function getFormat(): FormatType
128
    {
129
        return $this->format;
130
    }
131
132
    /**
133
     * @param FormatType $format
134
     *
135 4
     * @return $this
136
     */
137 4
    public function setFormat(FormatType $format): self
138
    {
139 4
        $this->format = $format;
140
141
        return $this;
142
    }
143
144
    /**
145
     * @return int
146
     */
147 1
    public function getMaxLoop(): int
148
    {
149 1
        return $this->maxLoop;
150
    }
151 1
152
    /**
153
     * @param int $maxLoop
154
     *
155
     * @return $this
156
     */
157
    public function setMaxLoop(int $maxLoop): self
158
    {
159 1
        $this->maxLoop = $maxLoop;
160
161 1
        return $this;
162
    }
163 1
164
    /**
165
     * @return int
166
     */
167
    public function getTimeout(): int
168
    {
169
        return $this->timeout;
170
    }
171 1
172
    /**
173 1
     * @param int $timeout
174
     *
175 1
     * @return $this
176
     */
177
    public function setTimeout(int $timeout): self
178
    {
179
        $this->timeout = $timeout;
180
181
        return $this;
182
    }
183 1
184
    /**
185 1
     * @return string
186
     */
187 1
    public function getWebservice(): string
188
    {
189
        return $this->webservice;
190
    }
191
192
    /**
193
     * @param string $webservice
194
     *
195 1
     * @return Config
196
     */
197 1
    public function setWebservice(string $webservice): Config
198
    {
199 1
        $this->webservice = $webservice;
200
201
        return $this;
202
    }
203
204
    /**
205
     * @param string $binary
206
     *
207
     * @return $this
208
     */
209
    public function setBinary(string $binary): self
210
    {
211
        $this->binary = $binary;
212
213
        return $this;
214
    }
215
216
    /**
217
     * @param string $host
218
     *
219
     * @return $this
220
     */
221
    public function setHost(string $host): self
222
    {
223
        $this->host = $host;
224
225
        return $this;
226
    }
227
228
    /**
229
     * @param int $port
230
     *
231
     * @return $this
232
     */
233
    public function setPort(int $port): self
234
    {
235
        $this->port = $port;
236
237
        return $this;
238
    }
239
}
240