@@ -39,6 +39,13 @@ class FixCommand extends Command
39
39
*/
40
40
protected $ longVersion ;
41
41
42
+ /**
43
+ *
44
+ * @var Fixer
45
+ */
46
+ protected $ fixerService ;
47
+
48
+
42
49
public function __construct ()
43
50
{
44
51
parent ::__construct ();
@@ -50,15 +57,59 @@ public function __construct()
50
57
$ this ->longVersion = $ this ->fixerApplication ->getLongVersion ();
51
58
}
52
59
60
+
61
+
53
62
public function handle ()
54
63
{
55
- $ this ->setVerbosity ($ this ->output ->getVerbosity ());
64
+ try {
65
+ $ this ->verbocityAndValidation ();
66
+ } catch (InvalidConfigurationException $ exception ) {
67
+ $ this ->error ($ exception ->getMessage ());
68
+ return 1 ;
69
+ }
70
+
71
+ $ this ->writePreamble ();
72
+
73
+ $ this ->fixerService ->fixFiles ();
74
+ $ this ->fixerService ->printLegend ();
75
+ $ this ->fixerService ->report ($ this ->verbosity , $ this ->output );
56
76
77
+ $ this ->info ('Completed ' );
78
+ }
79
+
80
+ protected function verbocityAndValidation ()
81
+ {
82
+ $ this ->setVerbosity ($ this ->output ->getVerbosity ());
57
83
if (null !== $ this ->option ('config ' ) && null !== $ this ->option ('rules ' )) {
58
84
throw new InvalidConfigurationException ('Passing both `--config` and `--rules` options is not allowed. ' );
59
85
}
86
+ }
60
87
61
- $ cli_input = [
88
+ protected function getFixerService (): Fixer
89
+ {
90
+ if ($ this ->fixerService === null ) {
91
+ $ this ->fixerService = new Fixer ($ this ->output , $ this ->composeCliInput ());
92
+ }
93
+
94
+ return $ this ->fixerService ;
95
+ }
96
+ protected function writePreamble ()
97
+ {
98
+ if (OutputInterface::VERBOSITY_VERBOSE <= $ this ->verbosity ) {
99
+ $ this ->info ($ this ->longVersion );
100
+ $ this ->writeln ($ this ->getFixerService ()->getPhpRuntimeMessage ());
101
+ }
102
+
103
+ $ this ->writeln ($ this ->getFixerService ()->getLoadedConfigMessage ());
104
+
105
+ if ($ this ->getFixerService ()->isUsingCache () && $ this ->getFixerService ()->cacheFileExists ()) {
106
+ $ this ->writeln ($ this ->getFixerService ()->getCacheFileMessage ());
107
+ }
108
+ }
109
+
110
+ protected function composeCliInput ()
111
+ {
112
+ return [
62
113
'allow-risky ' => $ this ->option ('allow-risky ' ),
63
114
'config ' => $ this ->option ('config ' ),
64
115
'dry-run ' => $ this ->option ('dry-run ' ),
@@ -73,25 +124,8 @@ public function handle()
73
124
'verbosity ' => $ this ->verbosity ,
74
125
'show-progress ' => $ this ->option ('show-progress ' ),
75
126
];
76
-
77
- $ fixerService = new Fixer ($ this ->input , $ this ->output , $ cli_input );
78
-
79
- if (OutputInterface::VERBOSITY_VERBOSE <= $ this ->verbosity ) {
80
- $ this ->info ($ this ->longVersion );
81
- $ this ->writeln ($ fixerService ->getPhpRuntimeMessage ());
82
- }
83
-
84
- $ this ->writeln ($ fixerService ->getLoadedConfigMessage ());
85
-
86
- if ($ fixerService ->isUsingCache () && $ fixerService ->cacheFileExists ()) {
87
- $ this ->writeln ($ fixerService ->getCacheFileMessage ());
88
- }
89
-
90
-
91
- $ this ->info ('Completed ' );
92
127
}
93
-
94
- public function writeln ($ messages , int $ type = SymfonyStyle::OUTPUT_NORMAL )
128
+ protected function writeln ($ messages , int $ type = SymfonyStyle::OUTPUT_NORMAL )
95
129
{
96
130
$ this ->output ->writeln ($ messages , $ type );
97
131
}
0 commit comments