Passed
Push — master ( 517cb3...2c2725 )
by Atanas
02:15
created

FlashServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 13 3
A boot() 0 3 1
1
<?php
2
3
namespace WPEmerge\Flash;
4
5
use WPEmerge;
6
use WPEmerge\ServiceProviders\ServiceProviderInterface;
7
8
/**
9
 * Provide flash dependencies
10
 *
11
 * @codeCoverageIgnore
12
 */
13
class FlashServiceProvider implements ServiceProviderInterface {
14
	/**
15
	 * {@inheritDoc}
16
	 */
17
	public function register( $container ) {
0 ignored issues
show
Coding Style introduced by
register uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
18
		$container[ WP_EMERGE_FLASH_KEY ] = function( $c ) {
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $c. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
19
			$session = null;
20
			if ( isset( $c[ WP_EMERGE_SESSION_KEY ] ) ) {
21
				$session = $c[ WP_EMERGE_SESSION_KEY ];
22
			} else if ( isset( $_SESSION ) ) {
23
				$session = &$_SESSION;
24
			}
25
			return new \WPEmerge\Flash\Flash( $session );
26
		};
27
28
		WPEmerge::facade( 'Flash', \WPEmerge\Flash\FlashFacade::class );
29
	}
30
31
	/**
32
	 * {@inheritDoc}
33
	 */
34
	public function boot( $container ) {
35
		// nothing to boot
36
	}
37
}
38