Completed
Push — master ( 2afc86...6ca8f1 )
by Russell
02:59
created

JSONTextTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 37.5 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 18
Bugs 4 Features 7
Metric Value
wmc 3
c 18
b 4
f 7
lcom 0
cbo 2
dl 21
loc 56
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testIsValidExpression() 10 10 1
A testIsValidJson() 0 16 1
A testIsValidDBValue() 11 11 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
 * @package silverstripe-jsontext
5
 * @subpackage fields
6
 * @author Russell Michell <[email protected]>
7
 */
8
9
use JSONText\Fields\JSONText;
10
11
class JSONTextTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
12
{
13
    /**
14
     * @todo There are a ton more permutations of a JSONPath regex
15
     * See the walk() method in JSONStore
16
     */
17 View Code Duplication
    public function testIsValidExpression()
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...
18
    {
19
        $field = JSONText::create('MyJSON');
20
        
21
        $this->assertTrue($field->isValidExpression('$..'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
        $this->assertTrue($field->isValidExpression('$.[2]'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
23
        $this->assertTrue($field->isValidExpression('$.cars.american[*]'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24
        $this->assertFalse($field->isValidExpression('$'));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
25
        $this->assertFalse($field->isValidExpression('$[2]'));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
26
    }
27
28
    /**
29
     * @return void
30
     */
31
    public function testIsValidJson()
32
    {
33
        $field = JSONText::create('MyJSON');
34
35
        $this->assertFalse($field->isValidJson(''));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
        $this->assertTrue($field->isValidJson('true'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
        $this->assertTrue($field->isValidJson('false'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
        $this->assertFalse($field->isValidJson('null'));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
        $this->assertFalse($field->isValidJson("['one']"));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
        $this->assertFalse($field->isValidJson('["one]'));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
        $this->assertFalse($field->isValidJson('{{{'));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
        $this->assertTrue($field->isValidJson('[]'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
        $this->assertTrue($field->isValidJson('["one"]'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
        $this->assertTrue($field->isValidJson('["one","two"]'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
        $this->assertTrue($field->isValidJson('{"cars":{"american":["buick","oldsmobile"]}}'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
    }
47
48
49
    /**
50
     * Ordinarily we can just use !is_null(json_decode($json)) but SS allows empty strings passed to setValue() so we need
51
     * to allow otherwise invalid JSON by means of an optional 2nd param
52
     *
53
     * @return void
54
     */
55 View Code Duplication
    public function testIsValidDBValue()
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...
56
    {
57
        $field = JSONText::create('MyJSON');
58
        
59
        $this->assertFalse($field->isValidDBValue('true'));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
        $this->assertFalse($field->isValidDBValue('false'));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
        $this->assertFalse($field->isValidDBValue('null'));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
        $this->assertTrue($field->isValidDBValue(''));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
        $this->assertTrue($field->isValidJson('["one","two"]'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
        $this->assertTrue($field->isValidJson('{"cars":{"american":["buick","oldsmobile"]}}'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<JSONTextTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
    }
66
}
67