RegistrationCertain   A
last analyzed

Complexity

Total Complexity 21

Size/Duplication

Total Lines 112
Duplicated Lines 32.14 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 21
lcom 1
cbo 1
dl 36
loc 112
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getRessourceName() 0 3 1
A getMandatoryFields() 0 4 1
A getRegistrations() 9 9 2
A getRegistrationsByEventCode() 9 9 2
B hasRegistrationsByEventCodeAndEmail() 0 25 11
A getRegistrationByEventCodeAnRegCode() 9 9 2
A updateRegistrationByEventCodeAnRegCode() 9 9 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
namespace Wabel\CertainAPI\Ressources;
3
4
use Wabel\CertainAPI\Interfaces\CertainRessourceInterface;
5
use Wabel\CertainAPI\CertainRessourceAbstract;
6
7
/**
8
 * RegistrationCertain about the Registration entity
9
 *
10
 * @author rbergina
11
 */
12
class RegistrationCertain extends CertainRessourceAbstract implements CertainRessourceInterface
13
{
14
    public function getRessourceName(){
15
        return 'Registration';
16
    }
17
    public function getMandatoryFields()
18
    {
19
        return array('profile');
20
    }
21
22
    /**
23
     * Return with all the result from certain.
24
     * @return RegistrationCertain[]
25
     */
26 View Code Duplication
    public function getRegistrations($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...
27
    {
28
        $request=  $this->get(null,$params);
29
        if($request->isSuccessFul()){
30
            $registrationCertainResults = $request->getResults();
31
            return $registrationCertainResults->registrations;
32
        }
33
        return null;
34
    }
35
    
36
    /**
37
     * Return with all the result from certain.
38
     * @return RegistrationCertain[]
39
     */
40 View Code Duplication
    public function getRegistrationsByEventCode($eventCode,$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...
41
    {
42
        $request=  $this->get($eventCode,$params);
43
        if($request->isSuccessFul()){
44
            $registrationCertainResults = $request->getResults();
45
            return $registrationCertainResults->registrations;
46
        }
47
        return null;
48
    }
49
50
    /**
51
     * Return with all the result from certain.
52
     * @param string $eventCode eventCode
53
     * @param string $email email
54
     * @param boolean $returnRegCode To say if we want return a boolean or the regCode
55
     * @param string $orderBySecure in order to get the first registration when we have duplciates
56
     * @return registrationCode|null|boolean|[registrationCode=> "",attendeeTypeCode=>""]
0 ignored issues
show
Documentation introduced by
The doc-type registrationCode=>">registrationCode|null|boolean|[registrationCode=> could not be parsed: Unknown type name "[" at position 30. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
57
     */
58
    public function hasRegistrationsByEventCodeAndEmail($eventCode,$email,$returnRegCode= true,$withAttenteeType=true,$orderBySecure='dateModified_asc')
59
    {
60
        $request=  $this->get($eventCode,[
61
            'email'=> $email,
62
            'orderBy'=> $orderBySecure
63
64
        ]);
65
        if($request->isSuccessFul()){
66
            $registrationCertainResults = $request->getResults();
67
            if($registrationCertainResults->size > 0 && $returnRegCode && $withAttenteeType){
68
                return [
69
                        'registrationCode' => $registrationCertainResults->registrations[0]->registrationCode,
70
                        'attendeeTypeCode' => (isset($registrationCertainResults->registrations[0]->attendeeTypeCode))?$registrationCertainResults->registrations[0]->attendeeTypeCode:'',
71
                    ];
72
            }
73
            elseif($registrationCertainResults->size > 0 && $returnRegCode){
74
                    return $registrationCertainResults->registrations[0]->registrationCode;
75
            } elseif($registrationCertainResults->size > 0  && !$returnRegCode){
76
                return true;
77
            }
78
        } elseif($request->isNotFound()){
79
            return false;
80
        }
81
        return null;
82
    }
83
84
    /**
85
     * Return with the result from certain.
86
     * @param string $eventCode
87
     * @param string $regCode
88
     * @return RegistrationObj
89
     */
90 View Code Duplication
    public function getRegistrationByEventCodeAnRegCode($eventCode,$regCode)
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...
91
    {
92
        $request=  $this->get($eventCode.'/'.$regCode);
93
        if($request->isSuccessFul()){
94
            $registrationCertainResult= $request->getResults();
95
            return $registrationCertainResult;
96
        }
97
        return null;
98
    }
99
100
    /**
101
     * Update with the result from certain.
102
     * @param string $eventCode
103
     * @param string $regCode
104
     * @return RegistrationObj
105
     */
106 View Code Duplication
    public function updateRegistrationByEventCodeAnRegCode($eventCode,$regCode,$data=[])
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...
107
    {
108
        $request=  $this->post($data,[],$eventCode.'/'.$regCode);
109
        if($request->isSuccessFul()){
110
            $registrationCertainResult= $request->getResults();
111
            return $registrationCertainResult;
112
        }
113
        return null;
114
    }
115
116
//    public function substituateRegistration($eventCode,$regCode,$profilePin){
117
//        return $this->updateRegistrationByEventCodeAnRegCode($eventCode, $regCode, [
118
//            'profile' => [
119
//                'pin'=> $profilePin
120
//            ]
121
//        ]);
122
//    }
123
}