Conditions | 9 |
Paths | 129 |
Total Lines | 85 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
80 | protected function execute(InputInterface $input, OutputInterface $output) |
||
81 | { |
||
82 | $header_style = new OutputFormatterStyle('white', 'green', array('bold')); |
||
83 | $style = new SymfonyStyle($input, $output); |
||
84 | $output->getFormatter()->setStyle('header', $header_style); |
||
85 | |||
86 | $start = new \DateTime($input->getOption('start')); |
||
87 | |||
88 | if (! $start instanceof \DateTime) { |
||
89 | throw new \InvalidArgumentException('The given date could not be parsed'); |
||
90 | } |
||
91 | |||
92 | $config = parse_ini_file(__DIR__ . '/../../config/callingallpapers.ini'); |
||
93 | |||
94 | $client = new Client([ |
||
95 | 'headers' => [ |
||
96 | 'Accept' => 'application/json', |
||
97 | 'Authorization' => 'token ' . $config['github.token'], |
||
98 | ], |
||
99 | ]); |
||
100 | |||
101 | $resultKeeper = new ConsoleOutputResultKeeper($style); |
||
102 | $writer = new ApiCfpWriter($config['event_api_url'], $config['event_api_token'], $client); |
||
103 | $writer->setOutput($output); |
||
104 | $writer->setResultKeeper($resultKeeper); |
||
105 | |||
106 | $style->comment(sprintf('Starting to parse %s', $this->getParserName())); |
||
107 | |||
108 | // Set CfP-Filters |
||
109 | $filter = new FilterList(); |
||
110 | $filter->add(new FollowUriRedirect(['conferenceUri'], $client)); |
||
111 | $filter->add(new StripParamsFromUri(['conferenceUri'])); |
||
112 | $writer->setFilter($filter); |
||
113 | |||
114 | $timezoneService = new TimezoneService($client, $config['timezonedb_token']); |
||
115 | $geolocationService = new GeolocationService($client); |
||
116 | |||
117 | // Parse Confs.tech |
||
118 | $parser = $this->getParser(new ServiceContainer($timezoneService, $geolocationService, $client)); |
||
119 | $parser->parse($writer); |
||
120 | |||
121 | $style->newLine(2); |
||
122 | |||
123 | $items = []; |
||
124 | foreach ($resultKeeper->getCreated() as $created) { |
||
125 | $items[] = $created->getConference(); |
||
126 | } |
||
127 | |||
128 | if ($items) { |
||
|
|||
129 | $style->writeln('Added these new Conferences:'); |
||
130 | $style->listing($items); |
||
131 | } |
||
132 | |||
133 | $items = []; |
||
134 | foreach ($resultKeeper->getUpdated() as $updated) { |
||
135 | $items[] = $updated->getConference(); |
||
136 | } |
||
137 | |||
138 | if ($items) { |
||
139 | $style->writeln('Updated these Conferences:'); |
||
140 | $style->listing($items); |
||
141 | } |
||
142 | |||
143 | $items = []; |
||
144 | foreach ($resultKeeper->getFailed() as $failed) { |
||
145 | $items[] = sprintf( |
||
146 | '%1$s (%2$s)', |
||
147 | $failed->getConference(), |
||
148 | $failed->getMessage() |
||
149 | ); |
||
150 | } |
||
151 | |||
152 | foreach ($resultKeeper->getErrored() as $errored) { |
||
153 | $items[] = sprintf( |
||
154 | '%1$s (%2$s)', |
||
155 | $errored->getConference(), |
||
156 | $errored->getMessage() |
||
157 | ); |
||
158 | } |
||
159 | |||
160 | if ($items) { |
||
161 | $style->writeln('There where issues with these conferences:'); |
||
162 | $style->listing($items); |
||
163 | } |
||
164 | } |
||
165 | |||
174 |
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
empty(..)
or! empty(...)
instead.