Issues (26)

src/App/Dependencies.php (2 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
use App\Handler\ApiError;
6
use App\Service\LoggerService;
7
use App\Service\RedisService;
8
use Psr\Container\ContainerInterface;
9
10 63
$container['db'] = static function (ContainerInterface $container): PDO {
11 56
    $database = $container->get('settings')['db'];
12 56
    $dsn = sprintf(
13 56
        'mysql:host=%s;dbname=%s;port=%s;charset=utf8',
14 56
        $database['host'],
15 56
        $database['name'],
16 56
        $database['port']
17
    );
18 56
    $pdo = new PDO($dsn, $database['user'], $database['pass']);
19 56
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
20 56
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
21 56
    $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
22
23 56
    return $pdo;
24
};
25
26 63
$container['errorHandler'] = static fn (): ApiError => new ApiError();
27
28 63
$container['redis_service'] = static function ($container): RedisService {
29 56
    $redis = $container->get('settings')['redis'];
30
31 56
    return new RedisService(new \Predis\Client($redis['url']));
32
};
33
34 63
$container['logger_service'] = static function ($container): LoggerService {
35 56
    $channel = $container->get('settings')['logger']['channel'];
36 56
    $path = $container->get('settings')['logger']['path'];
37 56
    $logger = new \Monolog\Logger($channel);
38 56
    $file_handler = new \Monolog\Handler\StreamHandler($path . date('Ymd') . '.log');
39 56
    $logger->pushHandler($file_handler);
40
41 56
    return new LoggerService($logger);
42
};
43
44 63
$container['notFoundHandler'] = static function () {
45 1
    return static function ($request, $response): void {
0 ignored issues
show
The parameter $response is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

45
    return static function ($request, /** @scrutinizer ignore-unused */ $response): void {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

45
    return static function (/** @scrutinizer ignore-unused */ $request, $response): void {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46 1
        throw new \App\Exception\NotFoundException('Route Not Found.', 404);
47 1
    };
48
};
49