Passed
Push — master ( 33798c...96726b )
by Yuri
03:51
created

CustomTemplate   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 15
rs 10
c 1
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A wrapMessages() 0 3 1
1
<?php
2
3
use Tamtamchik\SimpleFlash\BaseTemplate;
4
use Tamtamchik\SimpleFlash\TemplateInterface;
5
6
session_start();
7
8
require_once __DIR__ . '/../vendor/autoload.php';
9
10
class CustomTemplate extends BaseTemplate implements TemplateInterface
11
{
12
    protected $prefix  = '<li>'; // every line prefix
13
    protected $postfix = '</li>'; // every postfix
14
    protected $wrapper = '<ul class="a a-%s">%s</ul>'; // wrapper over messages of same type
15
16
    /**
17
     * @param $messages - message text
0 ignored issues
show
Documentation Bug introduced by
The doc comment - at position 0 could not be parsed: Unknown type name '-' at position 0 in -.
Loading history...
18
     * @param $type     - message type: success, info, warning, error
19
     *
20
     * @return string
21
     */
22
    public function wrapMessages($messages, $type)
23
    {
24
        return sprintf($this->getWrapper(), $type, $messages);
25
    }
26
}
27
28
flash()->setTemplate(new CustomTemplate)->error(['Invalid email!', 'Invalid username!'])
29
    ->warning('Warning message.')
30
    ->info('Info message.')
31
    ->success('Success message!');
32
33
?>
34
35
<!doctype html>
36
<html lang="en">
37
<head>
38
    <meta charset="UTF-8">
39
    <title>Test custom template example.</title>
40
41
    <style>
42
        .container {
43
            max-width: 600px;
44
            margin: 0 auto;
45
            font-family: -apple-system, --sans-serif, sans-serif;
46
        }
47
        .a {
48
            border: 1px solid;
49
            border-radius: 10px;
50
            padding: 1em;
51
            margin: 0.25em 0;
52
        }
53
54
        .a li {
55
            list-style: none;
56
        }
57
58
        .a-info {
59
            background: lightblue;
60
        }
61
62
        .a-error {
63
            background: lightpink;
64
        }
65
66
        .a-warning {
67
            background: lightgoldenrodyellow;
68
        }
69
70
        .a-success {
71
            background: lightgreen;
72
        }
73
    </style>
74
</head>
75
<body>
76
77
<a href="https://github.com/tamtamchik/simple-flash"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png"></a>
78
<br/>
79
80
<div class="container" style="width: 600px;">
81
82
    <?php include_once '_menu.php'; ?>
83
84
    <?= flash() ?>
85
86
</div>
87
88
</body>
89
</html>
90