Passed
Push — master ( 927712...e06ccd )
by Vítězslav
05:12
created

Regent   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 53
c 1
b 0
f 0
dl 0
loc 119
ccs 0
cts 45
cp 0
rs 10
wmc 19

5 Methods

Rating   Name   Duplication   Size   Complexity  
A takeMessage() 0 2 1
A addStatusObject() 0 6 1
C __construct() 0 36 13
A addToLog() 0 4 2
A singleton() 0 8 2
1
<?php
2
/**
3
 * Class to Rule message loggers.
4
 *
5
 * @author    Vitex <[email protected]>
6
 * @copyright 2016 [email protected] (G)
7
 */
8
9
namespace Ease\Logger;
10
11
/**
12
 * Description of Regent
13
 *
14
 * @author vitex
15
 */
16
class Regent extends \Ease\Atom
17
{
18
    /**
19
     * Saves obejct instace (singleton...).
20
     */
21
    private static $_instance = null;
22
23
    /**
24
     * Here to reach logger objects
25
     * @var array 
26
     */
27
    public $loggers = [];
28
29
    /**
30
     * Hodnoty pro obarvování logu.
31
     *
32
     * @var array
33
     */
34
    public $logStyles = [
35
        'notice' => 'color: black;',
36
        'success' => 'color: #2C5F23;',
37
        'message' => 'color: #2C5F23;',
38
        'warning' => 'color: #AB250E;',
39
        'error' => 'color: red;',
40
        'debug' => 'font-style: italic;',
41
        'report' => 'font-wight: bold;',
42
        'info' => 'color: blue;',
43
    ];
44
45
    public function __construct($logger = null)
46
    {
47
        if (is_null($logger) && defined('EASE_LOGGER')) {
48
            $loggers = explode('|', constant('EASE_LOGGER'));
49
        } else {
50
            $loggers = empty($logger) ? ['syslog'] : [$logger];
51
        }
52
53
        foreach ($loggers as $logger)
54
            switch ($logger) {
55
                case 'console':
56
                    $this->loggers[$logger] = ToConsole::singleton();
57
                    break;
58
                case 'syslog':
59
                    $this->loggers[$logger] = ToSyslog::singleton();
60
                    break;
61
                case 'memory':
62
                    $this->loggers[$logger] = ToMemory::singleton();
63
                    break;
64
                case 'email':
65
                    $this->loggers[$logger] = ToEmail::singleton();
66
                    break;
67
                case 'std':
68
                    $this->loggers[$logger] = ToStd::singleton();
69
                    break;
70
                case 'eventlog':
71
                    $this->loggers[$logger] = ToEventlog::singleton();
72
                    break;
73
                default:
74
                    if (class_exists($logger) && method_exists($logger,
75
                            'singleton')) {
76
                        $this->loggers[$logger] = $logger::singleton();
77
                    } else {
78
                        $this->loggers[$logger] = ToFile::singleton($logger);
0 ignored issues
show
Unused Code introduced by
The call to Ease\Logger\ToFile::singleton() has too many arguments starting with $logger. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

78
                        /** @scrutinizer ignore-call */ 
79
                        $this->loggers[$logger] = ToFile::singleton($logger);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
79
                    }
80
                    break;
81
            }
82
    }
83
84
    public function takeMessage()
85
    {
86
        
87
    }
88
89
    /**
90
     * Add Status Message to all registered loggers
91
     *
92
     * @param string $caller  message provider
93
     * @param string $message message to log
94
     * @param string $type    info|succes|warning|error|email|...
95
     */
96
    public function addToLog($caller, $message, $type = 'info')
97
    {
98
        foreach ($this->loggers as $logger) {
99
            $logger->addToLog($caller, $message, $type);
100
        }
101
    }
102
103
    /**
104
     * Add Status Object to stack
105
     * 
106
     * @param \Ease\Logger\Message $message
107
     * @param string $type
108
     * 
109
     * @return int number of stored message
110
     */
111
    public function addStatusObject(Message $message, $type = 'info')
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

111
    public function addStatusObject(Message $message, /** @scrutinizer ignore-unused */ $type = 'info')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
112
    {
113
        $this->addToLog($message->caller, $message->body, $message->type);
114
        \Ease\Shared::instanced()->addStatusMessage($message->body,
115
            $message->type);
116
        return parent::addStatusMessage($message->body, $message->type);
117
    }
118
119
    /**
120
     * Pri vytvareni objektu pomoci funkce singleton (ma stejne parametry, jako
121
     * konstruktor) se bude v ramci behu programu pouzivat pouze jedna jeho
122
     * instance (ta prvni).
123
     *
124
     * @link http://docs.php.net/en/language.oop5.patterns.html Dokumentace a
125
     * priklad
126
     */
127
    public static function singleton()
128
    {
129
        if (!isset(self::$_instance)) {
130
            $class           = __CLASS__;
131
            self::$_instance = new $class();
132
        }
133
134
        return self::$_instance;
135
    }
136
}
137