Completed
Branch BETA-4.9-message-activity (793322)
by
unknown
18:25 queued 10s
created

Registration   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 8
c 2
b 0
f 1
lcom 0
cbo 5
dl 0
loc 54
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C datetime_checkin_stati() 0 42 8
1
<?php
2
namespace EventEspresso\core\libraries\rest_api\calculations;
3
4
use EventEspresso\core\libraries\rest_api\calculations\Base as Calculations_Base;
5
use EventEspresso\core\libraries\rest_api\controllers\model\Base;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, EventEspresso\core\libra...t_api\calculations\Base.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
/**
7
 *
8
 * Class Registration
9
 *
10
 * 
11
 *
12
 * @package         Registration Espresso
13
 * @subpackage
14
 * @author				Mike Nelson
15
 * @since		 	   $VID:$
16
 *
17
 */
18
if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
19
	exit( 'No direct script access allowed' );
20
}
21
22
class Registration extends Calculations_Base {
23
24
	/**
25
	 * Calculates the checkin status for each datetime this registration has access to
26
	 *
27
	 * @param array            $wpdb_row
28
	 * @param \WP_REST_Request $request
29
	 * @param Base             $controller
30
	 * @return int
31
	 * @throws \EE_Error
32
	 */
33
	public static function datetime_checkin_stati( $wpdb_row, $request, $controller ){
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $controller is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
		if( is_array( $wpdb_row ) && isset( $wpdb_row[ 'Registration.REG_ID' ] ) ) {
35
			$reg = \EEM_Registration::instance()->get_one_by_ID( $wpdb_row[ 'Registration.REG_ID' ] );
36
		} else {
37
			$reg = null;
38
		}
39
		if( ! $reg instanceof \EE_Registration 
40
		) {
41
			throw new \EE_Error(
42
				sprintf(
43
					__( 'Cannot calculate datetime_checkin_stati because the registration with ID %1$s (from database row %2$s) was not found', 'event_espresso' ),
44
					$wpdb_row[ 'Registration.REG_ID' ],
45
					print_r( $wpdb_row, true )
46
				)
47
			);
48
		}
49
		$datetime_ids = \EEM_Datetime::instance()->get_col(
50
			array(
51
				array(
52
					'Ticket.TKT_ID' => $reg->ticket_ID()
53
				)
54
			)
55
		);
56
		$checkin_stati = array();
57
		foreach( $datetime_ids as $datetime_id ) {
58
			$status = $reg->check_in_status_for_datetime( $datetime_id );
59
			switch( $status ) {
60
				case \EE_Registration::checkin_status_out:
61
					$status_pretty = 'OUT';
62
					break;
63
				case \EE_Registration::checkin_status_in:
64
					$status_pretty = 'IN';
65
					break;
66
				case \EE_Registration::checkin_status_never:
67
				default:
68
					$status_pretty = 'NEVER';
69
					break;
70
			}
71
			$checkin_stati[ $datetime_id ] = $status_pretty;
72
		}
73
		return $checkin_stati;
74
	}
75
}
76