LogParserFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 18
c 1
b 0
f 0
dl 0
loc 41
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getParser() 0 22 6
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;
20
21
use Kristuff\Parselog\Core\LogEntryFactoryInterface;
22
use Kristuff\Parselog\Software\SoftwareLogParser;
23
24
/**
25
 * 
26
 */
27
class LogParserFactory 
28
{
29
    const TYPE_APACHE_ACCESS    = 'apache_access';
30
    const TYPE_APACHE_ERROR     = 'apache_error';
31
    const TYPE_SYSLOG           = 'syslog';
32
    const TYPE_FAIL2BAN         = 'fail2ban';
33
    const TYPE_MARIADB_ERROR    = 'mariadb_error';
34
35
    /** 
36
     * Gets a new LogParser instance based on given logType
37
     * 
38
     * @access public
39
     * @static
40
     * @param string                    $logType        The internal log type
41
     * @param string                    $format         The log format. Default is null
42
     * @param LogEntryFactoryInterface  $factory        The custom log entry factory. Default is null (use default factory)       
43
     * 
44
     * @return \Kristuff\Parselog\LogParser|null        
45
     */
46
    public static function getParser(string $logType, string $format = null, LogEntryFactoryInterface $factory = null): ?SoftwareLogParser
47
    {
48
        switch ($logType){
49
50
            case self::TYPE_APACHE_ACCESS: 
51
                return new \Kristuff\Parselog\Software\ApacheAccessLogParser($format, $factory); 
52
53
            case self::TYPE_APACHE_ERROR: 
54
                return new \Kristuff\Parselog\Software\ApacheErrorLogParser($format, $factory); 
55
56
            case self::TYPE_SYSLOG: 
57
                return new \Kristuff\Parselog\Software\SyslogParser($format, $factory); 
58
59
            case self::TYPE_FAIL2BAN:
60
                return new \Kristuff\Parselog\Software\Fail2BanLogParser($format, $factory); 
61
62
            case self::TYPE_MARIADB_ERROR:
63
                return new \Kristuff\Parselog\Software\MariadbErrorLogParser($format, $factory); 
64
65
                
66
        }
67
        return null;
68
    }
69
70
}