8000 feature(phpstan): add phpstan and fixes · sjunior-dev/symfony-api-test@8308b9f · GitHub
[go: up one dir, main page]

Skip to content

Commit 8308b9f

Browse files
committed
feature(phpstan): add phpstan and fixes
1 parent bcafc4a commit 8308b9f

File tree

6 files changed

+37
-6
lines changed

6 files changed

+37
-6
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ composer require nelmio/api-doc-bundle
2828

2929
```
3030

31+
### PHPSTAN
32+
```
33+
phpstan analyse -l 8 src/
34+
35+
12/12 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
36+
37+
38+
[OK] No errors
39+
40+
41+
```
3142
---
3243
### Commands and Run
3344

src/Controller/UserController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function view(): Response
3232
#[Route('/user', name: 'user_update', methods: ['PUT'])]
3333
public function update(Request $request): Response
3434
{
35+
/** @var User $user */
3536
$user = $this->getUser();
3637
$user = $this->userService->store($request, $user);
3738

src/Entity/User.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
2929
private ?int $id = null;
3030

3131
#[ORM\Column(type: 'uuid')]
32-
private ?Uuid $reference;
32+
private Uuid $reference;
3333

3434
#[Assert\NotBlank]
3535
#[Assert\NotNull]
3636
#[ORM\Column(length: 180)]
37-
private ?string $email = null;
37+
private string $email;
3838

3939
/**
4040
* @var list<string> The user roles
@@ -46,7 +46,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
4646
* @var string The hashed password
4747
*/
4848
#[ORM\Column]
49-
private ?string $password = null;
49+
private string $password;
5050

5151
public function __construct()
5252
{
@@ -59,7 +59,7 @@ public function getId(): ?int
5959
return $this->id;
6060
}
6161

62-
public function getEmail(): ?string
62+
public function getEmail(): string
6363
{
6464
return $this->email;
6565
}

src/Error/Normalizer.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
class Normalizer implements NormalizerInterface
99
{
10+
/**
11+
* @param array<string, mixed> $context
12+
* @return array<string, mixed>
13+
*/
1014
public function normalize($exception, string|null $format = null, array $context = []): array
1115
{
1216
return [
@@ -16,13 +20,22 @@ public function normalize($exception, string|null $format = null, array $context
1620
];
1721
}
1822

23+
/**
24+
* @param array<string, mixed> $context
25+
*/
1926
public function supportsNormalization($data, string|null $format = null, array $context = []): bool
2027
{
2128
return $data instanceof FlattenException;
2229
}
2330

31+
/**
32+
*
33+
* @return array<string, mixed>
34+
*/
2435
public function getSupportedTypes(?string $format): array
2536
{
26-
return ['exception'];
37+
return [
38+
\Exception::class => true,
39+
];
2740
}
2841
}

src/Response/UserResponse.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
class UserResponse
88
{
9+
/**
10+
*
11+
* @param array<int, string> $roles
12+
*/
913
public function __construct(
1014
public string $id,
1115
public string $email,

src/Service/UserService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use App\Entity\User;
66
use App\Repository\UserRepository;
77
use App\Response\UserResponse;
8-
use Doctrine\Common\Collections\Collection;
98
use Symfony\Component\HttpFoundation\Request;
109
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
1110
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
@@ -25,6 +24,9 @@ public function remove(User $user): void
2524
$this->userRepository->remove($user);
2625
}
2726

27+
/**
28+
* @return array<int, UserResponse>
29+
*/
2830
public function all(): array
2931
{
3032
$response = [];

0 commit comments

Comments
 (0)
0