Completed
Branch BUG-10738-inconsistency-in-ses... (860590)
by
unknown
57:39 queued 45:30
created

CreateTransactionCommand::getCapCheck()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
eloc 4
nc 2
nop 0
dl 10
loc 10
rs 9.2
c 0
b 0
f 0
1
<?php
2
namespace EventEspresso\core\services\commands\transaction;
3
4
use EE_Checkout;
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 CreateTransactionCommand
18
 * DTO for passing data to a CreateTransactionCommandHandler
19
 *
20
 * @package       Event Espresso
21
 * @author        Brent Christensen
22
 * @since         $VID:$
23
 */
24 View Code Duplication
class CreateTransactionCommand extends Command implements CommandRequiresCapCheckInterface
25
{
26
27
    /**
28
     * @var EE_Checkout $checkout
29
     */
30
    protected $checkout;
31
32
    /**
33
     * @var array $transaction_details
34
     */
35
    protected $transaction_details;
36
37
38
39
    /**
40
     * CreateTransactionCommand constructor.
41
     *
42
     * @param EE_Checkout $checkout
43
     * @param array       $transaction_details
44
     */
45
    public function __construct(EE_Checkout $checkout = null, array $transaction_details = array())
46
    {
47
        $this->checkout = $checkout;
48
        $this->transaction_details = $transaction_details;
49
    }
50
51
52
53
    /**
54
     * @return CapCheckInterface
55
     * @throws InvalidDataTypeException
56
     */
57
    public function getCapCheck()
58
    {
59
        // need cap for non-AJAX admin requests
60
        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
61
            // there's no specific caps for editing/creating transactions,
62
            // so that's why we are using ee_edit_registrations
63
            return new CapCheck('ee_edit_registrations', 'create_new_transaction');
64
        }
65
        return new PublicCapabilities('', 'create_new_transaction');
66
    }
67
68
69
70
    /**
71
     * @return EE_Checkout
72
     */
73
    public function checkout()
74
    {
75
        return $this->checkout;
76
    }
77
78
79
80
    /**
81
     * @return array
82
     */
83
    public function transactionDetails()
84
    {
85
        return $this->transaction_details;
86
    }
87
88
89
90
}
91
// End of file CreateTransactionCommand.php
92
// Location: EventEspresso\core\services\commands\transaction/CreateTransactionCommand.php