GenerateController::onDispatch()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 13
loc 13
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
3
namespace T4web\Migrations\Controller;
4
5
use Zend\Mvc\Controller\AbstractActionController;
6
use Zend\Console\Request as ConsoleRequest;
7
use Zend\Mvc\MvcEvent;
8
use T4web\Migrations\Service\Generator;
9
use T4web\Migrations\Exception\RuntimeException;
10
11 View Code Duplication
class GenerateController extends AbstractActionController
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    /**
14
     * @var Generator
15
     */
16
    protected $generator;
17
18
    /**
19
     * @param Generator $generator
20
     */
21
    public function __construct(Generator $generator)
22
    {
23
        $this->generator = $generator;
24
    }
25
26
    public function onDispatch(MvcEvent $e)
27
    {
28
        if (!$e->getRequest() instanceof ConsoleRequest) {
29
            throw new RuntimeException('You can only use this action from a console!');
30
        }
31
32
        $classPath = $this->generator->generate();
33
34
        $response = sprintf("Generated skeleton class @ %s\n", realpath($classPath));
35
36
        $e->setResult($response);
37
        return $response;
38
    }
39
}
40