ProductMaker   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 10 2
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