Completed
Push — master ( 67c38d...036b27 )
by Chris
02:43
created

DebugService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 25 5
1
<?php
2
namespace Darya\Foundation\Providers;
3
4
use ChromePhp;
5
use Darya\Service\Contracts\Container;
6
use Darya\Service\Contracts\Provider;
7
8
/**
9
 * A service provider that provides application debugging services, if debugging
10
 * is configured.
11
 * 
12
 * @author Chris Andrew <[email protected]>
13
 */
14
class DebugService implements Provider
15
{
16
	/**
17
	 * Register some debugging services if debugging is configured.
18
	 * 
19
	 * @param Container $container
20
	 */
21
	public function register(Container $container)
22
	{
23
		if (class_exists('ChromePhp') && !class_exists('Chrome')) {
24
			class_alias('ChromePhp', 'Chrome');
25
		}
26
		
27
		$configuration = $container->resolve('Darya\Foundation\Configuration');
28
		
29
		if (!$configuration->get('debug')) {
30
			return;
31
		}
32
		
33
		ini_set('display_errors', 1);
34
		
35
		$listener = function ($result) {
36
			Chrome::log(array($result->query->string, json_encode($result->query->parameters)));
37
			
38
			if ($result->error) {
39
				Chrome::error(array($result->error->number, $result->error->message));
40
			}
41
		};
42
		
43
		$container->event->listen('mysql.query', $listener);
0 ignored issues
show
Bug introduced by
Accessing event on the interface Darya\Service\Contracts\Container suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
44
		$container->event->listen('mssql.query', $listener);
0 ignored issues
show
Bug introduced by
Accessing event on the interface Darya\Service\Contracts\Container suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
45
	}
46
}
47