CreateWepayCustomerTask   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 90.48 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 38
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A run() 13 15 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
namespace App\Containers\Wepay\Tasks;
4
5
use App\Containers\Wepay\Exceptions\WepayApiErrorException;
6
use App\Ship\Parents\Tasks\Task;
7
use Exception;
8
use Illuminate\Support\Facades\Config;
9
use KevinEm\WePay\Laravel\WePayLaravel;
10
11
/**
12
 * Class CreateWepayCustomerTask.
13
 *
14
 * @author Rockers Technologies <[email protected]>
15
 */
16 View Code Duplication
class CreateWepayCustomerTask extends Task
0 ignored issues
show
Duplication introduced by Jaimin Suthar
This class 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...
17
{
18
19
    public $wepayLaravel;
20
21
    /**
22
     * WepayApi constructor.
23
     *
24
     * @param \KevinEm\WePay\Laravel\WePayLaravel $wepayLaravel
25
     */
26
    public function __construct(WePayLaravel $wepayLaravel)
27
    {
28
        $this->wepayLaravel = $wepayLaravel->make(
29
            Config::get('wepay-container.client_secret'),
30
            Config::get('wepay-container.version')
31
        );
32
    }
33
34
    /**
35
     * @param        $email
36
     * @param string $description
37
     *
38
     * @return array Wepay customer object
39
     * @throws WepayApiErrorException
40
     */
41
    public function run($email, $description = '')
42
    {
43
        try {
44
45
            $response = $this->wepayLaravel->customers()->create([
46
                'email'       => $email,
47
                'description' => $description,
48
            ]);
49
50
        } catch (Exception $e) {
51
            throw (new WepayApiErrorException('Wepay API error (createCustomer)'))->debug($e->getMessage(), true);
52
        }
53
54
        return $response;
55
    }
56
57
}
58