Completed
Push — master ( 100f13...cbf27e )
by Andreas
10s
created

ParseEvents   B

Complexity

Total Complexity 3

Size/Duplication

Total Lines 66
Duplicated Lines 28.79 %

Coupling/Cohesion

Components 0
Dependencies 16

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 19
loc 66
c 1
b 0
f 0
wmc 3
lcom 0
cbo 16
rs 8.4614

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 19 19 1
B execute() 0 43 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Exception\UnverifiedUriException;
36
use Callingallpapers\Parser\JoindinCfpParser;
37
use Callingallpapers\Parser\Lanyrd\LanyrdCfpParser;
38
use Callingallpapers\Parser\PapercallIo\PapercallIoParserFactory;
39
use Callingallpapers\Service\GeolocationService;
40
use Callingallpapers\Service\TimezoneService;
41
use Callingallpapers\Writer\ApiCfpWriter;
42
use GuzzleHttp\Client;
43
use Symfony\Component\Console\Command\Command;
44
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
45
use Symfony\Component\Console\Input\InputInterface;
46
use Symfony\Component\Console\Input\InputOption;
47
use Symfony\Component\Console\Output\OutputInterface;
48
49
class ParseEvents extends Command
50
{
51 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...
52
    {
53
        $this->setName("parseCfPs")
54
             ->setDescription("Retrieve CfPs and parse them")
55
             ->setDefinition(array(
56
                 new InputOption('start', 's', InputOption::VALUE_OPTIONAL, 'What should be the first date to be taken into account?', ''),
57
             ))
58
             ->setHelp(<<<EOT
59
Get details about CfPs from different sources
60
61
Usage:
62
63
<info>callingallpapers parseCfPs 2015-02-23<env></info>
64
65
If you ommit the date the current date will be used instead
66
<info>callingallpapers parseCfPs<env></info>
67
EOT
68
             );
69
    }
70
71
    protected function execute(InputInterface $input, OutputInterface $output)
72
    {
73
        $header_style = new OutputFormatterStyle('white', 'green', array('bold'));
74
        $output->getFormatter()->setStyle('header', $header_style);
75
76
        $start = new \DateTime($input->getOption('start'));
77
78
        if (! $start instanceof \DateTime) {
79
            throw new \InvalidArgumentException('The given date could not be parsed');
80
        }
81
82
        $client = new Client([
83
            'headers' => [
84
                'Accept' => 'application/json',
85
            ],
86
        ]);
87
88
        $config = parse_ini_file(__DIR__ . '/../../config/callingallpapers.ini');
89
        $writer = new ApiCfpWriter($config['event_api_url'], $config['event_api_token'], $client);
90
        $writer->setOutput($output);
91
92
        // Set CfP-Filters
93
        $filter = new FilterList();
94
        $filter->add(new FollowUriRedirect(['conferenceUri'], $client));
95
        $filter->add(new StripParamsFromUri(['conferenceUri']));
96
        $writer->setFilter($filter);
97
98
        $timezoneService = new TimezoneService($client, $config['timezonedb_token']);
99
100
        $geolocationService = new GeolocationService($client);
101
102
        // Parse Papercall.io
103
        $parser = (new PapercallIoParserFactory($timezoneService, $geolocationService))();
104
        $parser->parse($writer);
105
106
        // Parse Lanyrd.com
107
        $parser = new LanyrdCfpParser($timezoneService);
108
        $parser->parse($writer);
109
110
        // Parse joind.in
111
        $parser = new JoindinCfpParser();
112
        $parser->parse($writer);
113
    }
114
}
115