Completed
Branch BUG-9464-payment-methods-myste... (4799f5)
by
unknown
351:53 queued 337:20
created

Base   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 0
cbo 1
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A _verify_current_user_can() 0 13 2
A get_resource_name() 0 4 1
1
<?php
2
namespace EventEspresso\core\libraries\rest_api\calculations;
3
4
use EventEspresso\core\libraries\rest_api\Rest_Exception;
5
/**
6
 *
7
 * Class Base
8
 *
9
 * Description here
10
 *
11
 * @package         Event Espresso
12
 * @subpackage
13
 * @author				Mike Nelson
14
 * @since		 	   $VID:$
15
 *
16
 */
17
if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
18
	exit( 'No direct script access allowed' );
19
}
20
21
class Base {
22
23
	/**
24
	 * @param $required_permission
25
	 * @param $attempted_calculation
26
	 * @throws \EventEspresso\core\libraries\rest_api\Rest_Exception
27
	 */
28
	protected static function _verify_current_user_can( $required_permission, $attempted_calculation ) {
29
		if( ! current_user_can( $required_permission ) ) {
30
			throw new Rest_Exception(
31
				'permission_denied',
32
				sprintf(
33
					__( 'Permission denied, you cannot calculate %1$s on %2$s because you do not have the capability "%3$s"', 'event_espresso' ),
34
					$attempted_calculation,
35
					\EEH_Inflector::pluralize_and_lower( self::get_resource_name() ),
36
					$required_permission
37
				)
38
			);
39
		}
40
	}
41
42
	/**
43
	 * Gets the name of the resource of the called class
44
	 * @return string
45
	 */
46
	public static function get_resource_name() {
47
		$classname = get_called_class();
48
		return substr( $classname, strrpos( $classname, '\\' ) + 1 );
49
	}
50
}
51