ViewFlashMessageRenderer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
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