Completed
Pull Request — experimental/sf (#3412)
by Kentaro
14:51 queued 07:29
created

TaxRuleService::calcTaxIncluded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 4
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Service;
15
16
use Eccube\Repository\TaxRuleRepository;
17
18
class TaxRuleService
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
19
{
20
    /**
21
     * @var TaxRuleRepository
22
     */
23
    protected $taxRuleRepository;
24
25 469
    public function __construct(TaxRuleRepository $taxRuleRepository)
26
    {
27 469
        $this->taxRuleRepository = $taxRuleRepository;
28
    }
29
30
    /**
31
     * 設定情報に基づいて税金の金額を返す
32
     *
33
     * @param  int                                    $price        計算対象の金額
34
     * @param  int|null|\Eccube\Entity\Product        $product      商品
35
     * @param  int|null|\Eccube\Entity\ProductClass   $productClass 商品規格
36
     * @param  int|null|\Eccube\Entity\Master\Pref    $pref         都道府県
37
     * @param  int|null|\Eccube\Entity\Master\Country $country      国
38
     *
39
     * @return double                                 税金付与した金額
40
     */
41 463
    public function getTax($price, $product = null, $productClass = null, $pref = null, $country = null)
42
    {
43
        /* @var $TaxRule \Eccube\Entity\TaxRule */
44 463
        $TaxRule = $this->taxRuleRepository->getByRule($product, $productClass, $pref, $country);
45
46 463
        return $this->calcTax($price, $TaxRule->getTaxRate(), $TaxRule->getRoundingType()->getId(), $TaxRule->getTaxAdjust());
47
    }
48
49
    /**
50
     * calcIncTax
51
     *
52
     * @param  int                                    $price        計算対象の金額
53
     * @param  int|null|\Eccube\Entity\Product        $product      商品
54
     * @param  int|null|\Eccube\Entity\ProductClass   $productClass 商品規格
55
     * @param  int|null|\Eccube\Entity\Master\Pref    $pref         都道府県
56
     * @param  int|null|\Eccube\Entity\Master\Country $country      国
57
     *
58
     * @return int
59
     */
60 462
    public function getPriceIncTax($price, $product = null, $productClass = null, $pref = null, $country = null)
61
    {
62 462
        return $price + $this->getTax($price, $product, $productClass, $pref, $country);
63
    }
64
65
    /**
66
     * 税金額を計算する
67
     *
68
     * @param  int    $price     計算対象の金額
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 4 found
Loading history...
introduced by
Expected 8 spaces after parameter name; 5 found
Loading history...
69
     * @param  int    $taxRate   税率(%単位)
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 4 found
Loading history...
introduced by
Expected 6 spaces after parameter name; 3 found
Loading history...
70
     * @param  int    $RoundingType  端数処理
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 4 found
Loading history...
introduced by
Expected 1 spaces after parameter name; 2 found
Loading history...
71
     * @param  int    $taxAdjust 調整額
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 4 found
Loading history...
introduced by
Expected 4 spaces after parameter name; 1 found
Loading history...
72
     *
73
     * @return double 税金額
74
     */
75 465
    public function calcTax($price, $taxRate, $RoundingType, $taxAdjust = 0)
76
    {
77 465
        $tax = $price * $taxRate / 100;
78 465
        $roundTax = $this->roundByRoundingType($tax, $RoundingType);
79
80 465
        return $roundTax + $taxAdjust;
81
    }
82
83
    /**
84
     * 税込金額から税金額を計算する
85
     *
86
     * @param  int    $price     計算対象の金額
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 4 found
Loading history...
introduced by
Expected 8 spaces after parameter name; 5 found
Loading history...
87
     * @param  int    $taxRate   税率(%単位)
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 4 found
Loading history...
introduced by
Expected 6 spaces after parameter name; 3 found
Loading history...
88
     * @param  int    $RoundingType  端数処理
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 4 found
Loading history...
introduced by
Expected 1 spaces after parameter name; 2 found
Loading history...
89
     * @param  int    $taxAdjust 調整額
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 4 found
Loading history...
introduced by
Expected 4 spaces after parameter name; 1 found
Loading history...
90
     *
91
     * @return float  税金額
92
     */
93 203
    public function calcTaxIncluded($price, $taxRate, $RoundingType, $taxAdjust = 0)
94
    {
95 203
        $tax = ($price - $taxAdjust) * $taxRate / (100 + $taxRate);
96
97 203
        return $this->roundByRoundingType($tax, $RoundingType);
98
    }
99
100
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$RoundingType" missing
Loading history...
101
     * 課税規則に応じて端数処理を行う
102
     *
103
     * @param  float|integer $value    端数処理を行う数値
104
     * @param  integer       $calcRule 課税規則
0 ignored issues
show
Bug introduced by
There is no parameter named $calcRule. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
introduced by
Doc comment for parameter $calcRule does not match actual variable name $RoundingType
Loading history...
105
     *
106
     * @return double        端数処理後の数値
107
     */
108 469
    public function roundByRoundingType($value, $RoundingType)
109
    {
110
        switch ($RoundingType) {
111
            // 四捨五入
112 469
            case \Eccube\Entity\Master\RoundingType::ROUND:
113 466
                $ret = round($value);
114 466
                break;
115
            // 切り捨て
116 3
            case \Eccube\Entity\Master\RoundingType::FLOOR:
117 1
                $ret = floor($value);
118 1
                break;
119
            // 切り上げ
120 2
            case \Eccube\Entity\Master\RoundingType::CEIL:
121 1
                $ret = ceil($value);
122 1
                break;
123
            // デフォルト:切り上げ
124
            default:
125 1
                $ret = ceil($value);
126 1
                break;
127
        }
128
129 469
        return $ret;
130
    }
131
}
132