flash()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 9
ccs 4
cts 4
cp 1
crap 2
rs 10
c 3
b 0
f 0
1
<?php
2
3
namespace Tamtamchik\SimpleFlash;
4
5
use Tamtamchik\SimpleFlash\Core\Engine;
6
use Tamtamchik\SimpleFlash\Exceptions\FlashTemplateNotFoundException;
7
8
if ( ! function_exists('flash')) {
9
10
    /**
11
     * Wrapper for flash object to be used as global function.
12
     *
13
     * @param string|string[] $message - message text
14
     * @param string $type - message type: success, info, warning, error
15
     * @param TemplateInterface|null $template - template (optional)
16
     *
17
     * @return Engine|Flash
18
     * @throws FlashTemplateNotFoundException
19
     */
20
    function flash($message = '', string $type = 'info', ?TemplateInterface $template = null)
21
    {
22 38
        $flash = new Flash($template);
23
24 38
        if ( ! empty($message)) {
25 9
            return $flash->message($message, $type);
26
        }
27
28 35
        return $flash;
29
    }
30
}
31