Completed
Push — master ( 92ff78...57630a )
by Steve
20:35 queued 09:38
created

views/default/resources/user/view.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
$user_guid = elgg_extract('guid', $vars);
4
elgg_entity_gatekeeper($user_guid, 'user');
5
$user = get_user($user_guid);
6
7
$title = $user->getDisplayName();
1 ignored issue
show
The method getDisplayName does only exist in ElggEntity, but not in stdClass.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
8
9
$params = [
10
	'content' => elgg_view_entity($user),
11
	'title' => $title,
12
	'sidebar' => false,
13
];
14
$body = elgg_view_layout('default', $params);
15
16
echo elgg_view_page($title, $body);
17