1 | <?php |
||
2 | /** |
||
3 | * This file is part of the Code-Insight library. |
||
4 | * For the full copyright and license information, please view |
||
5 | * the LICENSE file that was distributed with this source code. |
||
6 | * |
||
7 | * @copyright Alexander Obuhovich <[email protected]> |
||
8 | * @link https://github.com/console-helpers/code-insight |
||
9 | */ |
||
10 | |||
11 | namespace ConsoleHelpers\CodeInsight\Command; |
||
12 | |||
13 | |||
14 | use ConsoleHelpers\ConsoleKit\Command\AbstractCommand as BaseCommand; |
||
15 | use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; |
||
16 | use Symfony\Component\Console\Input\ArgvInput; |
||
17 | use Symfony\Component\Console\Input\InputInterface; |
||
18 | |||
19 | /** |
||
20 | * Base command class. |
||
21 | */ |
||
22 | abstract class AbstractCommand extends BaseCommand |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * Prepare dependencies. |
||
27 | * |
||
28 | * @return void |
||
29 | */ |
||
30 | protected function prepareDependencies() |
||
31 | { |
||
32 | $container = $this->getContainer(); |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Returns input from completion context. |
||
37 | * |
||
38 | * @param CompletionContext $context Completion context. |
||
39 | * |
||
40 | * @return InputInterface |
||
41 | */ |
||
42 | protected function getInputFromCompletionContext(CompletionContext $context) |
||
43 | { |
||
44 | $words = $context->getWords(); |
||
45 | array_splice($words, 1, 1); // Remove the command name. |
||
46 | |||
47 | return new ArgvInput($words, $this->getDefinition()); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Returns and validates path. |
||
52 | * |
||
53 | * @param string $raw_path Raw path. |
||
54 | * |
||
55 | * @return string |
||
56 | * @throws \InvalidArgumentException When path isn't valid. |
||
57 | */ |
||
58 | protected function getPath($raw_path) |
||
59 | { |
||
60 | if ( !$raw_path ) { |
||
61 | return ''; |
||
62 | } |
||
63 | |||
64 | $path = realpath($raw_path); |
||
65 | |||
66 | if ( !$path || !file_exists($path) || !is_dir($path) ) { |
||
67 | throw new \InvalidArgumentException('The "' . $raw_path . '" path is invalid.'); |
||
68 | } |
||
69 | |||
70 | return $path; |
||
71 | } |
||
72 | |||
73 | } |
||
74 |