Test Failed
Pull Request — master (#110)
by Dmitriy
02:54
created

Command::getAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 4
c 1
b 1
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Gii\Generator\ActiveRecord;
6
7
use Yiisoft\ActiveRecord\ActiveRecord;
0 ignored issues
show
Bug introduced by
The type Yiisoft\ActiveRecord\ActiveRecord was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Yiisoft\Strings\Inflector;
9
use Yiisoft\Validator\Rule\Regex;
10
use Yiisoft\Validator\Rule\Required;
11
use Yiisoft\Yii\Gii\Generator\AbstractGeneratorCommand;
12
use Yiisoft\Yii\Gii\Validator\TableExistsRule;
13
use Yiisoft\Yii\Gii\Validator\TemplateRule;
14
15
final class Command extends AbstractGeneratorCommand
16
{
17
    public function __construct(
18
        #[Required]
19
        #[Regex(
20
            pattern: '/^(?:[a-z][a-z0-9]*)(?:\\\\[a-z][a-z0-9]*)*$/i',
21
            message: 'Invalid namespace'
22
        )]
23
        private readonly string $namespace = 'App\\Model',
24
        #[Required]
25
        #[Regex(
26
            pattern: '/^(?:[a-z][a-z0-9]*)(?:\\\\[a-z][a-z0-9]*)*$/i',
27
            message: 'Invalid table name'
28
        )]
29
        #[TableExistsRule]
30
        private readonly string $tableName = 'user',
31
        #[Regex(
32
            pattern: '/^[a-z\\\\]*$/i',
33
            message: 'Only word characters and backslashes are allowed.',
34
            skipOnEmpty: true,
35
        )]
36
        private readonly string $baseClass = ActiveRecord::class,
37
        #[Required(message: 'A code template must be selected.')]
38
        #[TemplateRule]
39
        protected string $template = 'default',
40
    ) {
41
        parent::__construct($template);
42
    }
43
44
    public function getNamespace(): string
45
    {
46
        return $this->namespace;
47
    }
48
49
    public function getBaseClass(): string
50
    {
51
        return $this->baseClass;
52
    }
53
54
    public function getTableName(): string
55
    {
56
        return $this->tableName;
57
    }
58
59
    public function getModelName(): string
60
    {
61
        return (new Inflector())->tableToClass($this->tableName);
62
    }
63
64
    public static function getAttributeLabels(): array
65
    {
66
        return [
67
            'namespace' => 'Controller Namespace',
68
            'tableName' => 'Table name',
69
            'template' => 'Action IDs',
70
        ];
71
    }
72
73
    public static function getHints(): array
74
    {
75
        return [
76
            'controllerClass' => 'This is the name of the controller class to be generated. You should
77
                provide a fully qualified namespaced class (e.g. <code>App\Controller\PostController</code>),
78
                and class name should be in CamelCase ending with the word <code>Controller</code>. Make sure the class
79
                is using the same namespace as specified by your application\'s namespace property.',
80
            'baseClass' => 'This is the class that the new controller class will extend from. Please make sure the class exists and can be autoloaded.',
81
        ];
82
    }
83
84
    public static function getAttributes(): array
85
    {
86
        return [
87
            'namespace',
88
            'tableName',
89
            'template',
90
        ];
91
    }
92
}
93