Completed
Push — master ( bff1a4...59b7c9 )
by Filipe
03:06
created

CreateCrudController::configureController()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * This file is part of slick/mvc package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Mvc\Console\Command\Task;
11
12
use Slick\Mvc\Console\MetaDataGenerator\Controller;
13
use Slick\Mvc\Console\MetaDataGenerator\Entity;
14
use Slick\Mvc\Exception\Console\EntityClassNotFound;
15
16
/**
17
 * CreatedCrudController
18
 *
19
 * @package Slick\Mvc\Console\Command\Task
20
 * @author  Filipe Silva <[email protected]>
21
 *
22
 * @property string $entityName
23
 */
24
class CreateCrudController extends CreateController
25
{
26
27
    /**
28
     * @readwrite
29
     * @var string
30
     */
31
    protected $entityName;
32
33
    /**
34
     * @var string
35
     */
36
    protected $template = 'crud-controller.twig';
37
38
    /**
39
     * Configures the controller generator
40
     *
41
     * @param Controller $controller
42
     */
43 2
    protected function configureController(Controller $controller)
44
    {
45 2
        parent::configureController($controller);
46 2
        $controller[] = new Entity($this->entityName);
47 2
    }
48
49
    /**
50
     * Sets the entity class name
51
     *
52
     * @param $entityName
53
     *
54
     * @return self|CreateCrudController
55
     */
56 6
    public function setEntityName($entityName)
57
    {
58 6
        if (!class_exists($entityName)) {
59 2
            throw new EntityClassNotFound(
60 2
                "The entity class '{$entityName}' does not exist in your system."
61 2
            );
62
        }
63 6
        $this->entityName = $entityName;
64 6
        return $this;
65
    }
66
}