Completed
Push — 1.0 ( 690a53...47c60b )
by Vladimir
05:44
created

LogServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 7
dl 0
loc 45
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 21 1
A register() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Application;
6
7
use Exception;
8
use Whoops\Run;
9
use Monolog\Logger;
10
use Psr\Log\LoggerInterface;
11
use Monolog\Handler\StreamHandler;
12
use Whoops\Handler\PrettyPageHandler;
13
use League\Container\ServiceProvider\AbstractServiceProvider;
14
use League\Container\ServiceProvider\BootableServiceProviderInterface;
15
16
class LogServiceProvider extends AbstractServiceProvider implements BootableServiceProviderInterface
17
{
18
    protected $provides = [
19
        LoggerInterface::class,
20
    ];
21
22
    /**
23
     * Method will be invoked on registration of a service provider implementing
24
     * this interface. Provides ability for eager loading of Service Providers.
25
     *
26
     * @return void
27
     */
28
    public function boot(): void
29
    {
30
        $this->getContainer()->share(LoggerInterface::class, function () {
31
            $logger = new Logger('FondBot');
32
            $logger->pushHandler(new StreamHandler(
33
                $this->getContainer()->get('resources_path').'/app.log'
34
            ));
35
36
            return $logger;
37
        });
38
39
        $whoops = new Run;
40
        $whoops->pushHandler(new PrettyPageHandler);
0 ignored issues
show
Documentation introduced by
new \Whoops\Handler\PrettyPageHandler() is of type object<Whoops\Handler\PrettyPageHandler>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
41
        $whoops->pushHandler(function (Exception $exception, $inspector, $run) {
0 ignored issues
show
Unused Code introduced by
The parameter $inspector 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...
Unused Code introduced by
The parameter $run 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...
42
            /** @var LoggerInterface $logger */
43
            $logger = $this->getContainer()->get(LoggerInterface::class);
44
45
            $logger->error($exception);
46
        });
47
        $whoops->register();
48
    }
49
50
    /**
51
     * Use the register method to register items with the container via the
52
     * protected $this->container property or the `getContainer` method
53
     * from the ContainerAwareTrait.
54
     *
55
     * @return void
56
     */
57
    public function register(): void
58
    {
59
    }
60
}
61