Failed Conditions
Pull Request — experimental/3.1 (#2526)
by Kentaro
40:11 queued 13:18
created

TaxRuleService::roundByRoundingType()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 15
c 0
b 0
f 0
nc 4
nop 2
dl 0
loc 23
ccs 13
cts 13
cp 1
crap 4
rs 8.7972
1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
25
namespace Eccube\Service;
26
27
use Eccube\Annotation\Inject;
28
use Eccube\Annotation\Service;
29
use Eccube\Repository\TaxRuleRepository;
30
31
/**
32
 * @Service
33
 */
34
class TaxRuleService
35
{
36
    /**
37
     * @Inject(TaxRuleRepository::class)
38
     * @var TaxRuleRepository
39
     */
40
    protected $taxRuleRepository;
41
42
    /**
43
     * 設定情報に基づいて税金の金額を返す
44
     *
45
     * @param  int                                    $price        計算対象の金額
46
     * @param  int|null|\Eccube\Entity\Product        $product      商品
47
     * @param  int|null|\Eccube\Entity\ProductClass   $productClass 商品規格
48
     * @param  int|null|\Eccube\Entity\Master\Pref    $pref         都道府県
49
     * @param  int|null|\Eccube\Entity\Master\Country $country      国
50
     * @return double                                 税金付与した金額
51
     */
52 289
    public function getTax($price, $product = null, $productClass = null, $pref = null, $country = null)
53
    {
54
        /* @var $TaxRule \Eccube\Entity\TaxRule */
55 289
        $TaxRule = $this->taxRuleRepository->getByRule($product, $productClass, $pref, $country);
56
57 289
        return $this->calcTax($price, $TaxRule->getTaxRate(), $TaxRule->getRoundingType()->getId(), $TaxRule->getTaxAdjust());
58
    }
59
60
    /**
61
     * calcIncTax
62
     *
63
     * @param  int                                    $price        計算対象の金額
64
     * @param  int|null|\Eccube\Entity\Product        $product      商品
65
     * @param  int|null|\Eccube\Entity\ProductClass   $productClass 商品規格
66
     * @param  int|null|\Eccube\Entity\Master\Pref    $pref         都道府県
67
     * @param  int|null|\Eccube\Entity\Master\Country $country      国
68
     * @return int
69
     */
70 288
    public function getPriceIncTax($price, $product = null, $productClass = null, $pref = null, $country = null)
71
    {
72 288
        return $price + $this->getTax($price, $product, $productClass, $pref, $country);
73
    }
74
75
    /**
76
     * 税金額を計算する
77
     *
78
     * @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...
79
     * @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...
80
     * @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...
81
     * @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...
82
     * @return double 税金額
83
     */
84 291
    public function calcTax($price, $taxRate, $RoundingType, $taxAdjust = 0)
85
    {
86 291
        $tax = $price * $taxRate / 100;
87 291
        $roundTax = $this->roundByRoundingType($tax, $RoundingType);
88
89 291
        return $roundTax + $taxAdjust;
90
    }
91
92
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$RoundingType" missing
Loading history...
93
     * 課税規則に応じて端数処理を行う
94
     *
95
     * @param  float|integer $value    端数処理を行う数値
96
     * @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...
97
     * @return double        端数処理後の数値
98
     */
99 295
    public function roundByRoundingType($value, $RoundingType)
100
    {
101
        switch ($RoundingType) {
102
            // 四捨五入
103 295
            case \Eccube\Entity\Master\RoundingType::ROUND:
104 292
                $ret = round($value);
105 292
                break;
106
            // 切り捨て
107 3
            case \Eccube\Entity\Master\RoundingType::FLOOR:
108 1
                $ret = floor($value);
109 1
                break;
110
            // 切り上げ
111 2
            case \Eccube\Entity\Master\RoundingType::CEIL:
112 1
                $ret = ceil($value);
113 1
                break;
114
            // デフォルト:切り上げ
115
            default:
116 1
                $ret = ceil($value);
117 1
                break;
118
        }
119
120 295
        return $ret;
121
    }
122
}
123