ApiProxyServiceProvider::provides()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * @package   cellcote/laravel-proxify
5
 * @author    Michele Andreoli <michi.andreoli[at]gmail.com>
6
 * @copyright Copyright (c) Michele Andreoli
7
 * @author    Rik Schreurs <rik.schreurs[at]mail.com>
8
 * @copyright Copyright (c) Rik Schreurs
9
 * @license   http://mit-license.org/
10
 * @link      https://github.com/cellcote/laravel-proxify
11
 */
12
13
namespace Cellcote\LaravelProxify;
14
15
use Illuminate\Support\ServiceProvider;
16
use Illuminate\Http\JsonResponse;
17
use Cellcote\LaravelProxify\Exceptions\ProxyException;
18
19
class ApiProxyServiceProvider extends ServiceProvider {
20
21
    /**
22
     * Indicates if loading of the provider is deferred.
23
     *
24
     * @var bool
25
     */
26
    protected $defer = false;
27
28
    /**
29
     * Bootstrap the application events.
30
     *
31
     * @return void
32
     */
33
    public function boot() {
34
        $this->publishes([
35
            __DIR__ . '/config/proxy.php' => config_path('proxy.php'),
36
        ]);
37
38
    }
39
40
    /**
41
     * Register the service provider.
42
     *
43
     * @return void
44
     */
45
    public function register() {
46
        //$this->registerErrorHandlers();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
47
        $this->registerApiProxy();
48
    }
49
50
    /**
51
     * Register ApiProxy with the IoC container
52
     * @return void
53
     */
54
    public function registerApiProxy() {
55
        $this->app->bindShared('api-proxy.proxy', function($app) {
0 ignored issues
show
Bug introduced by
The method bindShared() does not seem to exist on object<Illuminate\Contra...Foundation\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
            $params = $app['config']['proxy'];
57
            $proxy = new Proxy($params);
58
            return $proxy;
59
        });
60
61
        $this->app->bind('Cellcote\LaravelProxify\Proxy', function($app) {
62
            return $app['api-proxy.proxy'];
63
        });
64
    }
65
66
    /**
67
     * Get the services provided by the provider.
68
     *
69
     * @return string[]
70
     */
71
    public function provides() {
72
        return array('api-proxy.proxy');
73
    }
74
75
    /**
76
     * Register the ApiProxy error handlers
77
     * @return void
78
     */
79
    private function registerErrorHandlers() {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
80
        $this->app->error(function(ProxyException $ex) {
0 ignored issues
show
Bug introduced by
The method error() does not seem to exist on object<Illuminate\Contra...Foundation\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
81
            if (\Request::ajax() && \Request::wantsJson()) {
82
                return new JsonResponse([
83
                    'error' => $ex->errorType,
84
                    'error_description' => $ex->getMessage()
85
                ], $ex->httpStatusCode, $ex->getHttpHeaders()
86
                );
87
            }
88
89
            return \View::make('api-proxy-laravel::proxy_error', array(
90
                'header' => $ex->getHttpHeaders()[0],
91
                'code' => $ex->httpStatusCode,
92
                'error' => $ex->errorType,
93
                'message' => $ex->getMessage()
94
            ));
95
        });
96
    }
97
98
}
99