Completed
Push — master ( 31b5db...524ecf )
by Michael
03:26
created

ErrorWiring   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 16.66%

Importance

Changes 7
Bugs 1 Features 3
Metric Value
wmc 4
c 7
b 1
f 3
lcom 0
cbo 3
dl 0
loc 49
ccs 4
cts 24
cp 0.1666
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B wire() 0 43 4
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Contains class ErrorWiring.
5
 *
6
 * PHP version 7.0+
7
 *
8
 * LICENSE:
9
 * This file is part of Yet Another Php Eve Api Library also know as Yapeal
10
 * which can be used to access the Eve Online API data and place it into a
11
 * database.
12
 * Copyright (C) 2016 Michael Cummings
13
 *
14
 * This program is free software: you can redistribute it and/or modify it
15
 * under the terms of the GNU Lesser General Public License as published by the
16
 * Free Software Foundation, either version 3 of the License, or (at your
17
 * option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful, but WITHOUT
20
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
22
 * for more details.
23
 *
24
 * You should have received a copy of the GNU Lesser General Public License
25
 * along with this program. If not, see
26
 * <http://spdx.org/licenses/LGPL-3.0.html>.
27
 *
28
 * You should be able to find a copy of this license in the COPYING-LESSER.md
29
 * file. A copy of the GNU GPL should also be available in the COPYING.md file.
30
 *
31
 * @copyright 2016 Michael Cummings
32
 * @license   LGPL-3.0+
33
 * @author    Michael Cummings <[email protected]>
34
 */
35
namespace Yapeal\Configuration;
36
37
use Yapeal\Container\ContainerInterface;
38
use Yapeal\Log\LineFormatter;
39
use Yapeal\Log\Logger;
40
41
/**
42
 * Class ErrorWiring.
43
 */
44
class ErrorWiring implements WiringInterface
45
{
46
    /**
47
     * @param ContainerInterface $dic
48
     */
49 1
    public function wire(ContainerInterface $dic)
50
    {
51 1
        if (empty($dic['Yapeal.Error.Strategy'])) {
52
            $dic['Yapeal.Error.Strategy'] = function () use ($dic) {
53
                return new $dic['Yapeal.Error.Handlers.strategy']((int)$dic['Yapeal.Error.threshold']);
54
            };
55
        }
56 1
        if (empty($dic['Yapeal.Error.Logger'])) {
57
            $dic['Yapeal.Error.Logger'] = function () use ($dic) {
58
                /**
59
                 * @var Logger $logger
60
                 */
61
                $logger = new $dic['Yapeal.Error.Handlers.class']($dic['Yapeal.Error.channel']);
62
                $group = [];
63
                $lineFormatter = new LineFormatter(null, 'Ymd His.u', true, true);
64
                $lineFormatter->includeStacktraces();
65
                /**
66
                 * @var \Monolog\Handler\StreamHandler $handler
67
                 */
68
                if ('cli' === PHP_SAPI) {
69
                    $handler = new $dic['Yapeal.Error.Handlers.stream']('php://stderr', 100);
70
                    $group[] = $handler->setFormatter($lineFormatter);
71
                }
72
                $handler = new $dic['Yapeal.Error.Handlers.stream']($dic['Yapeal.Error.dir']
73
                    . $dic['Yapeal.Error.fileName'], 100);
74
                $group[] = $handler->setFormatter($lineFormatter);
75
                $logger->pushHandler(new $dic['Yapeal.Error.Handlers.fingersCrossed'](new $dic['Yapeal.Error.Handlers.group']($group),
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 134 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
76
                    $dic['Yapeal.Error.Strategy'],
77
                    (int)$dic['Yapeal.Error.bufferSize'],
78
                    true,
79
                    false));
80
                /**
81
                 * @var \Monolog\ErrorHandler $error
82
                 */
83
                $error = $dic['Yapeal.Error.Handlers.error'];
84
                $error::register($logger, [], (int)$dic['Yapeal.Error.threshold'], (int)$dic['Yapeal.Error.threshold']);
85
                return $error;
86
            };
87
            // Activate error logger now since it is needed to log any future fatal
88
            // errors or exceptions.
89 1
            $dic['Yapeal.Error.Logger'];
90
        }
91
    }
92
}
93