Test Failed
Push — feature-laravel-5.4 ( 2b4b90...5bfdc4 )
by Kirill
03:52
created

ContentRendererServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 18 1
A registerDefaultBehaviour() 0 9 1
1
<?php
2
3
/**
4
 * This file is part of laravel.su package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
declare(strict_types=1);
10
11
namespace App\Providers;
12
13
use cebe\markdown\GithubMarkdown;
14
use App\Models\Docs\ContentObserver;
15
use Illuminate\Support\ServiceProvider;
16
use App\Services\ContentRenderer\RawTextRenderer;
17
use App\Services\ContentRenderer\MarkdownRenderer;
18
use App\Services\ContentRenderer\LaravelDocsRenderer;
19
use App\Services\ContentRenderer\ContentRenderInterface;
20
21
/**
22
 * Class ContentRendererServiceProvider.
23
 */
24
class ContentRendererServiceProvider extends ServiceProvider
25
{
26
    /**
27
     * @return void
28
     */
29
    public function register(): void
30
    {
31
        $this->registerDefaultBehaviour();
32
33
        // Documentation renderer
34
        $this->app->when(ContentObserver::class)
35
            ->needs(ContentRenderInterface::class)
36
            ->give(function () {
37
                return new LaravelDocsRenderer(new GithubMarkdown());
38
            });
39
40
        // Tips content renderer
41
        $this->app->when(RawTextRenderer::class)
42
            ->needs(ContentRenderInterface::class)
43
            ->give(function() {
44
                return new RawTextRenderer(new GithubMarkdown());
45
            });
46
    }
47
48
    /**
49
     * @return void
50
     */
51
    private function registerDefaultBehaviour()
52
    {
53
        $this->app->singleton(MarkdownRenderer::class, function () {
54
            return new MarkdownRenderer(new GithubMarkdown());
55
        });
56
57
        $this->app->alias(MarkdownRenderer::class, ContentRenderInterface::class);
58
        $this->app->alias(MarkdownRenderer::class, 'md');
59
    }
60
}
61