DecrementTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 35.71 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
lcom 1
cbo 1
dl 10
loc 28
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A a_row_decrements() 0 12 1
A a_row_does_not_decrement() 10 10 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 LarsJanssen\IncrementDecrement\Test\core;
4
5
use LarsJanssen\IncrementDecrement\Test\TestCase;
6
use LarsJanssen\IncrementDecrement\Test\TestModel;
7
8
class DecrementTest extends TestCase
9
{
10
    /** @test */
11
    public function a_row_decrements()
12
    {
13
        $row = TestModel::where('order', 5)->first();
14
        $this->assertEquals(5, $row->order);
15
        $this->order->decrement($row);
16
        $this->assertEquals(1, $row->order);
17
18
        $this->assertEquals(2, TestModel::where('name', 'food')->first()->order);
19
        $this->assertEquals(3, TestModel::where('name', 'work')->first()->order);
20
        $this->assertEquals(4, TestModel::where('name', 'children')->first()->order);
21
        $this->assertEquals(5, TestModel::where('name', 'ict')->first()->order);
22
    }
23
24
    /** @test */
25 View Code Duplication
    public function a_row_does_not_decrement()
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...
26
    {
27
        $this->app['config']->set('increment-decrement.last_row_can_decrement', false);
28
29
        $row = TestModel::where('order', 5)->first();
30
31
        $this->assertEquals(5, $row->order);
32
        $this->order->decrement($row);
33
        $this->assertEquals(5, $row->order);
34
    }
35
}
36