Completed
Branch BUG/unit-tests-account-for-inc... (a3bc47)
by
unknown
28:13 queued 14:26
created

Attendee   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A userAvatar() 0 11 5
1
<?php
2
3
namespace EventEspresso\core\libraries\rest_api\calculations;
4
5
use EE_Attendee;
6
use EE_Error;
7
use EEM_Attendee;
8
use EventEspresso\core\exceptions\InvalidDataTypeException;
9
use EventEspresso\core\exceptions\InvalidInterfaceException;
10
use EventEspresso\core\libraries\rest_api\calculations\Base as Calculations_Base;
11
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...
12
use InvalidArgumentException;
13
use WP_REST_Request;
14
15
/**
16
 * Class Attendee
17
 * adds calculated fields to the  REST API output for the /attendees/ endpoint
18
 *
19
 * @package EventEspresso\core\libraries\rest_api\calculations
20
 * @author  Brent Christensen
21
 * @since   $VID:$
22
 */
23
class Attendee extends Calculations_Base
24
{
25
26
    /**
27
     * @param array           $wpdb_row
28
     * @param WP_REST_Request $request
29
     * @param Base            $controller
30
     * @since $VID:$
31
     * @return string
32
     */
33
    public static function userAvatar(array $wpdb_row, WP_REST_Request $request, Base $controller)
34
    {
35
        if (is_array($wpdb_row) && isset($wpdb_row['Attendee_Meta.ATT_email'])) {
36
            $email_address = $wpdb_row['Attendee_Meta.ATT_email'];
37
        }
38
        if (empty($email_address)) {
39
            return '';
40
        }
41
        $avatar = get_avatar_url($email_address);
42
        return $avatar ? $avatar : '';
43
    }
44
}
45