Passed
Push — master ( f13f78...5c1b24 )
by Ismayil
04:22
created

actions/avatar/remove.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
 * Avatar remove action
4
 */
5
6
$user_guid = get_input('guid');
7
$user = get_user($user_guid);
8
9
if (!$user || !$user->canEdit()) {
10
	return elgg_error_response(elgg_echo('avatar:remove:fail'));
11
}
12
13
$user->deleteIcon();
1 ignored issue
show
The method deleteIcon 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...
14
15
return elgg_ok_response('', elgg_echo('avatar:remove:success'));
16