Electricity   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A getDiscosAndMinMax() 4 4 1
A verifyMeterNumber() 7 7 1
A buyElectricity() 12 12 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
 * Created By: Henry Ejemuta
4
 * PC: Enrico Systems
5
 * Project: laravel-clubkonnect
6
 * Company: Stimolive Technologies Limited
7
 * Class Name: Transaction.php
8
 * Date Created: 5/14/21
9
 * Time Created: 10:24 AM
10
 */
11
12
namespace HenryEjemuta\LaravelClubKonnect;
13
14
use HenryEjemuta\LaravelClubKonnect\Classes\ClubKonnectResponse;
15
use HenryEjemuta\LaravelClubKonnect\Enums\DiscoEnum;
16
use HenryEjemuta\LaravelClubKonnect\Enums\MeterTypeEnum;
17
18 View Code Duplication
abstract class Electricity
0 ignored issues
show
Duplication introduced by
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...
19
{
20
    private $config;
21
    private $clubKonnect;
22
23
    public function __construct(ClubKonnect $clubKonnect, $config)
24
    {
25
        $this->config = $config;
26
        $this->clubKonnect = $clubKonnect;
27
    }
28
29
    /**
30
     * @return ClubKonnectResponse
31
     */
32
    public function getDiscosAndMinMax(): ClubKonnectResponse
33
    {
34
        return $this->clubKonnect->withAuth('APIElectricityDiscosV1.asp', []);
35
    }
36
37
    /**
38
     * @param DiscoEnum $disco
39
     * @param $meterNumber
40
     * @return ClubKonnectResponse
41
     */
42
    public function verifyMeterNumber(DiscoEnum $disco, $meterNumber): ClubKonnectResponse
43
    {
44
        return $this->clubKonnect->withAuth('APIVerifyElectricityV1.asp', [
45
            'ElectricCompany' => $disco->getCode(),
46
            'MeterNo' => $meterNumber,
47
        ]);
48
    }
49
50
    /**
51
     * @param DiscoEnum $disco
52
     * @param $meterNumber
53
     * @param $amount
54
     * @param MeterTypeEnum $meterType
55
     * @param $requestID
56
     * @param $callbackUrl
57
     * @return ClubKonnectResponse
58
     */
59
    public function buyElectricity(DiscoEnum $disco, $meterNumber, $amount, MeterTypeEnum $meterType, $requestID, $callbackUrl = null): ClubKonnectResponse
60
    {
61
        $callbackUrl = is_null($callbackUrl) ? $this->config['default_redirect_url'] : $callbackUrl;
62
        return $this->clubKonnect->withAuth('APIElectricityV1.asp', [
63
            'ElectricCompany' => $disco->getCode(),
64
            'MeterNo' => $meterNumber,
65
            'Amount' => $amount,
66
            'MeterType' => $meterType->getCode(),
67
            'RequestID' => $requestID,
68
            'CallBackURL' => $callbackUrl
69
        ]);
70
    }
71
72
}
73