GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#16)
by Scott van
20:36 queued 06:48
created

isRemoveRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright (c) 2013-2014 eBay Enterprise, Inc.
4
 *
5
 * NOTICE OF LICENSE
6
 *
7
 * This source file is subject to the Open Software License (OSL 3.0)
8
 * that is bundled with this package in the file LICENSE.md.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * @copyright   Copyright (c) 2013-2014 eBay Enterprise, Inc. (http://www.ebayenterprise.com/)
13
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
14
 */
15
16
/**
17
 * Observer for gift card events in the admin.
18
 */
19
class EbayEnterprise_GiftCard_Model_Adminhtml_Observer
20
{
21
    // post data fields for gift cards
22
    const CARD_NUMBER_PARAM = 'ebay_enterprise_giftcard_code';
23
    const CARD_PIN_PARAM = 'ebay_enterprise_giftcard_pin';
24
    const ACTION_PARAM = 'ebay_enterprise_giftcard_action';
25
    // action "flags" expected to be sent in the post data
26
    const ADD_ACTION = 'add';
27
    const REMOVE_ACTION = 'remove';
28
    /** @var array post data */
29
    protected $request;
30
    /** @var EbayEnterprise_GiftCard_Model_IContainer */
31
    protected $container;
32
    /** @var EbayEnterprise_GiftCard_Helper_Data */
33
    protected $helper;
34
    /** @var EbayEnterprise_MageLog_Helper_Data */
35
    protected $logger;
36
    /** @var EbayEnterprise_MageLog_Helper_Context */
37
    protected $logContext;
38
39
    /**
40
     * @param array
41
     */
42 View Code Duplication
    public function __construct(array $args = [])
0 ignored issues
show
Duplication introduced by
This method 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...
43
    {
44
        list(
45
            $this->container,
46
            $this->helper,
47
            $this->logger,
48
            $this->logContext
49
        ) = $this->checkTypes(
50
            $this->nullCoalesce($args, 'container', Mage::getModel('ebayenterprise_giftcard/container')),
51
            $this->nullCoalesce($args, 'helper', Mage::helper('ebayenterprise_giftcard')),
52
            $this->nullCoalesce($args, 'logger', Mage::helper('ebayenterprise_magelog')),
53
            $this->nullCoalesce($args, 'log_context', Mage::helper('ebayenterprise_magelog/context'))
54
        );
55
    }
56
57
    /**
58
     * @param EbayEnterprise_GiftCard_Model_IContainer
59
     * @param EbayEnterprise_GiftCard_Helper_Data
60
     * @param EbayEnterprise_MageLog_Helper_Data
61
     * @param EbayEnterprise_MageLog_Helper_Context
62
     * @return array
63
     */
64
    protected function checkTypes(
0 ignored issues
show
Unused Code introduced by
The method parameter $container is never used
Loading history...
Unused Code introduced by
The method parameter $helper is never used
Loading history...
Unused Code introduced by
The method parameter $logger is never used
Loading history...
Unused Code introduced by
The method parameter $logContext is never used
Loading history...
65
        EbayEnterprise_GiftCard_Model_IContainer $container,
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
66
        EbayEnterprise_GiftCard_Helper_Data $helper,
0 ignored issues
show
Unused Code introduced by
The parameter $helper is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
67
        EbayEnterprise_MageLog_Helper_Data $logger,
0 ignored issues
show
Unused Code introduced by
The parameter $logger is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
        EbayEnterprise_MageLog_Helper_Context $logContext
0 ignored issues
show
Unused Code introduced by
The parameter $logContext is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
69
    ) {
70
        return func_get_args();
71
    }
72
73
    /**
74
     * Return the value at field in array if it exists. Otherwise, use the default value.
75
     *
76
     * @param  array
77
     * @param  string $field Valid array key
78
     * @param  mixed
79
     * @return mixed
80
     */
81
    protected function nullCoalesce(array $arr, $field, $default)
82
    {
83
        return isset($arr[$field]) ? $arr[$field] : $default;
84
    }
85
86
    /**
87
     * Process post data and set usage of GC into order creation model
88
     *
89
     * @param Varien_Event_Observer $observer
90
     * @return self
91
     */
92
    public function processOrderCreationData(Varien_Event_Observer $observer)
93
    {
94
        if ($this->helper->getConfigModel()->isEnabled) {
0 ignored issues
show
Documentation introduced by
The property isEnabled does not exist on object<EbayEnterprise_Eb..._Model_Config_Registry>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
95
            $this->request = $observer->getEvent()->getRequest();
96
            list($cardNumber, $pin) = $this->getCardInfoFromRequest();
97
            if ($cardNumber) {
98
                $this->processCard($cardNumber, $pin);
99
            }
100
        }
101
        return $this;
102
    }
103
104
    /**
105
     * Add or remove the gift card, depending on the requested action.
106
     *
107
     * @param string $cardNumber
108
     * @param string $pin
109
     * @return self
110
     */
111
    protected function processCard($cardNumber, $pin)
112
    {
113
        if ($this->isAddRequest()) {
114
            $this->addGiftCard($cardNumber, $pin);
115
        } elseif ($this->isRemoveRequest()) {
116
            $this->removeGiftCard($cardNumber);
117
        }
118
        return $this;
119
    }
120
121
    /**
122
     * Is the gift card action param in the request for an add.
123
     *
124
     * @return boolean
125
     */
126
    protected function isAddRequest()
127
    {
128
        return $this->getPostData(self::ACTION_PARAM, '') === self::ADD_ACTION;
129
    }
130
131
    /**
132
     * Is the gift card action param in the request for a remove.
133
     *
134
     * @return boolean
135
     */
136
    protected function isRemoveRequest()
137
    {
138
        return $this->getPostData(self::ACTION_PARAM, '') === self::REMOVE_ACTION;
139
    }
140
141
    /**
142
     * add a giftcard.
143
     *
144
     * @param string $cardNumber
145
     * @param string $pin
146
     * @return self
147
     */
148
    protected function addGiftCard($cardNumber, $pin)
149
    {
150
        $giftcard = $this->container->getGiftCard($cardNumber)->setPin($pin);
151
        try {
152
            $this->helper->addGiftCardToOrder($giftcard, $this->container);
153
        } catch (EbayEnterprise_GiftCard_Exception $e) {
154
            $this->logger->debug('Failed to add gift card to admin order. See exception log for more details.', $this->logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
155
            $this->logger->logException($e, $this->logContext->getMetaData(__CLASS__, [], $e));
156
        }
157
        return $this;
158
    }
159
160
    /**
161
     * remove a giftcard.
162
     *
163
     * @param string $cardNumber
164
     * @return self
165
     */
166
    protected function removeGiftCard($cardNumber)
167
    {
168
        $giftcard = $this->container->getGiftCard($cardNumber);
169
        $this->container->removeGiftCard($giftcard);
170
        return $this;
171
    }
172
173
    /**
174
     * Extract the card number and pin from the request. If either is not present,
175
     * will return an empty string for that value.
176
     *
177
     * @return string[] Tuple of card number and pin
178
     */
179
    protected function getCardInfoFromRequest()
180
    {
181
        return [$this->getPostData(self::CARD_NUMBER_PARAM, ''), $this->getPostData(self::CARD_PIN_PARAM, '')];
182
    }
183
184
    /**
185
     * Get post data from the request. If not set, return the default value.
186
     *
187
     * @param string|int $field
188
     * @param string $default
189
     * @return string
190
     */
191
    protected function getPostData($field, $default)
192
    {
193
        return $this->nullCoalesce($this->request, $field, $default);
194
    }
195
}
196