1 | <?php |
||
26 | class ExecuteCommand extends Command |
||
27 | { |
||
28 | /** |
||
29 | * @var TaskHandlerFactoryInterface |
||
30 | */ |
||
31 | private $handlerFactory; |
||
32 | |||
33 | /** |
||
34 | * @var TaskExecutionRepositoryInterface |
||
35 | */ |
||
36 | private $executionRepository; |
||
37 | |||
38 | /** |
||
39 | * @param string $name |
||
40 | * @param TaskHandlerFactoryInterface $handlerFactory |
||
41 | * @param TaskExecutionRepositoryInterface $executionRepository |
||
42 | */ |
||
43 | public function __construct( |
||
44 | $name, |
||
45 | TaskHandlerFactoryInterface $handlerFactory, |
||
46 | TaskExecutionRepositoryInterface $executionRepository |
||
47 | ) { |
||
48 | parent::__construct($name); |
||
49 | |||
50 | $this->handlerFactory = $handlerFactory; |
||
51 | $this->executionRepository = $executionRepository; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | protected function configure() |
||
58 | { |
||
59 | $this->addArgument('uuid', InputArgument::REQUIRED); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | protected function execute(InputInterface $input, OutputInterface $output) |
||
66 | { |
||
67 | $errorOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output; |
||
68 | |||
69 | $execution = $this->executionRepository->findByUuid($input->getArgument('uuid')); |
||
|
|||
70 | $handler = $this->handlerFactory->create($execution->getHandlerClass()); |
||
71 | |||
72 | try { |
||
73 | $result = $handler->handle($execution->getWorkload()); |
||
74 | } catch (\Exception $exception) { |
||
75 | if ($exception instanceof FailedException) { |
||
76 | $errorOutput->writeln(FailedException::class); |
||
77 | $exception = $exception->getPrevious(); |
||
78 | } |
||
79 | |||
80 | $errorOutput->writeln($exception->__toString()); |
||
81 | |||
82 | // Process exit-code: 0 = OK, >1 = FAIL |
||
83 | return 1; |
||
84 | } |
||
85 | |||
86 | $output->write($result); |
||
87 | |||
88 | return 0; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | public function isHidden() |
||
98 | } |
||
99 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.