Completed
Pull Request — master (#33)
by Daniel
16:52 queued 13:40
created

ScalarTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 91.53 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 54
loc 59
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 26 26 1
A testStringCollection() 14 14 1
A testIntegerCollection() 14 14 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 Psi\Bridge\ContentType\Doctrine\PhpcrOdm\Tests\Functional;
4
5
use Psi\Bridge\ContentType\Doctrine\PhpcrOdm\Tests\Functional\Example\Article;
6
7
class ScalarTest extends PhpcrOdmTestCase
8
{
9 View Code Duplication
    public function setUp()
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
    {
11
        $container = $this->getContainer([
12
            'mapping' => [
13
                Article::class => [
14
                    'fields' => [
15
                        'paragraphs' => [
16
                            'type' => 'collection',
17
                            'options' => [
18
                                'field' => 'text',
19
                                'field_options' => [],
20
                            ],
21
                        ],
22
                        'numbers' => [
23
                            'type' => 'collection',
24
                            'options' => [
25
                                'field' => 'integer',
26
                            ],
27
                        ],
28
                    ],
29
                ],
30
            ],
31
        ]);
32
        $this->documentManager = $container->get('doctrine_phpcr.document_manager');
0 ignored issues
show
Bug introduced by
The property documentManager does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33
        $this->initPhpcr($this->documentManager);
34
    }
35
36 View Code Duplication
    public function testStringCollection()
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...
37
    {
38
        $article = new Article();
39
        $article->id = '/test/article';
40
        $article->title = 'Foo';
41
        $article->paragraphs = ['one', 'two', 'three'];
42
43
        $this->documentManager->persist($article);
44
        $this->documentManager->flush();
45
        $this->documentManager->clear();
46
47
        $article = $this->documentManager->find(null, '/test/article');
48
        $this->assertSame(['one', 'two', 'three'], $article->paragraphs);
49
    }
50
51 View Code Duplication
    public function testIntegerCollection()
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...
52
    {
53
        $article = new Article();
54
        $article->id = '/test/article';
55
        $article->title = 'Foo';
56
        $article->numbers = ['12', '13', '14'];
57
58
        $this->documentManager->persist($article);
59
        $this->documentManager->flush();
60
        $this->documentManager->clear();
61
62
        $article = $this->documentManager->find(null, '/test/article');
63
        $this->assertSame([12, 13, 14], $article->numbers);
64
    }
65
}
66