Completed
Push — master ( bdc00f...dd9c2b )
by max
02:06
created

MigrateController::generateAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace T4web\Migrations\Controller;
4
5
use Zend\Mvc\Controller\AbstractActionController;
6
use T4web\Migrations\Service\Migration;
7
use T4web\Migrations\Service\Generator;
8
use Zend\Console\Request as ConsoleRequest;
9
use Zend\Mvc\MvcEvent;
10
11
/**
12
 * Migration commands controller
13
 */
14
class MigrateController extends AbstractActionController
15
{
16
    /**
17
     * @var Migration
18
     */
19
    protected $migration;
20
21
    /**
22
     * @var Generator
23
     */
24
    protected $generator;
25
26
    public function onDispatch(MvcEvent $e)
27
    {
28
        if (!$this->getRequest() instanceof ConsoleRequest) {
29
            throw new \RuntimeException('You can only use this action from a console!');
30
        }
31
32
        parent::onDispatch($e);
33
    }
34
    /**
35
     * MigrateController constructor.
36
     *
37
     * @param Migration $migration
38
     * @param Generator $generator
39
     */
40
    public function __construct(Migration $migration, Generator $generator)
0 ignored issues
show
Unused Code introduced by
The parameter $migration 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...
41
    {
42
        $this->generator = $generator;
43
    }
44
45
    /**
46
     * Generate new migration skeleton class
47
     */
48
    public function generateAction()
49
    {
50
        $classPath = $this->getGenerator()->generate();
51
52
        return sprintf("Generated skeleton class @ %s\n", realpath($classPath));
53
    }
54
55
    /**
56
     * @return Generator
57
     */
58
    public function getGenerator()
59
    {
60
        return $this->generator;
61
    }
62
}
63