AppProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 19
ccs 0
cts 14
cp 0
rs 10
c 2
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 14 3
1
<?php
2
3
namespace Canvas\Providers;
4
5
use Phalcon\Di\ServiceProviderInterface;
0 ignored issues
show
Bug introduced by
The type Phalcon\Di\ServiceProviderInterface 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...
6
use Phalcon\DiInterface;
0 ignored issues
show
Bug introduced by
The type Phalcon\DiInterface 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...
7
use Canvas\Models\Apps;
8
use Canvas\Http\Exception\InternalServerErrorException;
9
use Phalcon\Http\Request;
10
11
class AppProvider implements ServiceProviderInterface
12
{
13
    /**
14
     * @param DiInterface $container
15
     */
16
    public function register(DiInterface $container)
17
    {
18
        $config = $container->getShared('config');
19
        
20
        $container->setShared(
21
            'app',
22
            function () use ($config) {
23
                $request = new Request();
24
                $appKey = $request->hasHeader('KanvasKey') ? $request->getHeader('KanvasKey') : $config->app->id;
25
                $app = Apps::findFirstByKey($appKey);
26
                if (!$app) {
27
                    throw new InternalServerErrorException('No App configure with this key ' . $appKey);
28
                }
29
                return $app;
30
            }
31
        );
32
    }
33
}
34