SettingsTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 58.46 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
lcom 1
cbo 3
dl 38
loc 65
rs 10
c 1
b 0
f 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A it_gets_a_setting_without_locale() 19 19 1
A it_gets_setting_in_given_locale() 19 19 1
A it_returns_a_default_value_if_no_setting_found() 0 8 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 namespace Modules\Setting\Tests;
2
3
class SettingsTest extends BaseSettingTest
4
{
5
    /**
6
     * @var \Modules\Setting\Support\Settings
7
     */
8
    protected $setting;
9
10
    public function setUp()
11
    {
12
        parent::setUp();
13
        $this->setting = app('Modules\Setting\Support\Settings');
14
    }
15
16
    /** @test */
17 View Code Duplication
    public function it_gets_a_setting_without_locale()
18
    {
19
        // Prepare
20
        $data = [
21
            'core::site-name' => [
22
                'en' => 'AsgardCMS_en',
23
                'fr' => 'AsgardCMS_fr',
24
            ],
25
            'core::template' => 'asgard',
26
            'blog::posts-per-page' => 10,
27
        ];
28
29
        // Run
30
        $this->settingRepository->createOrUpdate($data);
31
32
        // Assert
33
        $setting = $this->setting->get('core::site-name');
34
        $this->assertEquals('AsgardCMS_en', $setting);
35
    }
36
37
    /** @test */
38 View Code Duplication
    public function it_gets_setting_in_given_locale()
39
    {
40
        // Prepare
41
        $data = [
42
            'core::site-name' => [
43
                'en' => 'AsgardCMS_en',
44
                'fr' => 'AsgardCMS_fr',
45
            ],
46
            'core::template' => 'asgard',
47
            'blog::posts-per-page' => 10,
48
        ];
49
50
        // Run
51
        $this->settingRepository->createOrUpdate($data);
52
53
        // Assert
54
        $setting = $this->setting->get('core::site-name', 'fr');
55
        $this->assertEquals('AsgardCMS_fr', $setting);
56
    }
57
58
    /** @test */
59
    public function it_returns_a_default_value_if_no_setting_found()
60
    {
61
        // Prepare
62
        $setting = $this->setting->get('core::non-existing-setting', 'en', 'defaultValue');
63
64
        // Assert
65
        $this->assertEquals('defaultValue', $setting);
66
    }
67
}
68