UrlProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 7
Bugs 0 Features 2
Metric Value
c 7
b 0
f 2
dl 0
loc 63
rs 10
wmc 3
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 38 2
A getUrls() 0 4 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\Model;
17
18
use Hogosha\Monitor\Validator\Validator;
19
use Symfony\Component\OptionsResolver\OptionsResolver;
20
21
/**
22
 * Class UrlProvider.
23
 */
24
class UrlProvider
25
{
26
    /**
27
     * $urls.
28
     *
29
     * @var array
30
     */
31
    protected $urls = [];
32
33
    /**
34
     * Constructor.
35
     *
36
     * @param array $config
37
     */
38
    public function __construct(array $config)
39
    {
40
        $resolver = new OptionsResolver();
41
        $resolver->setDefaults(
42
            [
43
                'metric_uuid' => null,
44
                'service_uuid' => null,
45
                'validator' => [],
46
            ]
47
        );
48
49
        $resolver->setRequired(
50
            [
51
                'url',
52
                'method',
53
                'headers',
54
                'timeout',
55
                'status_code',
56
            ]
57
        );
58
59
        foreach ($config['urls'] as $name => $attribute) {
60
            $attribute = $resolver->resolve($attribute);
61
            $this->urls[$name] = new UrlInfo(
62
                $name,
63
                $attribute['url'],
64
                $attribute['method'],
65
                $attribute['headers'],
66
                $attribute['timeout'],
67
                $attribute['status_code'],
68
                (new Validator(
69
                    $attribute['validator']
70
                )),
71
                $attribute['metric_uuid'],
72
                $attribute['service_uuid']
73
            );
74
        }
75
    }
76
77
    /**
78
     * getUrls.
79
     *
80
     * @return array
81
     */
82
    public function getUrls()
83
    {
84
        return $this->urls;
85
    }
86
}
87