ProductMaker::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ReliqArts\Docweaver\Factory;
6
7
use ReliqArts\Docweaver\Contract\ConfigProvider;
8
use ReliqArts\Docweaver\Contract\Exception;
9
use ReliqArts\Docweaver\Contract\Filesystem;
10
use ReliqArts\Docweaver\Contract\Product\Maker;
11
use ReliqArts\Docweaver\Exception\InvalidDirectory;
12
use ReliqArts\Docweaver\Model\Product;
13
14
final class ProductMaker implements Maker
15
{
16
    /**
17
     * @var ConfigProvider
18
     */
19
    private $configProvider;
20
21
    /**
22
     * @var Filesystem
23
     */
24
    private $filesystem;
25
26
    /**
27
     * Factory constructor.
28
     */
29
    public function __construct(Filesystem $filesystem, ConfigProvider $configProvider)
30
    {
31
        $this->filesystem = $filesystem;
32
        $this->configProvider = $configProvider;
33
    }
34
35
    /**
36
     * @throws Exception if directory is invalid or product population fails
37
     */
38
    public function create(string $directory): Product
39
    {
40
        if (!$this->filesystem->isDirectory($directory)) {
41
            throw InvalidDirectory::forDirectory($directory);
42
        }
43
44
        $product = new Product($this->filesystem, $this->configProvider, $directory);
45
        $product->populate();
46
47
        return $product;
48
    }
49
}
50