PdfOptimizer::logger()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Mostafaznv\PdfOptimizer;
4
5
use Mostafaznv\PdfOptimizer\Actions\OptimizePdfAction;
6
use Mostafaznv\PdfOptimizer\Concerns\ExportsScript;
7
use Mostafaznv\PdfOptimizer\Concerns\PdfOptimizerProperties;
8
use Mostafaznv\PdfOptimizer\DTOs\OptimizeResult;
9
use Psr\Log\LoggerInterface;
10
11
12
class PdfOptimizer
13
{
14
    use PdfOptimizerProperties, ExportsScript;
0 ignored issues
show
introduced by
The trait Mostafaznv\PdfOptimizer\Concerns\ExportsScript requires some properties which are not provided by Mostafaznv\PdfOptimizer\PdfOptimizer: $name, $value
Loading history...
15
16
    private ?LoggerInterface $logger = null;
17
18
19
    public function __construct(
20
        private readonly string $gsBinary = 'gs',
21
    ) {}
22
23
    public static function init(string $gsBinary = 'gs'): self
24
    {
25
        return new self($gsBinary);
26
    }
27
28
29
    public function logger(LoggerInterface $logger): self
30
    {
31
        $this->logger = $logger;
32
33
        return $this;
34
    }
35
36
    public function optimize(string $pathToFile, string $pathToOptimizedFile): OptimizeResult
37
    {
38
        return OptimizePdfAction::init()
39
            ->logger($this->logger)
40
            ->setTimeout($this->timeout)
41
            ->execute(
42
                command: $this->command(),
43
                input: $pathToFile,
44
                output: $pathToOptimizedFile
45
            );
46
    }
47
}
48