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

CategoryParser   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 4
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
B __invoke() 0 21 6
1
<?php
2
3
/*
4
 * Copyright (c) Andreas Heigl<[email protected]
5
 *
6
 * Licensed under the MIT License. See LICENSE.md file in the project root
7
 * for full license information.
8
 */
9
10
namespace Callingallpapers\Parser\ConfsTech;
11
12
use Callingallpapers\ResultKeeper\ResultKeeper;
13
use Callingallpapers\Writer\WriterInterface;
14
use Exception;
15
use GuzzleHttp\Client;
16
use Symfony\Component\Console\Helper\ProgressBar;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use Symfony\Component\Console\Style\SymfonyStyle;
19
20
class CategoryParser
21
{
22
    private $conferenceParser;
23
24
    private $writer;
25
26
    private $client;
27
28
    public function __construct(
29
        ConferenceParser $conferenceParser,
30
        Client $client,
31
        WriterInterface $writer
32
    ) {
33
        $this->conferenceParser = $conferenceParser;
34
        $this->writer           = $writer;
35
        $this->client           = $client;
36
    }
37
38
    public function __invoke(string $category, string $url)
39
    {
40
        $cat = $this->client->request('GET', $url);
41
42
        $cat = json_decode($cat->getBody()->getContents(), true);
43
        if (isset($cat['encoding']) && $cat['encoding'] === 'base64') {
44
            $cat = json_decode(base64_decode($cat['content']), true);
45
        }
46
        foreach ($cat as $conference) {
47
            if (! isset($conference['cfpEndDate'])) {
48
                continue;
49
            }
50
            try {
51
                $cfp = ($this->conferenceParser)($conference);
52
                $cfp->addTag($category);
53
                $this->writer->write($cfp, 'confs.tech');
54
            } catch (Exception $e) {
55
                // Nothing to be done. We just skip over.
56
            }
57
        }
58
    }
59
}
60