Module::getConsoleUsage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 4
Bugs 0 Features 1
Metric Value
dl 0
loc 9
ccs 0
cts 2
cp 0
rs 9.6666
c 4
b 0
f 1
cc 1
eloc 6
nc 1
nop 1
crap 2
1
<?php
2
3
namespace AssetManager;
4
5
use AssetManager\Core\Service\AssetManager;
6
use Zend\Console\Adapter\AdapterInterface;
7
use Zend\EventManager\EventInterface;
8
use Zend\Loader\AutoloaderFactory;
9
use Zend\Loader\StandardAutoloader;
10
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
11
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
12
use Zend\ModuleManager\Feature\ConfigProviderInterface;
13
use Zend\Mvc\MvcEvent;
14
use Zend\Psr7Bridge\Psr7Response;
15
use Zend\Psr7Bridge\Psr7ServerRequest;
16
17
/**
18
 * Module class
19
 *
20
 * @category   AssetManager
21
 * @package    AssetManager
22
 */
23
class Module implements
24
    AutoloaderProviderInterface,
25
    ConfigProviderInterface,
26
    BootstrapListenerInterface
27
{
28
    /**
29
     * {@inheritDoc}
30
     */
31 1
    public function getAutoloaderConfig()
32
    {
33
        return array(
34 1
            AutoloaderFactory::STANDARD_AUTOLOADER => array(
35 1
                StandardAutoloader::LOAD_NS => array(
36
                    __NAMESPACE__ => __DIR__,
37
                ),
38
            ),
39
        );
40
    }
41
42
    /**
43
     * {@inheritDoc}
44
     */
45 1
    public function getConfig()
46
    {
47 1
        return include __DIR__ . '/../config/module.config.php';
48
    }
49
50
    /**
51
     * Callback method for dispatch and dispatch.error events.
52
     *
53
     * @param MvcEvent $event
54
     * @return \Zend\Http\Response|null
55
     */
56 4
    public function onDispatch(MvcEvent $event)
57
    {
58
        /* @var $zendResponse \Zend\Http\Response */
59 4
        $zendResponse = $event->getResponse();
60 4
        if (!method_exists($zendResponse, 'getStatusCode') || $zendResponse->getStatusCode() !== 404) {
61 2
            return null;
62
        }
63
64 2
        $response       = Psr7Response::fromZend($zendResponse);
65 2
        $request        = Psr7ServerRequest::fromZend($event->getRequest());
0 ignored issues
show
Compatibility introduced by
$event->getRequest() of type object<Zend\Stdlib\RequestInterface> is not a sub-type of object<Zend\Http\Request>. It seems like you assume a concrete implementation of the interface Zend\Stdlib\RequestInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
66 2
        $serviceManager = $event->getApplication()->getServiceManager();
67
68
        /** @var AssetManager $assetManager */
69 2
        $assetManager   = $serviceManager->get(AssetManager::class);
70
71 2
        if (!$assetManager->resolvesToAsset($request)) {
72 1
            return null;
73
        }
74
75 1
        $zendResponse = Psr7Response::toZend($assetManager->setAssetOnResponse($response));
76 1
        $zendResponse->setStatusCode(200);
77
78 1
        return $zendResponse;
79
    }
80
81
    /**
82
     * {@inheritDoc}
83
     */
84 1
    public function onBootstrap(EventInterface $event)
85
    {
86
        // Attach for dispatch, and dispatch.error (with low priority to make sure statusCode gets set)
87
        /* @var $eventManager \Zend\EventManager\EventManagerInterface */
88 1
        $eventManager = $event->getTarget()->getEventManager();
89 1
        $callback     = array($this, 'onDispatch');
90 1
        $priority     = -9999999;
91 1
        $eventManager->attach(MvcEvent::EVENT_DISPATCH, $callback, $priority);
92 1
        $eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, $callback, $priority);
93 1
    }
94
95
    /**
96
     * @param \Zend\Console\Adapter\AdapterInterface $console
97
     * @return array
98
     *
99
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
100
     */
101
    public function getConsoleUsage(AdapterInterface $console)
0 ignored issues
show
Unused Code introduced by
The parameter $console is not used and could be removed.

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

Loading history...
102
    {
103
        return array(
104
            'Warmup',
105
            'assetmanager warmup [--purge] [--verbose|-v]' => 'Warm AssetManager up',
106
            array('--purge', '(optional) forces cache flushing'),
107
            array('--verbose | -v', '(optional) verbose mode'),
108
        );
109
    }
110
}
111