Passed
Push — master ( eaf173...40d83e )
by Enjoys
02:10
created

Parse::addConfigSource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
/*
4
 * The MIT License
5
 *
6
 * Copyright 2020 Enjoys.
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26
27
declare(strict_types=1);
28
29
namespace Enjoys\Config;
30
31
use Enjoys\Traits\Options;
32
33
/**
34
 * Description of Parse
35
 * @psalm-suppress PropertyNotSetInConstructor
36
 * @author Enjoys
37
 */
38
abstract class Parse implements ParseInterface, \Psr\Log\LoggerAwareInterface
39
{
40
    use Options;
41
    use \Psr\Log\LoggerAwareTrait;
42
43
44
45
46
    private ?string $configSource = null;
47
//    protected ?array $errors = null;
48
49 16
    public function __construct()
50
    {
51
52 16
         $this->logger = new \Psr\Log\NullLogger();
53 16
    }
54
55 16
    public function addConfigSource(string $source): void
56
    {
57 16
        $this->configSource = $source;
58 16
    }
59
60 16
    public function parse()
61
    {
62 16
        if (is_null($this->configSource)) {
63
            $this->logger->error('Добавьте данные для парсинга');
64
            return;
65
        }
66
67 16
        if (!is_file($this->configSource)) {
68 11
            return $this->parseString($this->configSource);
69
        }
70
71 5
        return $this->parseFile($this->configSource);
72
    }
73
74
75
76
//    protected function setError(string $error): void
77
//    {
78
//        $this->errors[] = $error;
79
//    }
80
81
//    public function getErrors(): ?array
82
//    {
83
//        return $this->errors;
84
//    }
85
86
    /**
87
     * @return mixed
88
     */
89
    abstract protected function parseString(string $string);
90
91
    /**
92
     * @return mixed
93
     */
94
    abstract protected function parseFile(string $filename);
95
}
96