Issues (70)

Attributes/Alias.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace WebStream\Annotation\Attributes;
4
5
use WebStream\Annotation\Base\Annotation;
6
use WebStream\Annotation\Base\IAnnotatable;
7
use WebStream\Annotation\Base\IMethods;
8
use WebStream\Annotation\Base\IRead;
9
use WebStream\Container\Container;
0 ignored issues
show
The type WebStream\Container\Container 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...
10
use WebStream\Exception\Extend\AnnotationException;
0 ignored issues
show
The type WebStream\Exception\Extend\AnnotationException 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...
11
12
/**
13
 * Alias
14
 * @author Ryuichi TANAKA.
15
 * @since 2015/12/05
16
 * @version 0.7
17
 *
18
 * @Annotation
19
 * @Target("METHOD")
20
 */
21
class Alias extends Annotation implements IMethods, IRead
22
{
23
    /**
24
     * @var array<string> 注入アノテーション情報
25
     */
26
    private array $injectAnnotation;
27
28
    /**
29
     * @var array<string> 読み込みアノテーション情報
30
     */
31
    private array $readAnnotation;
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 2
    public function onInject(array $injectAnnotation)
37
    {
38 2
        $this->injectAnnotation = $injectAnnotation;
39 2
        $this->readAnnotation = ['method' => ''];
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 1
    public function getAnnotationInfo(): array
46
    {
47 1
        return $this->readAnnotation;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     * @throws \ReflectionException
53
     */
54 2
    public function onMethodInject(IAnnotatable $instance, \ReflectionMethod $method, Container $container)
55
    {
56 2
        $definedMethods = [];
57 2
        $refClass = new \ReflectionClass($instance);
58 2
        foreach ($refClass->getMethods() as $refMethod) {
59 2
            $definedMethods[] = $refMethod->name;
60
        }
61
62 2
        $aliasMethodName = $this->injectAnnotation['name'];
63 2
        if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]{0,}$/', $aliasMethodName)) {
64
            throw new AnnotationException("Alias method is invalid: " . $aliasMethodName);
65
        }
66
67 2
        if (array_key_exists($aliasMethodName, array_flip($definedMethods))) {
68 1
            throw new AnnotationException("Alias method of the same name is defined: $aliasMethodName");
69
        }
70
71 1
        if ($container->action === $aliasMethodName) {
72 1
            $this->readAnnotation['method'] = $method->name;
73
        }
74
    }
75
}
76