Passed
Push — master ( 345d4b...1543d0 )
by Petr
03:07 queued 48s
created

Factory::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 9
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
namespace kalanis\kw_images\Access;
4
5
6
use kalanis\kw_files\Access\CompositeAdapter;
7
use kalanis\kw_files\Extended\Config;
8
use kalanis\kw_files\Extended\Processor;
9
use kalanis\kw_images\Content\BasicOperations;
10
use kalanis\kw_images\Content\Dirs;
11
use kalanis\kw_images\Content\Images;
12
use kalanis\kw_images\Content\ImageUpload;
13
use kalanis\kw_images\ImagesException;
14
use kalanis\kw_images\Interfaces\IIMTranslations;
15
use kalanis\kw_images\Traits\TLang;
16
use kalanis\kw_images\Content;
17
use kalanis\kw_images\Graphics;
18
use kalanis\kw_images\Sources;
19
use kalanis\kw_mime\Check;
20
use kalanis\kw_mime\Interfaces\IMime;
21
22
23
/**
24
 * Class Files
25
 * Operations over files
26
 * @package kalanis\kw_images\Access
27
 */
28
class Factory
29
{
30
    use TLang;
31
32
    protected CompositeAdapter $composite;
33
    protected IMime $mime;
34
35 4
    public function __construct(
36
        CompositeAdapter $compositeAdapter,
37
        ?IMime $mime = null,
38
        ?IIMTranslations $imLang = null
39
    )
40
    {
41 4
        $this->setImLang($imLang);
42 4
        $this->composite = $compositeAdapter;
43 4
        $this->mime = $mime ?: new Check\CustomList();
44 4
    }
45
46
    /**
47
     * @param array<string, string|int> $params
48
     * @return BasicOperations
49
     */
50 1
    public function getOperations(array $params = []): BasicOperations
51
    {
52 1
        $fileConf = (new Config())->setData($params);
53 1
        return new BasicOperations(  // operations with images
54 1
            new Sources\Image($this->composite, $fileConf, $this->getImLang()),
55 1
            new Sources\Thumb($this->composite, $fileConf, $this->getImLang()),
56 1
            new Sources\Desc($this->composite, $fileConf, $this->getImLang())
57
        );
58
    }
59
60
    /**
61
     * @param array<string, string|int> $params
62
     * @throws ImagesException
63
     * @return Dirs
64
     */
65 1
    public function getDirs(array $params = []): Dirs
66
    {
67 1
        $fileConf = (new Config())->setData($params);
68 1
        return new Dirs(
69 1
            new Content\ImageSize(
70 1
                new Graphics(
71 1
                    new Graphics\Processor(
72 1
                        new Graphics\Format\Factory(),
73 1
                        $this->getImLang()
74
                    ),
75 1
                    $this->mime,
76 1
                    $this->getImLang()
77
                ),
78 1
                (new Graphics\ThumbConfig())->setData($params),
79 1
                new Sources\Image($this->composite, $fileConf, $this->getImLang()),
80 1
                $this->getImLang()
81
            ),
82 1
            new Sources\Thumb($this->composite, $fileConf, $this->getImLang()),
83 1
            new Sources\DirDesc($this->composite, $fileConf, $this->getImLang()),
84 1
            new Sources\DirThumb($this->composite, $fileConf, $this->getImLang()),
85 1
            new Processor($this->composite, $fileConf),
86 1
            $this->getImLang()
87
        );
88
    }
89
90
    /**
91
     * @param array<string, string|int> $params
92
     * @throws ImagesException
93
     * @return Images
94
     */
95 1
    public function getImages(array $params = []): Images
96
    {
97 1
        $fileConf = (new Config())->setData($params);
98 1
        $image = new Sources\Image($this->composite, $fileConf, $this->getImLang());
99 1
        return new Images(
100 1
            new Content\ImageSize(
101 1
                new Graphics(
102 1
                    new Graphics\Processor(
103 1
                        new Graphics\Format\Factory(),
104 1
                        $this->getImLang()
105
                    ),
106 1
                    $this->mime,
107 1
                    $this->getImLang()
108
                ),
109 1
                (new Graphics\ThumbConfig())->setData($params),
110
                $image,
111 1
                $this->getImLang()
112
            ),
113
            $image,
114 1
            new Sources\Thumb($this->composite, $fileConf, $this->getImLang()),
115 1
            new Sources\Desc($this->composite, $fileConf, $this->getImLang())
116
        );
117
    }
118
119
    /**
120
     * @param array<string, string|int> $params
121
     * @throws ImagesException
122
     * @return ImageUpload
123
     */
124 1
    public function getUpload(array $params = []): ImageUpload
125
    {
126 1
        $fileConf = (new Config())->setData($params);
127 1
        $graphics = new Graphics(
128 1
            new Graphics\Processor(
129 1
                new Graphics\Format\Factory(),
130 1
                $this->getImLang()
131
            ),
132 1
            $this->mime,
133 1
            $this->getImLang()
134
        );
135 1
        $image = new Sources\Image($this->composite, $fileConf, $this->getImLang());
136 1
        return new ImageUpload(  // process uploaded images
137 1
            $graphics,
138
            $image,
139 1
            (new Graphics\ImageConfig())->setData($params),
140 1
            new Images(
141 1
                new Content\ImageSize(
142 1
                    $graphics,
143 1
                    (new Graphics\ThumbConfig())->setData($params),
144
                    $image,
145 1
                    $this->getImLang()
146
                ),
147 1
                new Sources\Image($this->composite, $fileConf, $this->getImLang()),
148 1
                new Sources\Thumb($this->composite, $fileConf, $this->getImLang()),
149 1
                new Sources\Desc($this->composite, $fileConf, $this->getImLang())
150
            )
151
        );
152
    }
153
}
154