These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Created by PhpStorm. |
||
4 | * User: davis |
||
5 | * Date: 7/30/17 |
||
6 | * Time: 1:27 PM |
||
7 | */ |
||
8 | |||
9 | namespace DavisPeixoto\BlogCore\Entity; |
||
10 | |||
11 | |||
12 | use Ramsey\Uuid\Exception\InvalidUuidStringException; |
||
13 | use Ramsey\Uuid\Uuid; |
||
14 | use Ramsey\Uuid\UuidInterface; |
||
15 | use stdClass; |
||
16 | |||
17 | class AbstractEntity extends stdClass |
||
18 | { |
||
19 | /** |
||
20 | * @var UuidInterface |
||
21 | */ |
||
22 | protected $id; |
||
23 | |||
24 | /** |
||
25 | * @return string |
||
26 | */ |
||
27 | 9 | public function getId(): string |
|
28 | { |
||
29 | 9 | return $this->id->toString(); |
|
30 | } |
||
31 | |||
32 | /** |
||
33 | * @param string|null $id |
||
34 | * @return $this |
||
0 ignored issues
–
show
|
|||
35 | * @throws InvalidUuidStringException |
||
36 | */ |
||
37 | 74 | public function setId(string $id = null) |
|
38 | { |
||
39 | 74 | $uuid = null; |
|
0 ignored issues
–
show
$uuid 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
Loading history...
|
|||
40 | 74 | if ($id === null || $id === '') { |
|
41 | 47 | $uuid = Uuid::uuid4(); |
|
42 | } else { |
||
43 | 61 | if (Uuid::isValid($id)) { |
|
44 | 60 | $uuid = Uuid::fromString($id); |
|
45 | } else { |
||
46 | 1 | throw new InvalidUuidStringException('Invalid string'); |
|
47 | } |
||
48 | } |
||
49 | |||
50 | 73 | if ($uuid->getVersion() !== Uuid::uuid4()->getVersion()) { |
|
51 | 1 | throw new InvalidUuidStringException('Not supported version: '.$uuid->getVersion()); |
|
52 | } |
||
53 | |||
54 | 72 | $this->id = $uuid; |
|
55 | 72 | } |
|
56 | } |
||
57 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.