Failed Conditions
Branch ignore-unknown-keywords (efa676)
by Stéphane
02:58
created

PatternConstraintTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 20.59 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 7
loc 34
rs 10
c 1
b 1
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testNormalizeThrowsIfPatternIsNotString() 0 6 1
A testNormalizeThrowsIfPatternIsNotValidRegex() 0 6 1
A testDelimitersAreEscapedBeforeTestingRegex() 7 7 1
A getConstraint() 0 4 1
A getCaseFileNames() 0 4 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
/*
4
 * This file is part of the JVal package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace JVal\Constraint;
11
12
use JVal\Context;
13
use JVal\Testing\ConstraintTestCase;
14
15
class PatternConstraintTest extends ConstraintTestCase
16
{
17
    public function testNormalizeThrowsIfPatternIsNotString()
18
    {
19
        $this->expectConstraintException('InvalidTypeException', '/pattern');
20
        $schema = $this->loadSchema('invalid/pattern-not-string');
21
        $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker());
22
    }
23
24
    public function testNormalizeThrowsIfPatternIsNotValidRegex()
25
    {
26
        $this->expectConstraintException('InvalidRegexException', '/pattern');
27
        $schema = $this->loadSchema('invalid/pattern-invalid-regex');
28
        $this->getConstraint()->normalize($schema, new Context(), $this->mockWalker());
29
    }
30
31 View Code Duplication
    public function testDelimitersAreEscapedBeforeTestingRegex()
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...
32
    {
33
        $schema = $this->loadSchema('valid/pattern-with-slash');
34
        $context = new Context();
35
        $this->getConstraint()->normalize($schema, $context, $this->mockWalker());
36
        $this->assertEquals(0, $context->countViolations());
37
    }
38
39
    protected function getConstraint()
40
    {
41
        return new PatternConstraint();
42
    }
43
44
    protected function getCaseFileNames()
45
    {
46
        return ['pattern'];
47
    }
48
}
49