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

VersionController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A onDispatch() 0 12 2
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