Completed
Push — master ( 9003e7...f2c4d3 )
by ReliQ
04:59
created

ProductMaker::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ReliQArts\Docweaver\Factories;
6
7
use ReliQArts\Docweaver\Contracts\ConfigProvider;
8
use ReliQArts\Docweaver\Contracts\Exception;
9
use ReliQArts\Docweaver\Contracts\Filesystem;
10
use ReliQArts\Docweaver\Contracts\Product\Maker;
11
use ReliQArts\Docweaver\Exceptions\InvalidDirectory;
12
use ReliQArts\Docweaver\Models\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
     * @param Filesystem     $filesystem
30
     * @param ConfigProvider $configProvider
31
     */
32
    public function __construct(Filesystem $filesystem, ConfigProvider $configProvider)
33
    {
34
        $this->filesystem = $filesystem;
35
        $this->configProvider = $configProvider;
36
    }
37
38
    /**
39
     * @param string $directory
40
     *
41
     * @throws Exception if directory is invalid
42
     *
43
     * @return Product
44
     */
45
    public function create(string $directory): Product
46
    {
47
        if (!$this->filesystem->isDirectory($directory)) {
48
            throw InvalidDirectory::forDirectory($directory);
49
        }
50
51
        $product = new Product($this->filesystem, $this->configProvider, $directory);
52
        $product->populate();
53
54
        return $product;
55
    }
56
}
57