Test Failed
Push — master ( afd99a...0309cf )
by Ilya
03:13
created

ViewFlashMessageRenderer::getSkin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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