Completed
Push — master ( 3592ed...983069 )
by Guillaume
02:39
created

PusherManager::push()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 3
eloc 4
nc 3
nop 1
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
21
/**
22
 * Class PusherManager.
23
 */
24
class PusherManager
25
{
26
    protected $pushers = [];
27
28
    /**
29
     * Constructor.
30
     *
31
     * @param array $config
32
     */
33
    public function __construct(array $config)
34
    {
35
        $resolver = new OptionsResolver();
36
        $resolver->setRequired(
37
            [
38
                'username',
39
                'password',
40
                'base_uri',
41
                'default_resolved_incident_message',
42
                'default_failed_incident_message',
43
                'metric_update',
44
                'incident_update',
45
            ]
46
        );
47
48
        $options = $resolver->resolve($config['hogosha_portal']);
49
50
        if ($options['metric_update']) {
51
            $this->pushers['metric'] = new MetricPusher($options);
52
        }
53
54
        if ($options['incident_update']) {
55
            $this->pushers['incident'] = new IncidentPusher($options);
56
        }
57
    }
58
59
    /**
60
     * push.
61
     *
62
     * @param ResultCollection $results
63
     */
64
    public function push(ResultCollection $results)
65
    {
66
        foreach ($results as $result) {
67
            foreach ($this->pushers as $pusher) {
68
                $pusher->push($result);
69
            }
70
        }
71
    }
72
}
73