Skip to content

Commit b0526f4

Browse files
committed
feature #1391 Add Symfony and Doctrine PHPStan extensions (ker0x)
This PR was squashed before being merged into the main branch. Discussion ---------- Add Symfony and Doctrine PHPStan extensions Fix #1379 Commits ------- 0712760 Add Symfony and Doctrine PHPStan extensions
2 parents 852aaf5 + 0712760 commit b0526f4

File tree

8 files changed

+278
-10
lines changed

8 files changed

+278
-10
lines changed

composer.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@
4949
"require-dev": {
5050
"dama/doctrine-test-bundle": "^7.0",
5151
"doctrine/doctrine-fixtures-bundle": "^3.4",
52+
"phpstan/extension-installer": "^1.2",
5253
"phpstan/phpstan": "^1.2",
54+
"phpstan/phpstan-doctrine": "^1.3",
55+
"phpstan/phpstan-symfony": "^1.2",
5356
"symfony/browser-kit": "^6.2",
5457
"symfony/css-selector": "^6.2",
5558
"symfony/debug-bundle": "^6.2",
@@ -61,7 +64,8 @@
6164
"config": {
6265
"allow-plugins": {
6366
"symfony/flex": true,
64-
"symfony/runtime": true
67+
"symfony/runtime": true,
68+
"phpstan/extension-installer": true
6569
},
6670
"platform": {
6771
"php": "8.1.0"

composer.lock

+185-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/services.yaml

-6
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,3 @@ services:
3434
$sender: '%app.notifications.email_sender%'
3535

3636
Symfony\Component\Security\Http\Logout\LogoutUrlGenerator: '@security.logout_url_generator'
37-
38-
when@test:
39-
services:
40-
test.user_password_hasher:
41-
alias: 'security.user_password_hasher'
42-
public: true

phpstan-baseline.neon

+60
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,65 @@
11
parameters:
22
ignoreErrors:
3+
-
4+
message: "#^Property App\\\\Entity\\\\Comment\\:\\:\\$author type mapping mismatch\\: property can contain App\\\\Entity\\\\User\\|null but database expects App\\\\Entity\\\\User\\.$#"
5+
count: 1
6+
path: src/Entity/Comment.php
7+
8+
-
9+
message: "#^Property App\\\\Entity\\\\Comment\\:\\:\\$content type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
10+
count: 1
11+
path: src/Entity/Comment.php
12+
13+
-
14+
message: "#^Property App\\\\Entity\\\\Comment\\:\\:\\$post type mapping mismatch\\: property can contain App\\\\Entity\\\\Post\\|null but database expects App\\\\Entity\\\\Post\\.$#"
15+
count: 1
16+
path: src/Entity/Comment.php
17+
18+
-
19+
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$author type mapping mismatch\\: property can contain App\\\\Entity\\\\User\\|null but database expects App\\\\Entity\\\\User\\.$#"
20+
count: 1
21+
path: src/Entity/Post.php
22+
23+
-
24+
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$content type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
25+
count: 1
26+
path: src/Entity/Post.php
27+
28+
-
29+
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$slug type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
30+
count: 1
31+
path: src/Entity/Post.php
32+
33+
-
34+
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$summary type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
35+
count: 1
36+
path: src/Entity/Post.php
37+
38+
-
39+
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$title type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
40+
count: 1
41+
path: src/Entity/Post.php
42+
43+
-
44+
message: "#^Property App\\\\Entity\\\\User\\:\\:\\$email type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
45+
count: 1
46+
path: src/Entity/User.php
47+
48+
-
49+
message: "#^Property App\\\\Entity\\\\User\\:\\:\\$fullName type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
50+
count: 1
51+
path: src/Entity/User.php
52+
53+
-
54+
message: "#^Property App\\\\Entity\\\\User\\:\\:\\$password type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
55+
count: 1
56+
path: src/Entity/User.php
57+
58+
-
59+
message: "#^Property App\\\\Entity\\\\User\\:\\:\\$username type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
60+
count: 1
61+
path: src/Entity/User.php
62+
363
-
464
message: "#^Parameter \\#1 \\$function of class ReflectionFunction constructor expects Closure\\|string, callable\\(\\)\\: mixed given\\.$#"
565
count: 1

phpstan.neon.dist

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ parameters:
88
- tests
99
bootstrapFiles:
1010
- vendor/bin/.phpunit/phpunit/vendor/autoload.php
11+
doctrine:
12+
objectManagerLoader: tests/object-manager.php
13+
symfony:
14+
containerXmlPath: var/cache/dev/App_KernelDevDebugContainer.xml

src/Controller/BlogController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function commentForm(Post $post): Response
156156
public function search(Request $request, PostRepository $posts): Response
157157
{
158158
$query = (string) $request->query->get('q', '');
159-
$limit = (int) $request->query->get('l', 10);
159+
$limit = $request->query->getInt('l', 10);
160160

161161
if (!$request->isXmlHttpRequest()) {
162162
return $this->render('blog/search.html.twig', ['query' => $query]);

tests/Command/AddUserCommandTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private function assertUserCreated(bool $isAdmin): void
9292
$repository = $this->getContainer()->get(UserRepository::class);
9393

9494
/** @var UserPasswordHasherInterface $passwordHasher */
95-
$passwordHasher = $this->getContainer()->get('test.user_password_hasher');
95+
$passwordHasher = $this->getContainer()->get(UserPasswordHasherInterface::class);
9696

9797
$user = $repository->findOneByEmail($this->userData['email']);
9898

tests/object-manager.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use App\Kernel;
13+
use Symfony\Component\Dotenv\Dotenv;
14+
15+
require dirname(__DIR__).'/vendor/autoload.php';
16+
17+
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
18+
19+
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
20+
$kernel->boot();
21+
22+
return $kernel->getContainer()->get('doctrine')->getManager();

0 commit comments

Comments
 (0)