Completed
Push — master ( 2c3775...168ecb )
by max
02:05
created

VersionController::onDispatch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 2
eloc 6
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\Migration;
9
use T4web\Migrations\Exception\RuntimeException;
10
11
/**
12
 * Migration commands controller
13
 */
14
class VersionController extends AbstractActionController
15
{
16
    /**
17
     * @var Migration
18
     */
19
    protected $migration;
20
21
    /**
22
     * MigrateController constructor.
23
     *
24
     * @param Migration $migration
25
     */
26
    public function __construct(Migration $migration)
27
    {
28
        $this->migration = $migration;
29
    }
30
31
    public function onDispatch(MvcEvent $e)
32
    {
33
        if (!$e->getRequest() instanceof ConsoleRequest) {
34
            throw new RuntimeException('You can only use this action from a console!');
35
        }
36
37
        $response = sprintf("Current version %s\n", $this->migration->getCurrentVersion());
38
39
        $e->setResult($response);
40
41
        return $response;
42
    }
43
}
44