Completed
Branch BUG-10636-remove-unnecessary-b... (dfa227)
by
unknown
35:02 queued 23:26
created

CreateAttendeeCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 69
Duplicated Lines 91.3 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 63
loc 69
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A attendeeDetails() 4 4 1
A registration() 4 4 1
A getCapCheck() 6 8 4

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 EventEspresso\core\services\commands\attendee;
3
4
use EE_Registration;
5
use EventEspresso\core\domain\services\capabilities\CapCheck;
6
use EventEspresso\core\domain\services\capabilities\CapCheckInterface;
7
use EventEspresso\core\domain\services\capabilities\PublicCapabilities;
8
use EventEspresso\core\exceptions\InvalidDataTypeException;
9
use EventEspresso\core\services\commands\Command;
10
use EventEspresso\core\services\commands\CommandRequiresCapCheckInterface;
11
12
defined('EVENT_ESPRESSO_VERSION') || exit;
13
14
15
16
/**
17
 * Class CreateAttendeeCommand
18
 * DTO for passing data to a CreateAttendeeCommandHandler
19
 *
20
 * @package       Event Espresso
21
 * @author        Brent Christensen
22
 * @since         $VID:$
23
 */
24 View Code Duplication
class CreateAttendeeCommand extends Command implements CommandRequiresCapCheckInterface
25
{
26
27
    /**
28
     * array of details where keys are names of EEM_Attendee model fields
29
     *
30
     * @var array $attendee_details
31
     */
32
    protected $attendee_details;
33
34
    /**
35
     * an existing registration to associate this attendee with
36
     *
37
     * @var EE_Registration $registration
38
     */
39
    protected $registration;
40
41
42
43
    /**
44
     * CreateAttendeeCommand constructor.
45
     *
46
     * @param array            $attendee_details
47
     * @param EE_Registration $registration
48
     */
49
    public function __construct(array $attendee_details, EE_Registration $registration)
50
    {
51
        $this->attendee_details = $attendee_details;
52
        $this->registration = $registration;
53
    }
54
55
56
57
    /**
58
     * @return array
59
     */
60
    public function attendeeDetails()
61
    {
62
        return $this->attendee_details;
63
    }
64
65
66
67
    /**
68
     * @return EE_Registration
69
     */
70
    public function registration()
71
    {
72
        return $this->registration;
73
    }
74
75
76
77
    /**
78
     * @return CapCheckInterface
79
     * @throws InvalidDataTypeException
80
     */
81
    public function getCapCheck()
82
    {
83
        // need cap for non-AJAX admin requests
84
        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
85
            return new CapCheck('ee_edit_contacts', 'create_new_contact');
86
        }
87
        return new PublicCapabilities('', 'create_new_contact');
88
    }
89
90
91
92
}
93
// End of file CreateAttendeeCommand.php
94
// Location: EventEspresso\core\services\commands\attendee/CreateAttendeeCommand.php