1 | <?php |
||
2 | /** |
||
3 | * This file is part of the Jira-CLI 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/jira-cli |
||
9 | */ |
||
10 | |||
11 | namespace ConsoleHelpers\JiraCLI\Command; |
||
12 | |||
13 | |||
14 | use ConsoleHelpers\ConsoleKit\Config\ConfigEditor; |
||
15 | use ConsoleHelpers\ConsoleKit\Command\AbstractCommand as BaseCommand; |
||
16 | use ConsoleHelpers\JiraCLI\JiraApi; |
||
17 | use Doctrine\Common\Cache\CacheProvider; |
||
18 | use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; |
||
19 | |||
20 | /** |
||
21 | * Base command class. |
||
22 | */ |
||
23 | abstract class AbstractCommand extends BaseCommand |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * Config editor. |
||
28 | * |
||
29 | * @var ConfigEditor |
||
30 | */ |
||
31 | private $_configEditor; |
||
32 | |||
33 | /** |
||
34 | * Jira REST client. |
||
35 | * |
||
36 | * @var JiraApi |
||
37 | */ |
||
38 | protected $jiraApi; |
||
39 | |||
40 | /** |
||
41 | * Cache. |
||
42 | * |
||
43 | * @var CacheProvider |
||
44 | */ |
||
45 | protected $cache; |
||
46 | |||
47 | /** |
||
48 | * Statistics. |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $statistics = array(); |
||
53 | |||
54 | /** |
||
55 | * Prepare dependencies. |
||
56 | * |
||
57 | * @return void |
||
58 | */ |
||
59 | protected function prepareDependencies() |
||
60 | { |
||
61 | $container = $this->getContainer(); |
||
62 | |||
63 | $this->_configEditor = $container['config_editor']; |
||
64 | $this->jiraApi = $container['jira_api']; |
||
65 | $this->cache = $container['cache']; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Returns command setting value. |
||
70 | * |
||
71 | * @param string $name Name. |
||
72 | * |
||
73 | * @return mixed |
||
74 | */ |
||
75 | protected function getSetting($name) |
||
76 | { |
||
77 | return $this->_configEditor->get($name); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Checks if an issue key is valid. |
||
82 | * |
||
83 | * @param string $issue_key Issue key. |
||
84 | * |
||
85 | * @return boolean |
||
86 | */ |
||
87 | public function isValidIssueKey($issue_key) |
||
88 | { |
||
89 | return preg_match('/^([A-Z]+-[0-9]+)$/', $issue_key); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Return possible values for the named argument |
||
94 | * |
||
95 | * @param string $argumentName Argument name. |
||
96 | * @param CompletionContext $context Completion context. |
||
97 | * |
||
98 | * @return array |
||
99 | */ |
||
100 | public function completeArgumentValues($argumentName, CompletionContext $context) |
||
101 | { |
||
102 | $ret = parent::completeArgumentValues($argumentName, $context); |
||
103 | |||
104 | if ( $argumentName === 'project_key' || $argumentName === 'project_keys' ) { |
||
105 | return $this->jiraApi->getProjectKeys(); |
||
106 | } |
||
107 | |||
108 | return $ret; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Shows statistics. |
||
113 | * |
||
114 | * @return void |
||
115 | */ |
||
116 | protected function showStatistics() |
||
117 | { |
||
118 | if ( !$this->io->isVerbose() ) { |
||
119 | return; |
||
120 | } |
||
121 | |||
122 | $request_count = $this->jiraApi->getRequestCount(); |
||
123 | |||
124 | if ( $request_count ) { |
||
125 | $this->statistics[] = 'API Requests Made: ' . $request_count; |
||
126 | } |
||
127 | |||
128 | if ( $this->statistics ) { |
||
0 ignored issues
–
show
The expression
$this->statistics of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||
129 | $this->io->writeln('==============='); |
||
130 | $this->io->writeln($this->statistics); |
||
131 | } |
||
132 | } |
||
133 | |||
134 | } |
||
135 |