Completed
Push — master ( c06225...cf7e3d )
by Yuri
02:11
created

TailwindTemplate   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 24
loc 24
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A wrapMessages() 9 9 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Tamtamchik\SimpleFlash\Templates;
4
5
use Tamtamchik\SimpleFlash\BaseTemplate;
6
use Tamtamchik\SimpleFlash\TemplateInterface;
7
8
/**
9
 * Class TailwindTemplate.
10
 * Uses default Semantic UI markdown for flash messages.
11
 */
12 View Code Duplication
class TailwindTemplate extends BaseTemplate implements TemplateInterface
13
{
14
    protected $prefix  = '';
15
    protected $postfix = '<br />';
16
    protected $wrapper = '<div class="bg-%s-lightest border border-%s-light text-%s-dark px-4 py-3 mb-3 rounded relative" role="alert"">%s</div>';
17
18
    /**
19
     * Override base function to suite Bootstrap 3 alert naming.
20
     *
21
     * @param $messages - message text
22
     * @param $type     - message type: success, info, warning, error
23
     *
24
     * @return string
25
     */
26 3
    public function wrapMessages($messages, $type)
27
    {
28 3
        $type = ($type == 'success') ? 'green' : $type;
29 3
        $type = ($type == 'info') ? 'blue' : $type;
30 3
        $type = ($type == 'warning') ? 'orange' : $type;
31 3
        $type = ($type == 'error') ? 'red' : $type;
32
33 3
        return sprintf($this->getWrapper(), $type, $type, $type, $messages);
34
    }
35
}
36