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.

ErrorServiceProvider::register()   B
last analyzed

Complexity

Conditions 6
Paths 1

Size

Total Lines 63

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 28
CRAP Score 6.8081

Importance

Changes 0
Metric Value
dl 0
loc 63
ccs 28
cts 39
cp 0.7179
rs 8.185
c 0
b 0
f 0
cc 6
nc 1
nop 1
crap 6.8081

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php declare(strict_types=1);
2
/**
3
 * Starlit App.
4
 *
5
 * @copyright Copyright (c) 2016 Starweb AB
6
 * @license   BSD 3-Clause
7
 */
8
9
namespace Starlit\App\Provider;
10
11
use Monolog\Handler\ErrorLogHandler;
12
use Monolog\Logger;
13
use Monolog\Processor\WebProcessor;
14
use Starlit\App\BaseApp;
15
use Starlit\App\ErrorHandling\UserErrorPageHandler;
16
use Whoops\Handler\PlainTextHandler;
17
use Whoops\Handler\PrettyPageHandler;
18
19
class ErrorServiceProvider implements ServiceProviderInterface
20
{
21
    /**
22
     * @param BaseApp $app
23
     */
24 23
    public function register(BaseApp $app): void
25
    {
26 23
        $app->alias('errorLogger', Logger::class);
27 23
        $app->set(
28
            Logger::class, function (BaseApp $app) {
29 23
            $logger = new Logger('errorLogger');
30
31 23
            $handler = new ErrorLogHandler();
32 23
            if (!$app->isCli()) {
33
                $handler->pushProcessor(new WebProcessor());
34
                $format = '%level_name%: %message% %extra.server%%extra.url%';
35
            } else {
36 23
                $format = '%level_name%: %message%';
37
            }
38 23
            $handler->setFormatter(new \Monolog\Formatter\LineFormatter($format, null, true));
39 23
            $logger->pushHandler($handler);
40
41 23
            return $logger;
42 23
        });
43
44
        $app->set('whoopsDebugErrorPageHandler', function (BaseApp $app) {
45
            $prettyPageHandler = new PrettyPageHandler();
46
            if ($app->getConfig()->has('editor')) {
47
                $prettyPageHandler->setEditor($app->getConfig()->get('editor'));
0 ignored issues
show
Documentation introduced by
$app->getConfig()->get('editor') is of type *, 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...
48
            }
49
50
            return $prettyPageHandler;
51 23
        });
52
53 23
        $app->alias('whoopsUserErrorPageHandler', UserErrorPageHandler::class);
54 23
        $app->set(
55
            UserErrorPageHandler::class, function (BaseApp $app) {
56
            return new UserErrorPageHandler(
57
                $app->getConfig()->getRequired('errorPagePath')
58
            );
59 23
        });
60
61
        $app->set('whoopsErrorHandler', function (BaseApp $app) {
62 23
            $plainTextHandler = new PlainTextHandler();
63 23
            $plainTextHandler->setLogger($app->get(Logger::class));
64 23
            if (!$app->isCli()) {
65
                $plainTextHandler->loggerOnly(true);
66
            }
67
68 23
            return $plainTextHandler;
69 23
        });
70
71
        $app->set('whoops', function (BaseApp $app) {
72 23
            $whoops = new \Whoops\Run();
73
74 23
            if (ini_get('display_errors')) {
75
                $whoops->pushHandler($app->get('whoopsDebugErrorPageHandler'));
0 ignored issues
show
Documentation introduced by
$app->get('whoopsDebugErrorPageHandler') is of type *, 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...
Deprecated Code introduced by
The method Whoops\Run::pushHandler() has been deprecated with message: use appendHandler and prependHandler instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
76 23
            } elseif ($app->getConfig()->has('errorPagePath')) {
77
                $whoops->pushHandler($app->get('whoopsUserErrorPageHandler'));
0 ignored issues
show
Documentation introduced by
$app->get('whoopsUserErrorPageHandler') is of type *, 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...
Deprecated Code introduced by
The method Whoops\Run::pushHandler() has been deprecated with message: use appendHandler and prependHandler instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
78
            }
79
80
            // Handles cli output and logging
81 23
            $whoops->pushHandler($app->get('whoopsErrorHandler'));
0 ignored issues
show
Documentation introduced by
$app->get('whoopsErrorHandler') is of type *, 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...
Deprecated Code introduced by
The method Whoops\Run::pushHandler() has been deprecated with message: use appendHandler and prependHandler instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
82
83 23
            return $whoops;
84 23
        });
85 23
        $app->get('whoops')->register();
86 23
    }
87
}
88