UserStringConverter::convert()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 7
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 10
ccs 0
cts 8
cp 0
crap 30
rs 9.6111
1
<?php
2
3
namespace App\Converter;
4
5
use App\Entity\User;
6
7
class UserStringConverter {
8
    public function convert(User $user): string {
9
        if(empty($user->getLastname()) && empty($user->getFirstname())) {
10
            return $user->getUsername();
11
        } else if(empty($user->getFirstname())) {
12
            return sprintf('%s (%s)', $user->getFirstname(), $user->getUsername());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $user->getFirstname() targeting App\Entity\User::getFirstname() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
13
        } else if(empty($user->getLastname())) {
14
            return sprintf('%s (%s)', $user->getLastname(), $user->getUsername());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $user->getLastname() targeting App\Entity\User::getLastname() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
15
        }
16
17
        return sprintf('%s, %s (%s)', $user->getLastname(), $user->getFirstname(), $user->getUsername());
18
    }
19
}