Passed
Push — master ( eda005...2d3321 )
by Andrey
02:01
created

SwaggerServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 86.36%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 42
rs 10
c 0
b 0
f 0
ccs 19
cts 22
cp 0.8636
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 15 2
A register() 0 13 1
1
<?php
2
3
namespace JDesrosiers\Silex\Provider;
4
5
use Doctrine\Common\Annotations\AnnotationRegistry;
6
use Silex\Application;
7
use Silex\ServiceProviderInterface;
8
use Swagger\Logger;
9
10
/**
11
 * The SwaggerServiceProvider adds a swagger-php service to a silex app.  It also adds the routes necessary for
12
 * integrating with swagger-ui.
13
 */
14
class SwaggerServiceProvider implements ServiceProviderInterface
15
{
16
    /**
17
     * Add routes to the app that generate swagger documentation based on your annotations
18
     *
19
     * @param Application $app
20
     */
21 12
    public function boot(Application $app)
22
    {
23 12
        AnnotationRegistry::registerAutoloadNamespace("Swagger\Annotations", $app["swagger.srcDir"]);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\Common\Annotati...sterAutoloadNamespace() has been deprecated: this method is deprecated and will be removed in doctrine/annotations 2.0 autoloading should be deferred to the globally registered autoloader by then. For now, use @example AnnotationRegistry::registerLoader('class_exists') ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

23
        /** @scrutinizer ignore-deprecated */ AnnotationRegistry::registerAutoloadNamespace("Swagger\Annotations", $app["swagger.srcDir"]);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
24
25 12
        if ($app["logger"]) {
26 1
            $logger = Logger::getInstance();
27 1
            $originalLog = $logger->log;
28
            $logger->log = function ($entry, $type) use ($app, $originalLog) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type Swagger\Closure of property $log.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
29
                $app["logger"]->notice($entry);
30
                $originalLog($entry, $type);
31
            };
32
        }
33
34 12
        $app->get($app["swagger.apiDocPath"], new ResourceListController());
35 12
        $app->get("{$app["swagger.apiDocPath"]}/{service}", new ResourceDefinitionController());
36 12
    }
37
38
    /**
39
     * Registers the swagger service
40
     *
41
     * @param Application $app
42
     */
43 12
    public function register(Application $app)
44
    {
45 12
        $app["swagger.apiDocPath"] = "/api/api-docs";
46 12
        $app["swagger.excludePath"] = array();
47 12
        $app["swagger.prettyPrint"] = true;
48 12
        $app["swagger.cache"] = array();
49 12
        $app["swagger.basePath"] = null;
50 12
        $app["swagger.apiVersion"] = null;
51 12
        $app["swagger.swaggerVersion"] = "1.2";
52 12
        $app["swagger.resourcePrefix"] = "/";
53 12
        $app["swagger.resourceSuffix"] = "";
54
55 12
        $app["swagger"] = $app->share(new SwaggerService());
56 12
    }
57
}
58