HealthServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 48
ccs 22
cts 22
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B register() 0 24 2
A boot() 0 4 1
1
<?php
2
3
namespace Actuator\Silex\Provider;
4
5
use Actuator\Silex\Controller\HealthController;
6
use Actuator\Health\Health;
7
use Actuator\Health\OrderedHealthAggregator;
8
use Silex\Application;
9
use Silex\ServiceProviderInterface;
10
11
class HealthServiceProvider implements ServiceProviderInterface
12
{
13
14
    /**
15
     * Registers services on the given app.
16
     *
17
     * This method should only be used to configure services and parameters.
18
     * It should not get services.
19
     * @param Application $app
20
     */
21 6
    public function register(Application $app)
22
    {
23
        $app->view(function (Health $healthResult) use ($app) {
24 6
            $healthDetails = array();
25 3
            foreach ($healthResult->getDetails() as $key => $healthDetail) {
26 3
                $healthDetails[$key] = array_merge(
27 3
                    array('status' => $healthDetail->getStatus()->getCode()),
28 3
                    $healthDetail->getDetails()
29 3
                );
30 3
            }
31 3
            $healthDetails = array_merge(
32 3
                array('status' => $healthResult->getStatus()->getCode()),
33
                $healthDetails
34 3
            );
35
36 3
            return $app->json($healthDetails);
37 6
        });
38
39 6
        $app['health.aggregator'] = $app->share(function () {
40 6
            return new OrderedHealthAggregator();
41 6
        });
42 6
        $app['health.indicators'] = array();
43 6
        $app['health.endpoint'] = '/health';
44 6
    }
45
46
    /**
47
     * Bootstraps the application.
48
     *
49
     * This method is called after all services are registered
50
     * and should be used for "dynamic" configuration (whenever
51
     * a service must be requested).
52
     * @param Application $app
53
     */
54 3
    public function boot(Application $app)
55
    {
56 3
        $app->get($app['health.endpoint'], new HealthController());
57 3
    }
58
}
59