Issues (20)

src/BxCommand.php (1 issue)

Severity
1
<?php
2
namespace App\BxConsole;
3
4
use App\BxConsole\Annotations\Command;
5
use Doctrine\Common\Annotations\AnnotationReader;
6
use Psr\Log\LoggerAwareInterface;
7
use Psr\Log\LoggerAwareTrait;
8
9
class BxCommand extends \Symfony\Component\Console\Command\Command implements LoggerAwareInterface {
10
11
    use LoggerAwareTrait;
12
13
    /**
14
     * @return Application
15
     */
16
    public function getApplication()
17
    {
18
        return parent::getApplication();
19
    }
20
21
    /**
22
     * @return string
23
     */
24
    public function getDocumentRoot() {
25
26
        return $this->getApplication()->getDocumentRoot();
27
    }
28
29
    /**
30
     * @param $annotationName
31
     * @return mixed|object|null
32
     * @throws \ReflectionException
33
     */
34
    public function getAnnotation($annotationName) {
35
36
        $class = \get_called_class();
37
        $r = new \ReflectionClass($class);
38
        $reader = new AnnotationReader();
39
        return $reader->getClassAnnotation($r, $annotationName);
40
    }
41
42
    /**
43
     * @throws \ReflectionException
44
     */
45
    protected function configure() {
46
47
        /** @var Command $annotation */
48
        $annotation = $this->getAnnotation(\App\BxConsole\Annotations\Command::class);
49
50
        if($annotation) {
0 ignored issues
show
$annotation is of type App\BxConsole\Annotations\Command, thus it always evaluated to true.
Loading history...
51
            $this->setName($annotation->name);
52
            $this->setDescription($annotation->description);
53
            if($annotation->help) {
54
                $this->setHelp($annotation->help);
55
            }
56
        }
57
    }
58
59
    /**
60
     * @return \Psr\Log\LoggerInterface|null
61
     */
62
    protected function getLogger() {
63
64
        return $this->logger;
65
    }
66
}