escapeTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 81.58 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 31
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testEscape() 15 15 2
A testEscapePseudoHtml() 16 16 2

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
/**
4
 * @file
5
 * Grafizzi\Graph\Tests\escapeTest: a component of the Grafizzi library.
6
 *
7
 * (c) 2012 Frédéric G. MARAND <[email protected]>
8
 *
9
 * Grafizzi is free software: you can redistribute it and/or modify it under the
10
 * terms of the GNU Lesser General Public License as published by the Free
11
 * Software Foundation, either version 3 of the License, or (at your option) any
12
 * later version.
13
 *
14
 * Grafizzi is distributed in the hope that it will be useful, but WITHOUT ANY
15
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16
 * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
17
 * details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public License
20
 * along with Grafizzi, in the COPYING.LESSER.txt file.  If not, see
21
 * <http://www.gnu.org/licenses/>
22
 */
23
24
namespace Grafizzi\Graph\Tests;
25
26
require 'vendor/autoload.php';
27
28
use Grafizzi\Graph\AbstractNamed;
29
30
/**
31
 * escape() test case.
32
 */
33
class escapeTest extends BaseGraphTest {
34
35
  /**
36
   * Tests escape()
37
   */
38 View Code Duplication
  public function testEscape() {
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...
39
    $testSet = array(
40
      'foo' => 'foo',
41
      'foo bar' => '"foo bar"',
42
      "foo'bar" => '"foo\'bar"',
43
      'foo"bar' => '"foo\"bar"',
44
      // Newline in non-pseudo-HTML mode: escaped
45
      "foo\nbar" => '"foo\nbar"',
46
    );
47
48
    foreach ($testSet as $in => $expected) {
49
      $actual = AbstractNamed::escape($in);
50
      $this->assertEquals($expected, $actual);
51
    }
52
  }
53
54 View Code Duplication
  public function testEscapePseudoHtml() {
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...
55
    $testEscaped = array(
56
      // Test pseudo-HTML label: needs to be <>-wrapped.
57
      '<b>Label</b>' => '<<b>Label</b>>',
58
      // Test non-pseudo-HTML, non-ID label: needs to be dquote-wrapped.
59
      'Non HTML' => '"Non HTML"',
60
      // Test non-pseudo-HTML, ID label: needs not be wrapped.
61
      'nmtoken' => 'nmtoken',
62
      // Newline in pseudo-HTML: not converted
63
      "<b>One\nTwo</b>" => "<<b>One\nTwo</b>>",
64
    );
65
    foreach ($testEscaped as $in => $expected) {
66
      $actual = AbstractNamed::escape($in, true);
67
      $this->assertEquals($expected, $actual);
68
    }
69
  }
70
}
71
72