Passed
Push — master ( 60f89c...3e6fc7 )
by Jacques
02:01
created

SmartRica   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 35.94 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 0
dl 23
loc 64
ccs 0
cts 23
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B changeownership() 0 37 3
A registrations() 23 23 3

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
 * SmartCall Restful API (v3) HTTP Client.
4
 *
5
 * PLEASE NOTE: The interface is very fluid while the intial integration
6
 * is taking place.  It will be refactored in the near future.
7
 *
8
 * @author    Jacques Marneweck <[email protected]>
9
 * @copyright 2017-2018 Jacques Marneweck.  All rights strictly reserved.
10
 * @license   MIT
11
 */
12
13
namespace Jacques\Smartcall\HttpClient\Traits;
14
15
trait SmartRica
16
{
17
    public function changeownership()
18
    {
19
        try {
20
            $response = $this->post(
0 ignored issues
show
Bug introduced by
It seems like post() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
21
                '/webservice/smartrica/changeownership',
22
                [
23
                    'headers' => [
24
                        'Authorization' => $this->bearerOrBasic(),
0 ignored issues
show
Bug introduced by
It seems like bearerOrBasic() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
25
                    ],
26
                    'json' => [
27
                        'agentId'                => '27821234567',
28
                        'firstName'              => 'Jane',
29
                        'surname'                => 'Doe',
30
                        'idDetails'              => null,
31
                        'registrationType'       => null,
32
                        'subscriberId'           => '8911000000010240123456',
33
                        'last4Iccid'             => '3456',
34
                        'residentialAddress'     => null,
35
                        'previousIdNumber'       => null,
36
                        'previousIdType'         => null,
37
                        'network'                => null,
38
                        'businessOwnerIdDetails' => null,
39
                    ],
40
                ]
41
            );
42
43
            return [
44
                'status'    => 'ok',
45
                'http_code' => $response->getStatusCode(),
46
                'body'      => (string) $response->getBody(),
47
            ];
48
        } catch (\GuzzleHttp\Exception\ClientException $e) {
49
            return $this->clientError($e);
0 ignored issues
show
Bug introduced by
It seems like clientError() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
50
        } catch (\GuzzleHttp\Exception\ServerException $e) {
51
            return $this->parseError($e);
0 ignored issues
show
Bug introduced by
It seems like parseError() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
52
        }
53
    }
54
55 View Code Duplication
    public function registrations()
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...
56
    {
57
        try {
58
            $response = $this->post(
0 ignored issues
show
Bug introduced by
It seems like post() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
59
                '/webservice/smartrica/registrations',
60
                [
61
                    'headers' => [
62
                        'Authorization' => $this->bearerOrBasic(),
0 ignored issues
show
Bug introduced by
It seems like bearerOrBasic() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
63
                    ],
64
                ]
65
            );
66
67
            return [
68
                'status'    => 'ok',
69
                'http_code' => $response->getStatusCode(),
70
                'body'      => (string) $response->getBody(),
71
            ];
72
        } catch (\GuzzleHttp\Exception\ClientException $e) {
73
            return $this->clientError($e);
0 ignored issues
show
Bug introduced by
It seems like clientError() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
74
        } catch (\GuzzleHttp\Exception\ServerException $e) {
75
            return $this->parseError($e);
0 ignored issues
show
Bug introduced by
It seems like parseError() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
76
        }
77
    }
78
}
79