DocuGenerator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ublaboo\Anabelle\Generator;
6
7
use Ublaboo\Anabelle\Console\Utils\Logger;
8
use Ublaboo\Anabelle\Generator\Exception\DocuFileGeneratorException;
9
use Ublaboo\Anabelle\Generator\Exception\DocuGeneratorException;
10
use Ublaboo\Anabelle\Http\AuthCredentials;
11
use Ublaboo\Anabelle\Markdown\DocuScope;
12
use Ublaboo\Anabelle\Markdown\Parser;
13
14
final class DocuGenerator
15
{
16
17
	/**
18
	 * @var string
19
	 */
20
	private $inputDirectory;
21
22
	/**
23
	 * @var string
24
	 */
25
	private $outputDirectory;
26
27
	/**
28
	 * @var AuthCredentials
29
	 */
30
	private $authCredentials;
31
32
	/**
33
	 * @var Logger
34
	 */
35
	private $logger;
36
37
	/**
38
	 * @var Parser
39
	 */
40
	private $parser;
41
42
43
	public function __construct(
44
		string $inputDirectory,
45
		string $outputDirectory,
46
		AuthCredentials $authCredentials,
47
		Logger $logger
48
	) {
49
		$this->inputDirectory = $inputDirectory;
50
		$this->outputDirectory = $outputDirectory;
51
		$this->authCredentials = $authCredentials;
52
		$this->logger = $logger;
53
54
		$this->parser = new Parser(
55
			true,
56
			$authCredentials,
57
			$logger,
58
			new DocuScope($outputDirectory)
59
		);
60
	}
61
62
63
	/**
64
	 * @throws DocuGeneratorException
65
	 * @throws DocuFileGeneratorException
66
	 */
67
	public function run(): void
68
	{
69
		$fileType = $this->authCredentials->getUser() ? 'php' : 'html';
70
71
		$this->parser->parseFile(
72
			$this->inputDirectory . '/index.md',
73
			$this->outputDirectory . "/index.{$fileType}"
74
		);
75
	}
76
}
77