22
33namespace JMOlivas \Phpqa \Command ;
44
5+ use Exception ;
6+ use JMOlivas \Phpqa \Input \FilesOption ;
57use Symfony \Component \Console \Command \Command ;
68use Symfony \Component \Console \Input \InputInterface ;
79use Symfony \Component \Console \Input \InputOption ;
@@ -46,7 +48,7 @@ protected function configure()
4648 'git ' ,
4749 null ,
4850 InputOption::VALUE_NONE ,
49- 'All files added to git index will be analyze . '
51+ 'All files added to git index will be analyzed . '
5052 );
5153 }
5254
@@ -65,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6567 $ config = $ application ->getConfig ();
6668
6769 if (!$ config ->isCustom () && !$ project ) {
68- throw new \ Exception (
70+ throw new Exception (
6971 sprintf (
7072 'No local phpqa.yml or phpqa.yml.dist at current working directory ' .
7173 'you must provide a valid project value (%s) ' ,
@@ -75,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7577 }
7678
7779 if (!$ config ->isCustom () && !in_array ($ project , $ this ->projects )) {
78- throw new \ Exception (
80+ throw new Exception (
7981 sprintf (
8082 'You must provide a valid project value (%s) ' ,
8183 implode (', ' , $ this ->projects )
@@ -89,31 +91,25 @@ protected function execute(InputInterface $input, OutputInterface $output)
8991
9092 $ output ->writeln (sprintf ('<question>%s</question> ' , $ application ->getName ()));
9193
92- $ files = $ input ->getOption ('files ' );
94+ $ filesOption = new FilesOption ($ input ->getOption ('files ' ));
95+ $ git = $ input ->getOption ('git ' );
9396
94- $ git = false ;
95- if ($ input ->hasOption ('git ' )) {
96- $ git = $ input ->getOption ('git ' );
97+ if (!$ filesOption ->isAbsent () && $ git ) {
98+ throw new Exception ('Options `files` and `git` cannot be used in combination. ' );
9799 }
98100
99- if ($ files && $ git ) {
100- throw new \ Exception ('Options `files` and `git` can not used in combination . ' );
101+ if ($ filesOption -> isAbsent () && ! $ git ) {
102+ throw new Exception ('You must set `files` or `git` options . ' );
101103 }
102104
103- if ($ files ) {
104- $ files = explode (', ' , $ files [0 ]);
105- }
106-
107- if (!$ files [0 ]) {
108- $ files = [];
109- }
110-
111- if (!$ files && !$ git ) {
112- throw new \Exception ('You must set `files` or `git` options. ' );
105+ if (!$ filesOption ->isAbsent () && $ filesOption ->isEmpty ()) {
106+ throw new Exception ('Options `files` needs at least one file. ' );
113107 }
114108
115109 if ($ git ) {
116110 $ files = $ this ->extractCommitedFiles ($ output , $ config );
111+ } else {
112+ $ files = $ filesOption ->normalize ();
117113 }
118114
119115 $ output ->writeln (
@@ -202,7 +198,7 @@ private function checkComposer($output, $files, $config)
202198
203199 if ($ config ->get ('application.method.composer.exception ' )) {
204200 if ($ composerJsonDetected && !$ composerLockDetected ) {
205- throw new \ Exception ($ config ->get ('application.messages.composer.error ' ));
201+ throw new Exception ($ config ->get ('application.messages.composer.error ' ));
206202 }
207203
208204 $ output ->writeln (
@@ -269,7 +265,7 @@ private function analyzer($output, $analyzer, $files, $config, $project)
269265 }
270266
271267 if ($ exception && !$ success ) {
272- throw new \ Exception ($ config ->get ('application.messages. ' .$ analyzer .'.error ' ));
268+ throw new Exception ($ config ->get ('application.messages. ' .$ analyzer .'.error ' ));
273269 }
274270 }
275271
@@ -312,7 +308,7 @@ public function executeProcess($output, $processArguments, $file, $prefixes, $po
312308 private function validateBinary ($ binaryFile )
313309 {
314310 if (!file_exists ($ this ->directory .$ binaryFile )) {
315- throw new \ Exception (
311+ throw new Exception (
316312 sprintf ('%s do not exist! ' , $ binaryFile )
317313 );
318314 }
0 commit comments