GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 3c346f...e67d0f )
by Tyler
03:18
created

Base   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 9
c 3
b 0
f 1
lcom 1
cbo 2
dl 0
loc 84
ccs 26
cts 26
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
getDrivers() 0 1 ?
A getHandlerInstanceByName() 0 4 2
A attachHandler() 0 3 1
A attachDrivers() 0 8 2
A __call() 0 6 2
1
<?php
2
3
namespace Tylercd100\Notify\Drivers;
4
5
use Monolog\Logger;
6
use Monolog\Handler\HandlerInterface;
7
use Tylercd100\Notify\Factories\MonologHandlerFactory as Factory;
8
9
abstract class Base
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $levels = ["debug","info","notice","warning","error","critical","alert","emergency"];
15
16
    /**
17
     * @var array
18
     */
19
    protected $config;
20
21
    /**
22
     * @var Logger
23
     */
24
    protected $logger;
25
26
    /**
27
     * @param array  $config An array of config values to overwrite
28
     * @param Logger $logger A Monolog instance to use
29
     */
30 15
    public function __construct(array $config = [], Logger $logger = null){
31
        //Merge the existing config with the provided config
32 15
        $this->config = array_merge_recursive(config('notify'),$config);
33
34 15
        if(!$logger instanceof Logger){
35 12
            $logger = new Logger($this->config['channel']);
36 12
        }
37 15
        $this->logger = $logger;
38
39 15
        $this->attachDrivers();
40 15
    }
41
42
    /**
43
     * Returns a list of names that correspond to a config key and the Tylercd100\Notify\Factory::create method
44
     * @return array An array of drivers to use
45
     */
46
    abstract protected function getDrivers();
47
48
    /**
49
     * Gets a hanlder instance for the provided name
50
     * @param  string $name The name of the driver you want to use
51
     * @return HandlerInterface
52
     */
53 15
    protected function getHandlerInstanceByName($name){
54 15
        $config = (isset($this->config[$name]) ? $this->config[$name] : []);
55 15
        return Factory::create($name,$config);
56
    }
57
58
    /**
59
     * Pushes a Monolog Handler in to the Monolog Logger instance
60
     * @param  HandlerInterface $handler The Handler to attach
61
     * @return void
62
     */
63 15
    protected function attachHandler(HandlerInterface $handler){
64 15
        $this->logger->pushHandler($handler);
65 15
    }
66
67
    /**
68
     * This will attach all the monolog handlers specified in the drivers config array
69
     * @return void
70
     */
71 15
    protected function attachDrivers()
72
    {
73 15
        $drivers = $this->getDrivers();
74 15
        foreach ($drivers as $driver) {
75 15
            $handler = $this->getHandlerInstanceByName($driver);
76 15
            $this->attachHandler($handler);
77 15
        }
78 15
    }
79
80
    /**
81
     * This will call the log functions of Monolog\Logger
82
     * @param  string $method    The method to call
83
     * @param  array  $arguments The arguments provided
84
     * @return void
85
     */
86 3
    public function __call($method, $arguments)
87
    {
88 3
        if(in_array($method, $this->levels)){
89 3
            call_user_func([$this->logger,$method],$arguments);
90 3
        }
91
    }
92
}