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.

CouponService::getCoupons()   B
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 16
cts 16
cp 1
rs 8.9197
c 0
b 0
f 0
cc 4
eloc 13
nc 5
nop 1
crap 4
1
<?php
2
3
namespace Speicher210\Monsum\Api\Service\Coupon;
4
5
use Speicher210\Monsum\Api\AbstractService;
6
7
/**
8
 * Service for coupon.
9
 */
10
class CouponService extends AbstractService
11
{
12
    /**
13
     * Get the coupons.
14
     *
15
     * @param string $code The code to get.
16
     * @return Get\ApiResponse
17
     */
18 3
    public function getCoupons($code = null)
19
    {
20 3
        $requestData = new Get\RequestData($code);
21 3
        $request = new Get\Request($requestData);
22
23 3
        $apiResponse = $this->sendRequest($request, Get\ApiResponse::class);
24
        /** @var Get\Response $response */
25 3
        $response = $apiResponse->getResponse();
26 3
        foreach ($response->getCoupons() as $coupon) {
27 3
            $validFrom = $coupon->getValidFrom();
28 3
            if ($validFrom !== null) {
29 3
                $validFrom->setTime(0, 0, 0);
30 3
            }
31
32 3
            $validTo = $coupon->getValidTo();
33 3
            if ($validTo !== null) {
34 3
                $validTo->setTime(0, 0, 0);
35 3
            }
36 3
        }
37
38 3
        return $apiResponse;
39
    }
40
41
    /**
42
     * Check a coupon.
43
     *
44
     * @param string $code The code to check.
45
     * @param string $articleNumber The article number.
46
     * @return Check\ApiResponse
47
     */
48 12
    public function checkCoupon($code, $articleNumber)
49
    {
50 12
        $requestData = new Check\RequestData($code, $articleNumber);
51 12
        $request = new Check\Request($requestData);
52
53 12
        return $this->sendRequest($request, Check\ApiResponse::class);
54
    }
55
56
    /**
57
     * Check if a coupon is valid or not.
58
     *
59
     * @param string $code The code to check.
60
     * @param string $articleNumber The article number.
61
     * @return boolean
62
     */
63 6
    public function isCouponValid($code, $articleNumber)
64
    {
65 6
        return $this->checkCoupon($code, $articleNumber)->getResponse()->isStatusValid();
66
    }
67
}
68