Call to EntityManager::clear in loop not detected

Open
#595 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
php
Domain
devtools

Research direction

No source file or test is named. Start by reproducing the reported PHPStan error with the EntityManager::clear() call inside the foreach loop, then compare it with the version where clear() is outside the loop. Done means the valid assertion is no longer reported as always false while the relevant analysis behavior remains covered.

Written by the indexing model from the issue text.

Description

I'm currently in the process of upgrading phpstan an phpstan-doctrine to the current version (phpstan 1.11.6, phpstan-doctrine 1.4.4) and I'm encountering a new error.

We have a test like the following:

public function testCleanup(EntityManager $entityManager): void
{
    if ([] !== $entityManager->getRepository(Favourite::class)->findAll()) {
        self::markTestSkipped('Invalid setup');
    }

    foreach ([1,2,3] as $dummy) {
        // setup ...
        $entityManager->clear();
    }

    self::assertCount(4, $entityManager->getRepository(Favourite::class)->findAll());

    // ...
}

This test reports Call to static method PHPUnit\Framework\Assert::assertCount() with 4 and array{} will always evaluate to false..
When adding a $entityManager->clear(); outside the loop, no error is reported.

Dominant language
PHP
Stars
678
Forks
122
Avg merge
5d 18h
Merged PRs (30d)
3

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from phpstan/phpstan-doctrine

All issues in phpstan/phpstan-doctrine

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.