Test Failed
Pull Request — master (#57)
by Alexander
19:52 queued 17:20
created

AbstractGeneratorDTO::validateTemplate()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 21
rs 9.5222
cc 5
nc 3
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Gii\Generator;
6
7
use Yiisoft\Validator\Result;
8
use Yiisoft\Validator\Rule\Callback;
9
use Yiisoft\Validator\Rule\Required;
10
use Yiisoft\Validator\ValidationContext;
11
12
abstract class AbstractGeneratorDTO
13
{
14
    #[Required(message: 'A code template must be selected.')]
15
    #[Callback(['validateTemplate'])]
16
    private $template = [];
0 ignored issues
show
introduced by
The private property $template is not used, and could be removed.
Loading history...
17
18
    /**
19
     * Validates the template selection.
20
     * This method validates whether the user selects an existing template
21
     * and the template contains all required template files as specified in {@see requiredTemplates()}.
22
     *
23
     * @param string $value
24
     */
25
    public function validateTemplate(mixed $value, Callback $rule, ValidationContext $validationContext): Result
0 ignored issues
show
Unused Code introduced by
The parameter $rule is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

25
    public function validateTemplate(mixed $value, /** @scrutinizer ignore-unused */ Callback $rule, ValidationContext $validationContext): Result

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
    {
27
        /** @var self $dataSet */
28
        $dataSet = $validationContext->getDataSet();
29
        $result = new Result();
30
        $templates = $dataSet->getTemplates();
0 ignored issues
show
Bug introduced by
The method getTemplates() does not exist on Yiisoft\Yii\Gii\Generator\AbstractGeneratorDTO. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        /** @scrutinizer ignore-call */ 
31
        $templates = $dataSet->getTemplates();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
31
        if ($templates === []) {
32
            return $result;
33
        }
34
        if (!isset($templates[$value])) {
35
            $result->addError('Invalid template selection.');
36
        } else {
37
            $templatePath = $templates[$value];
38
            foreach ($dataSet->requiredTemplates() as $template) {
0 ignored issues
show
Bug introduced by
The method requiredTemplates() does not exist on Yiisoft\Yii\Gii\Generator\AbstractGeneratorDTO. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
            foreach ($dataSet->/** @scrutinizer ignore-call */ requiredTemplates() as $template) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
                if (!is_file($dataSet->aliases->get($templatePath . '/' . $template))) {
0 ignored issues
show
Bug Best Practice introduced by
The property aliases does not exist on Yiisoft\Yii\Gii\Generator\AbstractGeneratorDTO. Did you maybe forget to declare it?
Loading history...
40
                    $result->addError("Unable to find the required code template file '$template'.");
41
                }
42
            }
43
        }
44
45
        return $result;
46
    }
47
}
48