Completed
Push — master ( ce2be0...7bcb9a )
by Olivier
02:08
created

Subscription   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 78
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 41.38%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 4
dl 26
loc 78
ccs 12
cts 29
cp 0.4138
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 10 2
A all() 0 10 2
A create() 13 13 2
A cancel() 13 13 2
A getItem() 0 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace Shapin\Stripe\Api;
11
12
use Shapin\Stripe\Configuration;
13
use Shapin\Stripe\Exception;
14
use Shapin\Stripe\Model\Subscription\Item;
15
use Shapin\Stripe\Model\Subscription\Subscription as SubscriptionModel;
16
use Shapin\Stripe\Model\Subscription\SubscriptionCollection;
17
use Symfony\Component\Config\Definition\Processor;
18
19
final class Subscription extends HttpApi
20
{
21
    /**
22
     * @throws Exception
23
     */
24 1
    public function get(string $id)
25
    {
26 1
        $response = $this->httpGet("/v1/subscriptions/$id");
27
28 1
        if (200 !== $response->getStatusCode()) {
29
            $this->handleErrors($response);
30
        }
31
32 1
        return $this->hydrator->hydrate($response, SubscriptionModel::class);
33
    }
34
35
    /**
36
     * @throws Exception
37
     */
38 1
    public function all(array $params = [])
39
    {
40 1
        $response = $this->httpGet('/v1/subscriptions'.http_build_query($params));
41
42 1
        if (200 !== $response->getStatusCode()) {
43
            $this->handleErrors($response);
44
        }
45
46 1
        return $this->hydrator->hydrate($response, SubscriptionCollection::class);
47
    }
48
49
    /**
50
     * @throws Exception
51
     */
52 View Code Duplication
    public function create(array $params)
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...
53
    {
54
        $processor = new Processor();
55
        $params = $processor->processConfiguration(new Configuration\SubscriptionCreate(), [$params]);
56
57
        $response = $this->httpPostRaw('/v1/subscriptions', http_build_query($params), ['Content-Type' => 'application/x-www-form-urlencoded']);
58
59
        if (200 !== $response->getStatusCode()) {
60
            $this->handleErrors($response);
61
        }
62
63
        return $this->hydrator->hydrate($response, SubscriptionModel::class);
64
    }
65
66
    /**
67
     * @throws Exception
68
     */
69 View Code Duplication
    public function cancel(string $id, array $params = [])
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...
70
    {
71
        $processor = new Processor();
72
        $params = $processor->processConfiguration(new Configuration\SubscriptionCancel(), [$params]);
73
74
        $response = $this->httpDelete("/v1/subscriptions/$id?".http_build_query($params));
75
76
        if (200 !== $response->getStatusCode()) {
77
            $this->handleErrors($response);
78
        }
79
80
        return $this->hydrator->hydrate($response, SubscriptionModel::class);
81
    }
82
83
    /**
84
     * @throws Exception
85
     */
86 1
    public function getItem(string $id)
87
    {
88 1
        $response = $this->httpGet("/v1/subscription_items/$id");
89
90 1
        if (200 !== $response->getStatusCode()) {
91
            $this->handleErrors($response);
92
        }
93
94 1
        return $this->hydrator->hydrate($response, Item::class);
95
    }
96
}
97