Completed
Push — master ( d89681...8e123d )
by Andreas
20s
created

ParseEventsConfsTech::execute()   C

Complexity

Conditions 9
Paths 129

Size

Total Lines 87

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 87
rs 6.5347
c 0
b 0
f 0
cc 9
nc 129
nop 2

How to fix   Long Method   

Long Method

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:

1
<?php
2
/**
3
 * Copyright (c) 2015-2016 Andreas Heigl<[email protected]>
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy
6
 * of this software and associated documentation files (the "Software"), to deal
7
 * in the Software without restriction, including without limitation the rights
8
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included in
13
 * all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 * THE SOFTWARE.
22
 *
23
 * @author    Andreas Heigl<[email protected]>
24
 * @copyright 2015-2016 Andreas Heigl/callingallpapers.com
25
 * @license   http://www.opensource.org/licenses/mit-license.php MIT-License
26
 * @version   0.0
27
 * @since     01.12.2015
28
 * @link      http://github.com/heiglandreas/callingallpapers-cli
29
 */
30
namespace Callingallpapers\Command;
31
32
use Callingallpapers\CfpFilter\FilterList;
33
use Callingallpapers\CfpFilter\FollowUriRedirect;
34
use Callingallpapers\CfpFilter\StripParamsFromUri;
35
use Callingallpapers\ErrorHandling\ErrorStore;
36
use Callingallpapers\Exception\UnverifiedUriException;
37
use Callingallpapers\Parser\ConfsTech\ConferenceParser;
38
use Callingallpapers\Parser\ConfsTechParser;
39
use Callingallpapers\Parser\JoindinCfpParser;
40
use Callingallpapers\Parser\Lanyrd\LanyrdCfpParser;
41
use Callingallpapers\Parser\PapercallIo\PapercallIoParserFactory;
42
use Callingallpapers\ResultKeeper\ConsoleOutputResultKeeper;
43
use Callingallpapers\ResultKeeper\ResultKeeper;
44
use Callingallpapers\Service\ConfsTechParserFactory;
45
use Callingallpapers\Service\GeolocationService;
46
use Callingallpapers\Service\TimezoneService;
47
use Callingallpapers\Writer\ApiCfpWriter;
48
use GuzzleHttp\Client;
49
use Symfony\Component\Console\Command\Command;
50
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
51
use Symfony\Component\Console\Input\InputInterface;
52
use Symfony\Component\Console\Input\InputOption;
53
use Symfony\Component\Console\Output\OutputInterface;
54
use Symfony\Component\Console\Style\SymfonyStyle;
55
56
class ParseEventsConfsTech extends Command
57
{
58 View Code Duplication
    protected function configure()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    {
60
        $this->setName("parseCfPs:confs.tech")
61
             ->setDescription("Retrieve CfPs from Confs.tech ony and parse them")
62
             ->setDefinition(array(
63
                 new InputOption('start', 's', InputOption::VALUE_OPTIONAL, 'What should be the first date to be taken into account?', ''),
64
             ))
65
             ->setHelp(<<<EOT
66
Get details about CfPs from https://confs.tech
67
68
Usage:
69
70
<info>callingallpapers parseCfPs:confs.tech 2015-02-23<env></info>
71
72
If you ommit the date the current date will be used instead
73
<info>callingallpapers parseCfPs<env></info>
74
EOT
75
             );
76
    }
77
78
    protected function execute(InputInterface $input, OutputInterface $output)
79
    {
80
        $header_style = new OutputFormatterStyle('white', 'green', array('bold'));
81
        $style = new SymfonyStyle($input, $output);
82
        $output->getFormatter()->setStyle('header', $header_style);
83
84
        $start = new \DateTime($input->getOption('start'));
85
86
        if (! $start instanceof \DateTime) {
87
            throw new \InvalidArgumentException('The given date could not be parsed');
88
        }
89
90
        $config = parse_ini_file(__DIR__ . '/../../config/callingallpapers.ini');
91
92
        $client = new Client([
93
            'headers' => [
94
                'Accept' => 'application/json',
95
                'Authorization' => 'token ' . $config['github.token'],
96
            ],
97
        ]);
98
99
        $resultKeeper = new ConsoleOutputResultKeeper($style);
100
        $writer = new ApiCfpWriter($config['event_api_url'], $config['event_api_token'], $client);
101
        $writer->setOutput($output);
102
        $writer->setResultKeeper($resultKeeper);
103
104
        $style->comment('Starting to parse Confs.tech');
105
106
        // Set CfP-Filters
107
        $filter = new FilterList();
108
        $filter->add(new FollowUriRedirect(['conferenceUri'], $client));
109
        $filter->add(new StripParamsFromUri(['conferenceUri']));
110
        $writer->setFilter($filter);
111
112
        $timezoneService = new TimezoneService($client, $config['timezonedb_token']);
113
        $geolocationService = new GeolocationService($client);
114
115
        // Parse Confs.tech
116
        $conferenceParser = new ConferenceParser($geolocationService, $timezoneService);
117
        $factory = new ConfsTechParserFactory($conferenceParser, $client, $writer);
118
        $parser = new ConfsTechParser($factory);
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) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $items 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 empty(..) or ! empty(...) instead.

Loading history...
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) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $items 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 empty(..) or ! empty(...) instead.

Loading history...
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) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $items 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 empty(..) or ! empty(...) instead.

Loading history...
161
            $style->writeln('There where issues with these conferences:');
162
            $style->listing($items);
163
        }
164
    }
165
}
166