Failed Conditions
Pull Request — 4.0 (#4302)
by chihiro
04:25
created

TaxExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.ec-cube.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\Twig\Extension;
15
16
use Eccube\Common\EccubeConfig;
17
use Eccube\Entity\Master\ProductStatus;
18
use Eccube\Entity\Product;
19
use Eccube\Entity\ProductClass;
20
use Eccube\Entity\TaxRule;
21
use Eccube\Repository\ProductRepository;
22
use Eccube\Repository\TaxRuleRepository;
23
use Eccube\Util\StringUtil;
24
use Symfony\Component\Form\FormView;
25
use Symfony\Component\Intl\Intl;
26
use Twig\Extension\AbstractExtension;
27
use Twig\TwigFilter;
28
use Twig\TwigFunction;
29
30
class TaxExtension extends AbstractExtension
31
{
32
    /**
33
     * @var TaxRuleRepository
34
     */
35
    private $taxRuleRepository;
36
37
    /**
38
     * TaxExtension constructor.
39
     * @param TaxRuleRepository $taxRuleRepository
40
     */
41
    public function __construct(TaxRuleRepository $taxRuleRepository)
42
    {
43
        $this->taxRuleRepository = $taxRuleRepository;
44
    }
45
46
    /**
47
     * Returns a list of functions to add to the existing list.
48
     *
49
     * @return TwigFunction[] An array of functions
50
     */
51
    public function getFunctions()
52
    {
53
        return [
54
            new TwigFunction('is_reduced_tax_rate', [$this, 'isReducedTaxRate']),
55
        ];
56
    }
57
58
    /**
59
     * 明細が軽減税率対象かどうかを返す.
60
     *
61
     * 受注作成時点での標準税率と比較し, 異なれば軽減税率として判定する.
62
     *
63
     * @param null $OrderItem
64
     * @return bool
65
     */
66
    public function isReducedTaxRate($OrderItem = null)
67
    {
68
        if (null === $OrderItem) {
69
            return false;
70
        }
71
72
        $Order = $OrderItem->getOrder();
0 ignored issues
show
Bug introduced by
The method getOrder cannot be called on $OrderItem (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
73
74
        $qb = $this->taxRuleRepository->createQueryBuilder('t');
75
        try {
76
            $TaxRule = $qb
77
                ->where('t.Product IS NULL AND t.ProductClass IS NULL AND t.apply_date < :apply_date')
78
                ->orderBy('t.apply_date', 'DESC')
79
                ->setParameter('apply_date', $Order->getCreateDate())
80
                ->setMaxResults(1)
81
                ->getQuery()
82
                ->getOneOrNullResult();
83
        } catch (\Exception $e) {
84
            return false;
85
        }
86
87
        return $TaxRule && $TaxRule->getTaxRate() != $OrderItem->getTaxRate();
0 ignored issues
show
Bug introduced by
The method getTaxRate cannot be called on $OrderItem (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
88
    }
89
}
90