Completed
Branch master (bff1a4)
by Filipe
02:53
created

CreatedCrudController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 33.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 41
ccs 4
cts 12
cp 0.3333
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureController() 0 6 1
A setEntityName() 0 9 2
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 CreatedCrudController 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
    protected function configureController(Controller $controller)
44
    {
45
        parent::configureController($controller);
46
        $entity = new Entity($this->entityName);
47
        $controller->add($entity);
48
    }
49
50
    /**
51
     * Sets the entity class name
52
     *
53
     * @param string $entityName
54
     */
55 2
    public function setEntityName($entityName)
56
    {
57 2
        if (!class_exists($entityName)) {
58
            throw new EntityClassNotFound(
59
                "The entity class '{$entityName}' does not exist in your system."
60
            );
61
        }
62 2
        $this->entityName = $entityName;
63
    }
64
}