PusherManager   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 3
dl 0
loc 50
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 25 3
A push() 0 8 3
1
<?php
2
3
/*
4
 * This file is part of the hogosha-monitor package
5
 *
6
 * Copyright (c) 2016 Guillaume Cavana
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * Feel free to edit as you please, and have fun.
12
 *
13
 * @author Guillaume Cavana <[email protected]>
14
 */
15
16
namespace Hogosha\Monitor\Pusher;
17
18
use Hogosha\Monitor\Model\ResultCollection;
19
use Symfony\Component\OptionsResolver\OptionsResolver;
20
use Webmozart\Console\Api\IO\IO;
21
22
/**
23
 * Class PusherManager.
24
 */
25
class PusherManager
26
{
27
    protected $pushers = [];
28
29
    /**
30
     * Constructor.
31
     *
32
     * @param array $config
33
     * @param IO    $io
34
     */
35
    public function __construct(array $config, IO $io)
36
    {
37
        $resolver = new OptionsResolver();
38
        $resolver->setRequired(
39
            [
40
                'username',
41
                'password',
42
                'base_uri',
43
                'default_resolved_incident_message',
44
                'default_failed_incident_message',
45
                'metric_update',
46
                'incident_update',
47
            ]
48
        );
49
50
        $options = $resolver->resolve($config['hogosha_portal']);
51
52
        if ($options['metric_update']) {
53
            $this->pushers['metric'] = new MetricPusher($options, $io);
54
        }
55
56
        if ($options['incident_update']) {
57
            $this->pushers['incident'] = new IncidentPusher($options, $io);
58
        }
59
    }
60
61
    /**
62
     * push.
63
     *
64
     * @param ResultCollection $results
65
     */
66
    public function push(ResultCollection $results)
67
    {
68
        foreach ($results as $result) {
69
            foreach ($this->pushers as $pusher) {
70
                $pusher->push($result);
71
            }
72
        }
73
    }
74
}
75