Completed
Push — master ( e15c58...b150a8 )
by Changwan
07:08
created

HttpServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
dl 0
loc 36
ccs 0
cts 24
cp 0
rs 10
c 2
b 0
f 2
wmc 5
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
B register() 0 23 4
A boot() 0 3 1
1
<?php
2
namespace Wandu\Http;
3
4
use Predis\Client;
5
use SessionHandlerInterface;
6
use Wandu\DI\ContainerInterface;
7
use Wandu\DI\ServiceProviderInterface;
8
use Wandu\Http\Factory\ResponseFactory;
9
use Wandu\Http\Session\Handler\FileHandler;
10
use Wandu\Http\Session\Handler\GlobalHandler;
11
use Wandu\Http\Session\Handler\RedisHandler;
12
use Wandu\Http\Session\SessionFactory;
13
use function Wandu\Foundation\config;
14
use function Wandu\Foundation\path;
15
16
class HttpServiceProvider implements ServiceProviderInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function register(ContainerInterface $app)
22
    {
23
        $app->closure(ResponseFactory::class, function () {
24
            return response(); // singleton
25
        });
26
        $app->closure(SessionFactory::class, function ($app) {
27
            return new SessionFactory($app[SessionHandlerInterface::class], [
28
                'timeout' => config('session.timeout', 3600),
29
                'name' => config('session.name', ini_get('session.name') ?: 'WdSessId'),
30
                'gc_frequency' => config('session.gc_frequency', 100),
31
            ]);
32
        });
33
        $app->closure(SessionHandlerInterface::class, function ($app) {
34
            switch (config('session.type')) {
35
                case 'file':
36
                    return new FileHandler(path(config('session.path', 'cache/sessions')));
0 ignored issues
show
Bug introduced by
It seems like \Wandu\Foundation\path(\...th', 'cache/sessions')) targeting Wandu\Foundation\path() can also be of type array; however, Wandu\Http\Session\Handl...eHandler::__construct() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
37
                case 'redis':
38
                    return new RedisHandler($app[Client::class], config('session.timeout', 3600));
39
                default:
40
                    return new GlobalHandler();
41
            }
42
        });
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function boot(ContainerInterface $app)
49
    {
50
    }
51
}
52