Completed
Push — master ( 74c577...c1ce98 )
by Kirill
06:10
created

AnnotationsServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 15 2
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * This file is part of GitterBot package.
5
 *
6
 * @author Serafim <[email protected]>
7
 * @date 03.03.2016 15:00
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
14
namespace Core\Providers;
15
16
use Core\Doctrine\CacheBridge;
17
use Doctrine\Common\Annotations\AnnotationReader;
18
use Doctrine\Common\Annotations\AnnotationRegistry;
19
use Doctrine\Common\Annotations\CachedReader;
20
use Doctrine\Common\Annotations\Reader;
21
use Doctrine\Common\Cache\ArrayCache;
22
use Illuminate\Contracts\Config\Repository;
23
use Illuminate\Contracts\Foundation\Application;
24
use Illuminate\Support\ServiceProvider;
25
26
/**
27
 * Class AnnotationsServiceProvider
28
 * @package Core\Providers
29
 */
30
class AnnotationsServiceProvider extends ServiceProvider
31
{
32
    /**
33
     * Register class
34
     * @throws \InvalidArgumentException
35
     */
36
    public function register()
37
    {
38
        AnnotationRegistry::registerLoader(function ($class) {
39
            return class_exists($class);
40
        });
41
42
        $this->app->singleton(Reader::class, function (Application $app) {
43
            $debug = $app->make(Repository::class)->get('app.debug', false);
44
            $cache = $app->make($debug ? ArrayCache::class : CacheBridge::class);
45
46
            return new CachedReader(new AnnotationReader(), $cache, $debug);
47
        });
48
49
        $this->app->alias(AnnotationReader::class, Reader::class);
50
    }
51
}
52