Completed
Push — master ( 09063a...21ed69 )
by Marco
02:26
created

ProviderBuilder::NullHandler()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 2
crap 6
1
<?php namespace Comodojo\Foundation\Logging;
2
3
use \Monolog\Handler\StreamHandler;
4
use \Monolog\Handler\SyslogHandler;
5
use \Monolog\Handler\ErrorLogHandler;
6
use \Monolog\Handler\NullHandler;
7
8
/**
9
 * @package     Comodojo Foundation
10
 * @author      Marco Giovinazzi <[email protected]>
11
 * @license     MIT
12
 *
13
 * LICENSE:
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 * THE SOFTWARE.
22
 */
23
24
class ProviderBuilder {
25
26
    const DEFAULT_STREAM = 'comodojo.log';
27
28
    const DEFAULT_SYSLOG_FACILITY = LOG_USER;
29
30
    const DEFAULT_SYSLOG_LOGOPTS = LOG_PID;
31
32 1
    public static function StreamHandler($name, $basepath, $parameters) {
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

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

Loading history...
33
34 1
        $stream = $basepath.'/'.(empty($parameters['stream']) ? DEFAULT_STREAM : $parameters['stream']);
35
36 1
        $level = Levels::getLevel( empty($parameters['level']) ? null : $parameters['level'] );
37
38 1
        $bubble = self::getBubble( empty($parameters['bubble']) ? true : $parameters['bubble'] );
39
40 1
        $filePermission = self::getFilePermission( empty($parameters['filePermission']) ? null : $parameters['filePermission'] );
41
42 1
        $useLocking = self::getLocking( empty($parameters['useLocking']) ? false : $parameters['useLocking'] );
43
44 1
        return new StreamHandler($stream, $level, $bubble, $filePermission, $useLocking);
45
46
    }
47
48
    public static function SyslogHandler($name, $parameters) {
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

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

Loading history...
49
50
        if ( empty($parameters['ident']) ) return null;
51
52
        $facility = empty($parameters['facility']) ? DEFAULT_SYSLOG_FACILITY : $parameters['facility'];
53
54
        $level = Levels::getLevel( empty($parameters['level']) ? null : $parameters['level'] );
55
56
        $bubble = self::getBubble( empty($parameters['bubble']) ? true : $parameters['bubble'] );
57
58
        $logopts = empty($parameters['logopts']) ? DEFAULT_SYSLOG_LOGOPTS : $parameters['logopts'];
59
60
        return new SyslogHandler($parameters['ident'], $facility, $level, $bubble, $logopts);
61
62
    }
63
64
    public static function ErrorLogHandler($name, $parameters) {
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

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

Loading history...
65
66
        $messageType = empty($parameters['messageType']) ? ErrorLogHandler::OPERATING_SYSTEM : $parameters['messageType'];
67
68
        $level = Levels::getLevel( empty($parameters['level']) ? null : $parameters['level'] );
69
70
        $bubble = self::getBubble( empty($parameters['bubble']) ? true : $parameters['bubble'] );
71
72
        $expandNewlines = self::getExpandNewlines( empty($parameters['expandNewlines']) ? false : $parameters['expandNewlines'] );
73
74
        return new ErrorLogHandler($messageType, $level, $bubble, $expandNewlines);
75
76
    }
77
78
    public static function NullHandler($name = null, $parameters = array()) {
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

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

Loading history...
79
80
        $level = Levels::getLevel( empty($parameters['level']) ? null : $parameters['level'] );
0 ignored issues
show
Unused Code introduced by
$level is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
81
82
        return new NullHandler( Levels::getLevel() );
83
84
    }
85
86 1
    protected static function getBubble($bubble) {
87
88 1
        return filter_var($bubble, FILTER_VALIDATE_BOOLEAN, array(
89
            'options' => array(
90
                'default' => true
91 1
            )
92 1
        ));
93
94
    }
95
96 1
    protected static function getFilePermission($filepermission = null) {
97
98 1
        if ( is_null($filepermission) ) return null;
99
100
        return filter_var($filepermission, FILTER_VALIDATE_INT, array(
101
            'options' => array(
102
                'default' => 0644
103
            ),
104
            'flags' => FILTER_FLAG_ALLOW_OCTAL
105
        ));
106
107
    }
108
109 1
    protected static function getLocking($uselocking) {
110
111 1
        return filter_var($uselocking, FILTER_VALIDATE_BOOLEAN, array(
112
            'options' => array(
113
                'default' => false
114 1
            )
115 1
        ));
116
117
    }
118
119
    protected static function getExpandNewlines($expandNewlines) {
120
121
        return filter_var($expandNewlines, FILTER_VALIDATE_BOOLEAN, array(
122
            'options' => array(
123
                'default' => false
124
            )
125
        ));
126
127
    }
128
129
}
130