Passed
Pull Request — master (#300)
by
unknown
02:30
created

AmastyGiftcard   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 47
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAmastyGiftCards() 0 12 3
A hasAmastyGiftcards() 0 7 2
1
<?php
2
3
/**
4
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * PHP version 5
18
 *
19
 * @category  Payone
20
 * @package   Payone_Magento2_Plugin
21
 * @author    FATCHIP GmbH <[email protected]>
22
 * @copyright 2003 - 2020 Payone GmbH
23
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
24
 * @link      http://www.payone.de
25
 */
26
27
namespace Payone\Core\Helper;
28
29
/**
30
 * Helper class for Amasty giftcards
31
 */
32
class AmastyGiftcard extends \Payone\Core\Helper\Base
33
{
34
    /**
35
     * Array of amasty giftcards
36
     *
37
     * @var array
38
     */
39
    protected $aAmastyGiftcard = null;
40
41
    /**
42
     * Checks if Amasty Giftcard class is existing and returns the used giftcards for this order
43
     *
44
     * We are aware that the ObjectManager should not be called like this,
45
     * but since most shops won't have this module installed we can't load it with the dependency injection in the constructor.
46
     *
47
     * If there is a better way to solve this optional injection/soft dependancy feel free to tell us.
48
     *
49
     * @param  string $sQuoteId
50
     * @return array
51
     */
52
    public function getAmastyGiftCards($sQuoteId)
53
    {
54
        if ($this->aAmastyGiftcard === null) {
55
            $this->aAmastyGiftcard = [];
56
            if (class_exists('\Amasty\GiftCard\Model\ResourceModel\Quote\CollectionFactory')) {
57
                $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
0 ignored issues
show
Bug introduced by
The type Magento\Framework\App\ObjectManager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
58
59
                $giftCardsCollection = $objectManager->create('Amasty\GiftCard\Model\ResourceModel\Quote\CollectionFactory');
60
                $this->aAmastyGiftcard = $giftCardsCollection->create()->getGiftCardsWithAccount($sQuoteId)->getData();
61
            }
62
        }
63
        return $this->aAmastyGiftcard;
64
    }
65
66
    /**
67
     * Determine if order has used amasty giftcards
68
     *
69
     * @param  string $sQuoteId
70
     * @return bool
71
     */
72
    public function hasAmastyGiftcards($sQuoteId)
73
    {
74
        $aGiftCards = $this->getAmastyGiftCards($sQuoteId);
75
        if (!empty($aGiftCards)) {
76
            return true;
77
        }
78
        return false;
79
    }
80
}
81