SoftwareLogParser   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 161
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 16
c 1
b 0
f 0
dl 0
loc 161
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A addFile() 0 3 1
A getKnownFormats() 0 3 1
A getPaths() 0 3 1
A addPath() 0 3 1
A getSoftware() 0 3 1
A getPrettyName() 0 3 1
A addFormat() 0 3 1
A getFiles() 0 3 1
1
<?php declare(strict_types=1);
2
3
/**
4
 *  ___             _
5
 * | _ \__ _ _ _ __| |___  __ _
6
 * |  _/ _` | '_(_-< / _ \/ _` |
7
 * |_| \__,_|_| /__/_\___/\__, |
8
 *                        |___/
9
 * 
10
 * (c) Kristuff <[email protected]>
11
 *
12
 * For the full copyright and license information, please view the LICENSE
13
 * file that was distributed with this source code.
14
 *
15
 * @version    0.7.2
16
 * @copyright  2017-2021 Kristuff
17
 */
18
19
namespace Kristuff\Parselog\Software;
20
21
use Kristuff\Parselog\Core\LogEntryFactoryInterface;
22
use Kristuff\Parselog\LogParser;
23
24
/**
25
 * Abstract base class for software parser
26
 */
27
abstract class SoftwareLogParser extends LogParser
28
{
29
    /** 
30
     * The default log format 
31
     * 
32
     * @access protected
33
     * @var string
34
     */
35
    protected $defaultFormat = '';
36
37
    /** 
38
     * The software name
39
     * 
40
     * @access protected
41
     * @var string 
42
     */
43
    protected $software = '';
44
45
    /** 
46
     * The log pretty name
47
     * 
48
     * @access protected
49
     * @var string 
50
     */
51
    protected $prettyName = '';
52
53
    /** 
54
     * @access protected
55
     * @var array 
56
     */
57
    protected $knownFormats = [];
58
59
    /** 
60
     * The log files names
61
     * 
62
     * @access protected
63
     * @var array 
64
     */
65
    protected $files = [];
66
67
    /** 
68
     * The log files paths
69
     * 
70
     * @access protected
71
     * @var array 
72
     */
73
    protected $paths = [];
74
75
    /**
76
     * Constructor
77
     * 
78
     * @access public
79
     * @param string                    $format    
80
     * @param LogEntryFactoryInterface  $factory        
81
     * 
82
     * @return void
83
     */
84
    public function __construct(string $format = null, LogEntryFactoryInterface $factory = null)
85
    {
86
        parent::__construct($format ?? $this->defaultFormat, $factory);
87
    }
88
89
    /**
90
     * Gets the pretty name 
91
     * 
92
     * @access public
93
     * 
94
     * @return string
95
     */
96
    public function getPrettyName(): string
97
    {
98
        return $this->prettyName;
99
    }
100
101
    /**
102
     * Gets the software name 
103
     * 
104
     * @access public
105
     * 
106
     * @return string
107
     */
108
    public function getSoftware(): string
109
    {
110
        return $this->software;
111
    }
112
    
113
    /**
114
     * Add a format to the known formats list
115
     * 
116
     * @access protected
117
     * @param string    $name        Common name
118
     * @param string    $format      The log format
119
     * 
120
     * @return void
121
     */
122
    protected function addFormat(string $name, string $format): void
123
    {
124
        $this->knownFormats[$name] = $format;
125
    }
126
127
    /**
128
     * Gets the list of known log formats
129
     * 
130
     * @access public
131
     * 
132
     * @return array                An indexed array name/format
133
     */
134
    public function getKnownFormats(): array
135
    {
136
        return $this->knownFormats;
137
    }
138
139
    /**
140
     * Add a file to the known files list
141
     * 
142
     * @access protected
143
     * @param string    $fielName    The log file name
144
     * 
145
     * @return void
146
     */
147
    protected function addFile(string $fileName): void
148
    {
149
        $this->files[] = $fileName;
150
    }
151
152
    /**
153
     * Gets the list of known files names for current parser
154
     *  
155
     * 
156
     * @access public
157
     * 
158
     * @return array
159
     */
160
    public function getFiles(): array
161
    {
162
        return $this->files;
163
    }
164
165
    /**
166
     * Add a path to the known paths list
167
     * 
168
     * @access protected
169
     * @param string    $path        The log path
170
     * 
171
     * @return void
172
     */
173
    protected function addPath(string $path): void
174
    {
175
        $this->paths[] = $path;
176
    }
177
178
    /**
179
     * Gets the list of known paths for current parser
180
     * 
181
     * @access public
182
     * 
183
     * @return array
184
     */
185
    public function getPaths(): array
186
    {
187
        return $this->paths;
188
    }
189
}