Skip to content

Commit

Permalink
feature #1391 Add Symfony and Doctrine PHPStan extensions (ker0x)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
javiereguiluz committed Jan 13, 2023
2 parents 852aaf5 + 0712760 commit b0526f4
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 10 deletions.
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@
"require-dev": {
"dama/doctrine-test-bundle": "^7.0",
"doctrine/doctrine-fixtures-bundle": "^3.4",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^1.2",
"phpstan/phpstan-doctrine": "^1.3",
"phpstan/phpstan-symfony": "^1.2",
"symfony/browser-kit": "^6.2",
"symfony/css-selector": "^6.2",
"symfony/debug-bundle": "^6.2",
Expand All @@ -61,7 +64,8 @@
"config": {
"allow-plugins": {
"symfony/flex": true,
"symfony/runtime": true
"symfony/runtime": true,
"phpstan/extension-installer": true
},
"platform": {
"php": "8.1.0"
Expand Down
186 changes: 185 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,3 @@ services:
$sender: '%app.notifications.email_sender%'

Symfony\Component\Security\Http\Logout\LogoutUrlGenerator: '@security.logout_url_generator'

when@test:
services:
test.user_password_hasher:
alias: 'security.user_password_hasher'
public: true
60 changes: 60 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,65 @@
parameters:
ignoreErrors:
-
message: "#^Property App\\\\Entity\\\\Comment\\:\\:\\$author type mapping mismatch\\: property can contain App\\\\Entity\\\\User\\|null but database expects App\\\\Entity\\\\User\\.$#"
count: 1
path: src/Entity/Comment.php

-
message: "#^Property App\\\\Entity\\\\Comment\\:\\:\\$content type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/Comment.php

-
message: "#^Property App\\\\Entity\\\\Comment\\:\\:\\$post type mapping mismatch\\: property can contain App\\\\Entity\\\\Post\\|null but database expects App\\\\Entity\\\\Post\\.$#"
count: 1
path: src/Entity/Comment.php

-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$author type mapping mismatch\\: property can contain App\\\\Entity\\\\User\\|null but database expects App\\\\Entity\\\\User\\.$#"
count: 1
path: src/Entity/Post.php

-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$content type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/Post.php

-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$slug type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/Post.php

-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$summary type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/Post.php

-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$title type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/Post.php

-
message: "#^Property App\\\\Entity\\\\User\\:\\:\\$email type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/User.php

-
message: "#^Property App\\\\Entity\\\\User\\:\\:\\$fullName type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/User.php

-
message: "#^Property App\\\\Entity\\\\User\\:\\:\\$password type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/User.php

-
message: "#^Property App\\\\Entity\\\\User\\:\\:\\$username type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/User.php

-
message: "#^Parameter \\#1 \\$function of class ReflectionFunction constructor expects Closure\\|string, callable\\(\\)\\: mixed given\\.$#"
count: 1
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ parameters:
- tests
bootstrapFiles:
- vendor/bin/.phpunit/phpunit/vendor/autoload.php
doctrine:
objectManagerLoader: tests/object-manager.php
symfony:
containerXmlPath: var/cache/dev/App_KernelDevDebugContainer.xml
2 changes: 1 addition & 1 deletion src/Controller/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function commentForm(Post $post): Response
public function search(Request $request, PostRepository $posts): Response
{
$query = (string) $request->query->get('q', '');
$limit = (int) $request->query->get('l', 10);
$limit = $request->query->getInt('l', 10);

if (!$request->isXmlHttpRequest()) {
return $this->render('blog/search.html.twig', ['query' => $query]);
Expand Down
2 changes: 1 addition & 1 deletion tests/Command/AddUserCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private function assertUserCreated(bool $isAdmin): void
$repository = $this->getContainer()->get(UserRepository::class);

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

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

Expand Down
22 changes: 22 additions & 0 deletions tests/object-manager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use App\Kernel;
use Symfony\Component\Dotenv\Dotenv;

require dirname(__DIR__).'/vendor/autoload.php';

(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$kernel->boot();

return $kernel->getContainer()->get('doctrine')->getManager();

0 comments on commit b0526f4

Please sign in to comment.