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   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 10
dl 0
loc 58
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B getCoupons() 0 22 4
A checkCoupon() 0 7 1
A isCouponValid() 0 4 1
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