ViewFlashMessageRenderer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 34
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 9 2
A setSkin() 0 3 1
A __construct() 0 5 1
A getSkin() 0 3 1
1
<?php
2
3
namespace Coderello\Laraflash\FlashMessage;
4
5
use Coderello\Laraflash\Exceptions\SkinNotFoundException;
6
use Illuminate\Contracts\Config\Repository as ConfigRepository;
7
use Illuminate\Contracts\View\Factory as ViewFactory;
8
9
class ViewFlashMessageRenderer implements FlashMessageRendererContract
10
{
11
    protected $viewFactory;
12
13
    protected $configRepository;
14
15
    protected $skin;
16
17 4
    public function __construct(ViewFactory $viewFactory, ConfigRepository $configRepository)
18
    {
19 4
        $this->viewFactory = $viewFactory;
20
21 4
        $this->configRepository = $configRepository;
22
    }
23
24 2
    public function setSkin(string $skin)
25
    {
26 2
        $this->skin = $skin;
27
    }
28
29 4
    public function getSkin()
30
    {
31 4
        return $this->skin ?? $this->configRepository->get('laraflash.skin');
32
    }
33
34 2
    public function render(FlashMessage $flashMessage): string
35
    {
36 2
        $skin = $this->getSkin();
37
38 2
        if (! $this->viewFactory->exists($skin)) {
39 1
            throw new SkinNotFoundException($skin);
40
        }
41
42 1
        return $this->viewFactory->make($skin, $flashMessage->toArray());
43
    }
44
}
45