Passed
Branch split-service-provider-lumen-l... (a6b330)
by Pieter
05:01
created

ApieLumenServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 19 3
A boot() 0 10 3
1
<?php
2
namespace W2w\Laravel\Apie\Providers;
3
4
use Illuminate\Support\ServiceProvider;
5
use Psr\Http\Message\ServerRequestInterface;
6
use W2w\Laravel\Apie\Controllers\SwaggerUiController;
7
8
/**
9
 * Service provider for Apie to link to Laravel (and that do not work in Laravel)
10
 */
11
class ApieLumenServiceProvider extends ServiceProvider
12
{
13
    public function boot()
14
    {
15
        $config = $this->app->get('apie.config');
16
        if ($config['disable-routes']) {
17
            return;
18
        }
19
        if ($config['swagger-ui-test-page']) {
20
            include __DIR__ . '/../../config/routes-lumen-openapi.php';
21
        }
22
        include __DIR__ . '/../../config/routes-lumen.php';
23
    }
24
25
    public function register()
26
    {
27
        // fix for PSR requests in Lumen
28
        $this->app->extend(
29
            ServerRequestInterface::class, function (ServerRequestInterface $psrRequest) {
30
                $route = (array) $this->app->make('request')->route();
31
                if (is_array($route[2])) {
32
                    foreach ($route[2] as $key => $value) {
33
                        $psrRequest = $psrRequest->withAttribute($key, $value);
34
                    }
35
                }
36
                return $psrRequest;
37
            }
38
        );
39
40
        $this->app->bind(
41
            SwaggerUiController::class, function () {
42
                $urlGenerator = new \Laravel\Lumen\Routing\UrlGenerator($this->app);
0 ignored issues
show
Bug introduced by
The type Laravel\Lumen\Routing\UrlGenerator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
43
                return new SwaggerUiController($urlGenerator, __DIR__ . '/../../resources/open-api.html');
44
            }
45
        );
46
    }
47
}
48