Test Failed
Push — master ( af6147...dbfe7c )
by Maximo
11:22 queued 06:20
created

LoggerProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 78.95%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 18
c 2
b 0
f 1
dl 0
loc 39
ccs 15
cts 19
cp 0.7895
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 32 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Providers;
6
7
use function Canvas\Core\appPath;
8
use function Canvas\Core\envValue;
9
use Monolog\Formatter\LineFormatter;
10
use Monolog\Handler\StreamHandler;
11
use Monolog\Logger;
12
use Phalcon\Di\ServiceProviderInterface;
0 ignored issues
show
Bug introduced by
The type Phalcon\Di\ServiceProviderInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Phalcon\DiInterface;
0 ignored issues
show
Bug introduced by
The type Phalcon\DiInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Raven_Client;
15
use Monolog\Handler\RavenHandler;
16
17
class LoggerProvider implements ServiceProviderInterface
18
{
19
    /**
20
     * Registers the logger component.
21
     *
22
     * @param DiInterface $container
23
     */
24 4
    public function register(DiInterface $container)
25
    {
26 4
        $config = $container->getShared('config');
27
28 4
        $container->setShared(
29 4
            'log',
30 4
            function () use ($config) {
31
                /** @var string $logName */
32 4
                $logName = envValue('LOGGER_DEFAULT_FILENAME', 'api.log');
33
                /** @var string $logPath */
34 4
                $logPath = envValue('LOGGER_DEFAULT_PATH', 'storage/logs');
35 4
                $logFile = appPath($logPath) . '/' . $logName . '.log';
36
37 4
                $formatter = new LineFormatter("[%datetime%][%level_name%] %message% %context% \n");
38
39 4
                $logger = new Logger('api-logger');
40
41 4
                $handler = new StreamHandler($logFile, Logger::DEBUG);
42 4
                $handler->setFormatter($formatter);
43
44
                //only run logs in production
45 4
                if ($config->app->logsReport) {
46
                    //sentry logger
47
                    $client = new Raven_Client('https://' . getenv('SENTRY_RPOJECT_SECRET') . '@sentry.io/' . getenv('SENTRY_PROJECT_ID'));
48
                    $handlerSentry = new RavenHandler($client, Logger::ERROR);
49
                    $handlerSentry->setFormatter(new LineFormatter("%message% %context% %extra%\n"));
50
                    $logger->pushHandler($handlerSentry);
51
                }
52
53 4
                $logger->pushHandler($handler);
54
55 4
                return $logger;
56 4
            }
57
        );
58 4
    }
59
}
60