diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e69de29bb..ee81541e3 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -0,0 +1,6 @@ +parameters: + ignoreErrors: + - + message: "#^Parameter \\#1 \\$function of class ReflectionFunction constructor expects Closure\\|string, callable\\(\\)\\: mixed given\\.$#" + count: 1 + path: src/Twig/SourceCodeExtension.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index b9fc14d8a..e60011a08 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,3 +1,6 @@ +includes: + - phpstan-baseline.neon + parameters: level: max paths: diff --git a/src/Command/ListUsersCommand.php b/src/Command/ListUsersCommand.php index 908937a97..68af9f036 100644 --- a/src/Command/ListUsersCommand.php +++ b/src/Command/ListUsersCommand.php @@ -105,7 +105,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int }; // Doctrine query returns an array of objects, and we need an array of plain arrays - /** @var callable $createUserArray */ $usersAsPlainArrays = array_map($createUserArray, $allUsers); // In your console commands you should always use the regular output type, @@ -124,7 +123,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $usersAsATable = $bufferedOutput->fetch(); $output->write($usersAsATable); - /** @var string $email */ + /** @var string|null $email */ $email = $input->getOption('send-to'); if (null !== $email) { diff --git a/src/Controller/BlogController.php b/src/Controller/BlogController.php index 8b8c8979d..de0c028f9 100644 --- a/src/Controller/BlogController.php +++ b/src/Controller/BlogController.php @@ -13,7 +13,6 @@ use App\Entity\Comment; use App\Entity\Post; -use App\Entity\Tag; use App\Entity\User; use App\Event\CommentCreatedEvent; use App\Form\CommentType; @@ -53,7 +52,6 @@ public function index(Request $request, int $page, string $_format, PostReposito { $tag = null; if ($request->query->has('tag')) { - /** @var Tag $tag */ $tag = $tags->findOneBy(['name' => $request->query->get('tag')]); } $latestPosts = $posts->findLatest($page, $tag); diff --git a/src/DataFixtures/AppFixtures.php b/src/DataFixtures/AppFixtures.php index 5001a1695..45db2fe35 100644 --- a/src/DataFixtures/AppFixtures.php +++ b/src/DataFixtures/AppFixtures.php @@ -68,8 +68,6 @@ private function loadTags(ObjectManager $manager): void private function loadPosts(ObjectManager $manager): void { - /** @var User $author */ - /** @var array $tags */ foreach ($this->getPostData() as [$title, $slug, $summary, $content, $publishedAt, $author, $tags]) { $post = new Post(); $post->setTitle($title); @@ -132,13 +130,17 @@ private function getTagData(): array /** * @throws \Exception * - * @return array}> + * @return array}> */ private function getPostData(): array { $posts = []; foreach ($this->getPhrases() as $i => $title) { // $postData = [$title, $slug, $summary, $content, $publishedAt, $author, $tags, $comments]; + + /** @var User $user */ + $user = $this->getReference(['jane_admin', 'tom_admin'][0 === $i ? 0 : random_int(0, 1)]); + $posts[] = [ $title, $this->slugger->slug($title)->lower(), @@ -146,7 +148,7 @@ private function getPostData(): array $this->getPostContent(), new \DateTime('now - '.$i.'days'), // Ensure that the first post is written by Jane Doe to simplify tests - $this->getReference(['jane_admin', 'tom_admin'][0 === $i ? 0 : random_int(0, 1)]), + $user, $this->getRandomTags(), ]; } @@ -249,7 +251,7 @@ private function getPostContent(): string /** * @throws \Exception * - * @return array + * @return array */ private function getRandomTags(): array { @@ -257,6 +259,11 @@ private function getRandomTags(): array shuffle($tagNames); $selectedTags = \array_slice($tagNames, 0, random_int(2, 4)); - return array_map(function ($tagName) { return $this->getReference('tag-'.$tagName); }, $selectedTags); + return array_map(function ($tagName) { + /** @var Tag $tag */ + $tag = $this->getReference('tag-'.$tagName); + + return $tag; + }, $selectedTags); } } diff --git a/src/Form/DataTransformer/TagArrayToStringTransformer.php b/src/Form/DataTransformer/TagArrayToStringTransformer.php index 14f0a5081..6b9cd0b5d 100644 --- a/src/Form/DataTransformer/TagArrayToStringTransformer.php +++ b/src/Form/DataTransformer/TagArrayToStringTransformer.php @@ -36,8 +36,6 @@ public function __construct( /** * {@inheritdoc} - * - * @phpstan-param array|null $tags */ public function transform($tags): string { diff --git a/src/Security/PostVoter.php b/src/Security/PostVoter.php index 939f2bd81..ad48bd0b5 100644 --- a/src/Security/PostVoter.php +++ b/src/Security/PostVoter.php @@ -35,7 +35,7 @@ class PostVoter extends Voter /** * {@inheritdoc} * - * @phpstan-param Post $subject + * @phpstan-param object $subject */ protected function supports(string $attribute, $subject): bool { diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index b778324b8..993a80f48 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -30,7 +30,7 @@ class AppExtension extends AbstractExtension private array $localeCodes; /** - * @var array>|null + * @var list|null */ private ?array $locales = null; diff --git a/src/Twig/SourceCodeExtension.php b/src/Twig/SourceCodeExtension.php index e7349fbf4..67ea1181e 100644 --- a/src/Twig/SourceCodeExtension.php +++ b/src/Twig/SourceCodeExtension.php @@ -117,7 +117,6 @@ private function getCallableReflector(callable $callable): \ReflectionFunctionAb return $r->getMethod('__invoke'); } - // @phpstan-ignore-next-line return new \ReflectionFunction($callable); } diff --git a/tests/Command/AddUserCommandTest.php b/tests/Command/AddUserCommandTest.php index 008d1ea1c..3d5fe160e 100644 --- a/tests/Command/AddUserCommandTest.php +++ b/tests/Command/AddUserCommandTest.php @@ -91,12 +91,11 @@ private function assertUserCreated(bool $isAdmin): void /** @var UserRepository $repository */ $repository = $this->getContainer()->get(UserRepository::class); - /** @var \App\Entity\User $user */ - $user = $repository->findOneByEmail($this->userData['email']); - /** @var UserPasswordHasherInterface $passwordHasher */ $passwordHasher = $this->getContainer()->get('test.user_password_hasher'); + $user = $repository->findOneByEmail($this->userData['email']); + $this->assertNotNull($user); $this->assertSame($this->userData['full-name'], $user->getFullName()); $this->assertSame($this->userData['username'], $user->getUsername());