FakeVoucherYear   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A get() 4 4 1
A vatAccountIsSet() 4 4 1
A getSetting() 4 4 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
require_once 'Intraface/modules/accounting/Voucher.php';
3
require_once 'Intraface/modules/accounting/VoucherFile.php';
4
5 View Code Duplication
class FakeVoucherYear
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...
6
{
7
    public $kernel;
8
    function __construct()
9
    {
10
        $this->kernel = new Stub_Kernel;
11
        $this->kernel->setting->set('intranet', 'vatpercent', 25);
12
    }
13
    function get()
14
    {
15
        return 1;
16
    }
17
    function vatAccountIsSet()
18
    {
19
        return true;
20
    }
21
    function getSetting()
22
    {
23
        return 1;
24
    }
25
}
26
27
class VoucherTest extends PHPUnit_Framework_TestCase
28
{
29
    private $year;
30
31
    function setUp()
32
    {
33
        $this->year = new FakeVoucherYear;
34
    }
35
36
    function testVoucherCreate()
37
    {
38
        // TODO needs to be updated
39
        $voucher = new Voucher($this->year);
40
        $this->assertFalse($voucher->get('id') > 0);
41
        $voucher->save(array('text' => 'Description', 'date' => '2002-10-10'));
42
        $new_voucher = new Voucher($this->year, $voucher->get('id'));
43
        $new_voucher->save(array('text' => 'Description - edited', 'date' => '2002-10-10'));
44
        $this->assertTrue($voucher->get('id') == $new_voucher->get('id'));
45
        $this->assertTrue($new_voucher->get('text') == 'Description - edited');
46
    }
47
48
    function testVatCalculation()
49
    {
50
        $this->assertTrue((80 + Voucher::calculateVat(100, 25)) == 100);
0 ignored issues
show
Deprecated Code introduced by
The method Voucher::calculateVat() has been deprecated.

This method has been deprecated.

Loading history...
51
        $this->assertTrue((100 + Voucher::calculateVat(110, 10)) == 110);
0 ignored issues
show
Deprecated Code introduced by
The method Voucher::calculateVat() has been deprecated.

This method has been deprecated.

Loading history...
52
        $this->assertTrue(round((93.40 + Voucher::calculateVat(100.41, 7.5)), 2) == 100.41);
0 ignored issues
show
Deprecated Code introduced by
The method Voucher::calculateVat() has been deprecated.

This method has been deprecated.

Loading history...
53
    }
54
55
    function testDeleteReturnsTrue()
56
    {
57
        $voucher = new Voucher($this->year);
58
        $voucher->save(array('text' => 'Description', 'date' => '2002-10-10'));
59
        $this->assertTrue($voucher->delete());
60
    }
61
62
    function testStateDraftReturnsFalseWhenNoPostsAreFound()
63
    {
64
        $voucher = new Voucher($this->year);
65
        $voucher->save(array('text' => 'Description', 'date' => '2002-10-10'));
66
        $res = $voucher->stateDraft();
67
        $this->assertFalse($res);
68
    }
69
70
    function testStateVoucherReturnsTrueWhenNoPostsAreFound()
71
    {
72
        $voucher = new Voucher($this->year);
73
        $voucher->save(array('text' => 'Description', 'date' => '2002-10-10'));
74
        $this->assertTrue($voucher->stateVoucher());
75
    }
76
77
    function testGetList()
78
    {
79
        $voucher = new Voucher($this->year);
80
        $this->assertTrue(is_array($voucher->getList()));
81
    }
82
}
83