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.

ArticleService::generateCheckoutURLForCustomer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 9.6666
ccs 2
cts 2
cp 1
cc 1
eloc 6
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Speicher210\Monsum\Api\Service\Article;
4
5
use Speicher210\Monsum\Api\AbstractService;
6
use Speicher210\Monsum\Api\Model\Article;
7
use Speicher210\Monsum\Api\Model\Customer;
8
use Speicher210\Monsum\Api\Model\CustomerQueryParams;
9
use Speicher210\Monsum\Api\Model\Subscription;
10
11
/**
12
 * Service for articles.
13
 */
14
class ArticleService extends AbstractService
15
{
16
    /**
17
     * Get the articles.
18
     *
19
     * @param string $articleNumber Article number to filter on.
20
     * @return Get\ApiResponse
21 3
     */
22
    public function getArticles($articleNumber = null)
23 3
    {
24 3
        $requestData = new Get\RequestData();
25
        $requestData->setArticleNumber($articleNumber);
26 3
27
        $request = new Get\Request($requestData);
28 3
29
        return $this->sendRequest($request, Get\ApiResponse::class);
30
    }
31
32
    /**
33
     * Get one article by article number.
34
     *
35
     * @param string $articleNumber Article number of the article to get.
36
     * @return Article|null
37 12
     */
38
    public function getArticle($articleNumber)
39 12
    {
40 12
        $requestData = new Get\RequestData();
41
        $requestData->setArticleNumber($articleNumber);
42 12
43 12
        $request = new Get\Request($requestData);
44
        $request->setLimit(1);
45
46 12
        /** @var Get\ApiResponse $apiResponse */
47 12
        $apiResponse = $this->sendRequest($request, Get\ApiResponse::class);
48
        $articles = $apiResponse->getResponse()->getArticles();
49 12
50
        return isset($articles[0]) ? $articles[0] : null;
51
    }
52
53
    /**
54
     * Get the article checkout URL.
55
     *
56
     * @param Article $article The article.
57
     * @param Customer|null $customer The customer.
58
     * @return string
59 9
     */
60
    public function getArticleCheckoutURL(Article $article, Customer $customer = null)
61 9
    {
62 3
        if ($customer === null) {
63
            return $article->getCheckoutUrl();
64
        }
65 6
66
        return $this->generateCheckoutURLForCustomer($customer->getHash(), $article->getArticleNumber());
67
    }
68
69
    /**
70
     * Get the article checkout URL with customer query params.
71
     *
72
     * @param Article $article The article.
73
     * @param CustomerQueryParams $params The customer query params
74
     * @return string
75
     */
76 9
    public function getArticleCheckoutUrlWithQueryParams(Article $article, CustomerQueryParams $params)
77
    {
78 9
        return $article->getCheckoutUrl() . (string)$params;
79 9
    }
80 3
81
    /**
82
     * Get the checkout URL for an article.
83 6
     *
84
     * @param string $articleNumber Article number of the article to get the checkout URL.
85
     * @param Customer $customer The customer for which the checkout URL should be created.
86
     * @return string
87
     * @throws \OutOfBoundsException If the article is not found.
88
     */
89
    public function getArticleNumberCheckoutURL($articleNumber, Customer $customer = null)
90
    {
91
        $article = $this->getArticle($articleNumber);
92
        if ($article === null) {
93
            throw new \OutOfBoundsException('Article not found.');
94
        }
95
96
        return $this->getArticleCheckoutURL($article, $customer);
97
    }
98
99
    /**
100
     * Get the checkout URL for an article.
101
     *
102
     * @deprecated Use getArticleNumberCheckoutURL
103
     *
104
     * @param string $articleNumber Article number of the article to get the checkout URL.
105
     * @param Customer $customer The customer for which the checkout URL should be created.
106
     * @return string
107 6
     */
108
    public function getCheckoutURL($articleNumber, Customer $customer = null)
109 6
    {
110 6
        return $this->getArticleNumberCheckoutURL($articleNumber, $customer);
111 6
    }
112 6
113
    /**
114 6
     * Get the checkout URL of an article for a customer.
115
     *
116
     * @param string $customerHash The customer hash.
117
     * @param string $articleNumber The article number.
118
     * @return string
119
     */
120
    protected function generateCheckoutURLForCustomer($customerHash, $articleNumber)
121
    {
122
        return sprintf(
123
            'https://app.monsum.com/checkout/0/%s/%s/%s',
124 3
            $this->transport->getCredentials()->getAccountHash(),
125
            $customerHash,
126 3
            $articleNumber
127
        );
128
    }
129
130
    /**
131
     * Get the checkout URL to change a product for a subscription.
132
     *
133
     * @param Subscription $subscription The subscription.
134
     * @param Article $article The new article.
135
     * @return string
136 3
     */
137
    public function getSubscriptionProductChangeURL(Subscription $subscription, Article $article)
138 3
    {
139 3
        return $this->generateSubscriptionProductChangeURL($subscription->getHash(), $article->getArticleNumber());
140 3
    }
141 3
142
    /**
143 3
     * Get the checkout URL to change a product for a subscription.
144
     *
145
     * @param string $subscriptionId The subscription ID.
146
     * @param string $articleNumber The new article number.
147
     * @return string
148
     */
149
    protected function generateSubscriptionProductChangeURL($subscriptionId, $articleNumber)
150
    {
151
        return sprintf(
152
            'https://app.monsum.com/change/%s/%s/%s',
153
            $this->transport->getCredentials()->getAccountHash(),
154
            $subscriptionId,
155
            $articleNumber
156
        );
157
    }
158
}
159