Completed
Push — master ( 7c429e...75748b )
by Michael
03:23
created

ErrorWiring::wire()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 32
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 32
rs 8.8571
cc 3
eloc 18
nc 2
nop 1
1
<?php
2
/**
3
 * Contains class ErrorWiring.
4
 *
5
 * PHP version 5.5
6
 *
7
 * LICENSE:
8
 * This file is part of Yet Another Php Eve Api Library also know as Yapeal
9
 * which can be used to access the Eve Online API data and place it into a
10
 * database.
11
 * Copyright (C) 2016 Michael Cummings
12
 *
13
 * This program is free software: you can redistribute it and/or modify it
14
 * under the terms of the GNU Lesser General Public License as published by the
15
 * Free Software Foundation, either version 3 of the License, or (at your
16
 * option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful, but WITHOUT
19
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
21
 * for more details.
22
 *
23
 * You should have received a copy of the GNU Lesser General Public License
24
 * along with this program. If not, see
25
 * <http://www.gnu.org/licenses/>.
26
 *
27
 * You should be able to find a copy of this license in the LICENSE.md file. A
28
 * copy of the GNU GPL should also be available in the GNU-GPL.md file.
29
 *
30
 * @copyright 2016 Michael Cummings
31
 * @license   LGPL-3.0+
32
 * @author    Michael Cummings <[email protected]>
33
 */
34
namespace Yapeal\Configuration;
35
36
use Monolog\ErrorHandler;
37
use Yapeal\Container\ContainerInterface;
38
use Yapeal\Log\Logger;
39
40
/**
41
 * Class ErrorWiring.
42
 */
43
class ErrorWiring implements WiringInterface
44
{
45
    /**
46
     * @param ContainerInterface $dic
47
     *
48
     * @return self Fluent interface.
49
     */
50
    public function wire(ContainerInterface $dic)
51
    {
52
        if (!empty($dic['Yapeal.Error.Logger'])) {
53
            return $this;
54
        }
55
        $dic['Yapeal.Error.Logger'] = function ($dic) {
56
            /**
57
             * @var Logger $logger
58
             */
59
            $logger = new $dic['Yapeal.Error.class']($dic['Yapeal.Error.channel']);
60
            $group = [];
61
            if ('cli' === PHP_SAPI) {
62
                $group[] = new $dic['Yapeal.Error.Handlers.stream']('php://stderr', 100);
63
            }
64
            $group[] = new $dic['Yapeal.Error.Handlers.stream']($dic['Yapeal.Error.dir'] . $dic['Yapeal.Error.fileName'],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 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...
65
                100);
66
            $logger->pushHandler(
67
                new $dic['Yapeal.Error.Handlers.fingersCrossed'](new $dic['Yapeal.Error.Handlers.group']($group),
68
                    (int)$dic['Yapeal.Error.threshold'], (int)$dic['Yapeal.Error.bufferSize'], true, false)
69
            );
70
            /**
71
             * @var ErrorHandler $error
72
             */
73
            $error = $dic['Yapeal.Error.Handlers.error'];
74
            $error::register($logger, [], (int)$dic['Yapeal.Error.threshold'], (int)$dic['Yapeal.Error.threshold']);
75
            return $error;
76
        };
77
        // Activate error logger now since it is needed to log any future fatal
78
        // errors or exceptions.
79
        $dic['Yapeal.Error.Logger'];
80
        return $this;
81
    }
82
}
83