Completed
Push — analysis-8wyw7o ( 0d8c91 )
by Sullivan
22:22 queued 16:34
created

GedmoTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testTranslatableModel() 8 8 1
A testPersonalTranslatableModel() 18 18 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 Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\TranslationBundle\Tests\Traits;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Sonata\TranslationBundle\Model\Gedmo\AbstractPersonalTranslation;
16
use Sonata\TranslationBundle\Model\Gedmo\TranslatableInterface;
17
use Sonata\TranslationBundle\Traits\Gedmo\PersonalTranslatable;
18
use Sonata\TranslationBundle\Traits\Translatable;
19
20
class ModelTranslatable implements TranslatableInterface
21
{
22
    use Translatable;
23
}
24
25
class ModelPersonalTranslatable implements TranslatableInterface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
26
{
27
    use PersonalTranslatable;
28
29
    /**
30
     * @var ArrayCollection
31
     */
32
    protected $translations;
33
34
    public function __construct()
35
    {
36
        $this->translations = new ArrayCollection();
37
    }
38
}
39
40
class ModelPersonalTranslation extends AbstractPersonalTranslation
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
41
{
42
}
43
44
/**
45
 * @author Nicolas Bastien <[email protected]>
46
 */
47 View Code Duplication
class GedmoTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
48
{
49
    /**
50
     * @test Translatable
51
     */
52
    public function testTranslatableModel()
53
    {
54
        $model = new ModelTranslatable();
55
        $model->setLocale('fr');
56
57
        $this->assertSame('fr', $model->getLocale());
58
        $this->assertTrue($model instanceof \Sonata\TranslationBundle\Model\TranslatableInterface);
59
    }
60
61
    /**
62
     * @test PersonalTranslatable
63
     */
64
    public function testPersonalTranslatableModel()
65
    {
66
        $model = new ModelPersonalTranslatable();
67
        $model->setLocale('fr');
68
69
        $this->assertSame('fr', $model->getLocale());
70
        $this->assertTrue($model instanceof \Sonata\TranslationBundle\Model\TranslatableInterface);
71
72
        $model->addTranslation(new ModelPersonalTranslation('en', 'title', 'Title en'));
73
        $model->addTranslation(new ModelPersonalTranslation('it', 'title', 'Title it'));
74
        $model->addTranslation(new ModelPersonalTranslation('es', 'title', 'Title es'));
75
76
        $this->assertSame('Title en', $model->getTranslation('title', 'en'));
77
        $this->assertSame('Title it', $model->getTranslation('title', 'it'));
78
        $this->assertSame('Title es', $model->getTranslation('title', 'es'));
79
80
        $this->assertSame(3, count($model->getTranslations()));
81
    }
82
}
83