Completed
Push — master ( 17df9a...99bd38 )
by Arnold
03:12
created

TextExtensionTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 20.51 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 1
dl 8
loc 39
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A buildEnv() 8 8 1
A process() 0 5 1
A check() 0 4 1
A testQuote() 0 3 1
A testLine() 0 3 1
A testLess() 0 3 1
A testTruncate() 0 3 1

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 Jasny\Twig;
4
5
use Jasny\Twig\TextExtension;
6
7
class TextExtensionTest extends PHPUnit_Framework_TestCase {
8
9 View Code Duplication
    private function buildEnv($template) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
        $loader = new Twig_Loader_Array(array(
11
            'template' => $template,
12
        ));
13
        $twig = new Twig_Environment($loader);
14
        $twig->addExtension(new TextExtension());
15
        return $twig;
16
    }
17
    
18
    private function process($template, $data = array()) {
19
        $twig = $this->buildEnv($template);
20
        $result = $twig->render('template', $data);
21
        return $result;
22
    }
23
    
24
    private function check($expected, $template) {
25
        $result = $this->process($template);
26
        $this->assertEquals($expected, $result);
27
    }
28
29
    public function testQuote() {
30
        $this->check("<p>foo<br>\nbar</p>", "{{ 'foo\nbar'|paragraph() }}");
31
    }
32
    
33
    public function testLine() {
34
        $this->check("bar", "{{ 'foo\nbar\nbaz'|line(2) }}");
35
    }
36
    
37
    public function testLess() {
38
        $this->check("foo..", "{{ 'fooXbarXbaz'|less('..', 'X') }}");
39
    }
40
    
41
    public function testTruncate() {
42
        $this->check("foo ..", "{{ 'foo bar baz'|truncate(4, '..') }}");
43
    }
44
    
45
}
46