Completed
Push — master ( 209992...5259ee )
by Paweł
02:43
created

AbstractOutput::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Wszetko Sitemap.
7
 *
8
 * (c) Paweł Kłopotek-Główczewski <[email protected]>
9
 *
10
 * This source file is subject to the MIT license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13
14
namespace Wszetko\Sitemap\Drivers\Output;
15
16
use InvalidArgumentException;
17
use Wszetko\Sitemap\Interfaces\XML;
18
use Wszetko\Sitemap\Traits\Domain;
19
use Wszetko\Sitemap\Traits\IsAssoc;
20
21
/**
22
 * Class AbstractXML.
23
 *
24
 * @package Wszetko\Sitemap\Drivers\XML
25
 */
26
abstract class AbstractOutput implements XML
27
{
28
    use IsAssoc;
29
    use Domain;
30
31
    /**
32
     * Name of current sitemap.
33
     *
34
     * @var string
35
     */
36
    private $currentSitemap;
37
38
    /**
39
     * Path of current work directory.
40
     *
41
     * @var null|string
42
     */
43
    private $workDir;
44
45
    /**
46
     * @inheritDoc
47
     *
48
     * @throws InvalidArgumentException
49
     */
50 18
    public function __construct(array $config)
51
    {
52 18
        if (!isset($config['domain'])) {
53 2
            throw new InvalidArgumentException('Domain is not set.');
54
        }
55
56 18
        $this->setDomain($config['domain']);
57 18
    }
58
59
    /**
60
     * Return current sitemap name.
61
     *
62
     * @return string
63
     */
64 2
    public function getCurrentSitemap(): string
65
    {
66 2
        return $this->currentSitemap;
67
    }
68
69
    /**
70
     * Set current sitemap name.
71
     *
72
     * @param string $currentSitemap
73
     */
74 8
    public function setCurrentSitemap(string $currentSitemap): void
75
    {
76 8
        $this->currentSitemap = $currentSitemap;
77 8
    }
78
79
    /**
80
     * @inheritDoc
81
     */
82 8
    public function getWorkDir(): ?string
83
    {
84 8
        return $this->workDir;
85
    }
86
87
    /**
88
     * @inheritDoc
89
     */
90 8
    public function setWorkDir(string $dir): void
91
    {
92 8
        $this->workDir = $dir;
93 8
    }
94
95
    /**
96
     * Return full path of current sitemap.
97
     *
98
     * @return string
99
     */
100 6
    protected function getSitemapFileFullPath(): string
101
    {
102 6
        return ((string) $this->getWorkDir()) . DIRECTORY_SEPARATOR . $this->currentSitemap;
103
    }
104
}
105