AttributeMap::renderValue()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 4
nc 3
nop 1
1
<?php
2
3
4
namespace flipbox\saml\core\models;
5
6
use craft\elements\User;
7
use yii\base\Model;
8
9
class AttributeMap extends Model
10
{
11
    /**
12
     * @var string
13
     */
14
    public $craftProperty;
15
    /**
16
     * @var string
17
     */
18
    public $attributeName;
19
    /**
20
     * @var string
21
     */
22
    public $templateOverride;
23
24
    public function renderValue(User $user)
25
    {
26
        $value = null;
0 ignored issues
show
Unused Code introduced by
$value is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
27
        if (! $this->templateOverride && ! $this->craftProperty) {
28
            return '';
29
        }
30
31
        if ($this->templateOverride) {
32
            $value = \Craft::$app->view->renderObjectTemplate(
33
                $this->templateOverride,
34
                $user
35
            );
36
        } else {
37
            $value = $user->{$this->craftProperty};
38
        }
39
40
        return $value;
41
    }
42
}
43