Client   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A compressFile() 0 7 3
A compressBuffer() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\TinyPngBundle\Client;
6
7
class Client implements ClientInterface
8
{
9
    /**
10
     * @param string      $apiKey
11
     * @param null|string $proxy
12
     */
13
    public function __construct(string $apiKey, ?string $proxy)
14
    {
15
        \Tinify\Tinify::setKey($apiKey);
16
        \Tinify\Tinify::setProxy($proxy);
17
    }
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function compressBuffer(string $buffer): string
23
    {
24
        return \Tinify\fromBuffer($buffer)->toBuffer();
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function compressFile(\SplFileInfo $input, \SplFileInfo $output, bool $overwrite = true): void
31
    {
32
        if (!$overwrite && $output->isFile()) {
33
            throw new \RuntimeException('The file '.$output->getPathname().' already exists and the overwrite option is false');
34
        }
35
36
        \Tinify\fromFile($input->getPathname())->toFile($output->getPathname());
37
    }
38
}
39