Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise PHPStan level to 8 #1409

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 7
level: 8
paths:
- src
- tests
Expand Down
8 changes: 4 additions & 4 deletions src/DependencyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
{
if ($this->configuration === null) {
$this->configuration = $this->configurationLoader->getConfiguration();
$this->freeze();
$this->frozen = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these changes where the frozen() method gets replaced with the direct set to true?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPStan treats the method calls as impure and complains that $this->configuration might be null when we return it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was playing around with annotations and other configurations, but it seems like PHPStan can't be convinced that $this->freeze() does nothing evil with other property states.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and this is fine imho. freeze() is impure, so PHPStan's behavior is correct.

}

return $this->configuration;
Expand All @@ -157,7 +157,7 @@
$this->connection = $this->hasEntityManager()
? $this->getEntityManager()->getConnection()
: $this->connectionLoader->getConnection($this->getConfiguration()->getConnectionName());
$this->freeze();
$this->frozen = true;
}

return $this->connection;
Expand All @@ -171,7 +171,7 @@
}

$this->em = $this->emLoader->getEntityManager($this->getConfiguration()->getEntityManagerName());
$this->freeze();
$this->frozen = true;
}

return $this->em;
Expand Down Expand Up @@ -222,7 +222,7 @@

private function getEmptySchemaProvider(): SchemaProvider
{
return $this->getDependency(EmptySchemaProvider::class, fn (): SchemaProvider => new EmptySchemaProvider($this->connection->createSchemaManager()));
return $this->getDependency(EmptySchemaProvider::class, fn (): SchemaProvider => new EmptySchemaProvider($this->getConnection()->createSchemaManager()));

Check warning on line 225 in src/DependencyFactory.php

View check run for this annotation

Codecov / codecov/patch

src/DependencyFactory.php#L225

Added line #L225 was not covered by tests
}

public function hasSchemaProvider(): bool
Expand Down
8 changes: 5 additions & 3 deletions src/Tools/Console/Command/DoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,17 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
$configurationLoader = new ConfigurationFileWithFallback($configurationParameter);
$this->dependencyFactory->setConfigurationLoader($configurationLoader);
}
$dependencyFactory = $this->dependencyFactory;

$this->setNamedEmOrConnection($input);

if ($this->dependencyFactory->isFrozen()) {
if ($dependencyFactory->isFrozen()) {
return;
}

$logger = new ConsoleLogger($output);
$this->dependencyFactory->setService(LoggerInterface::class, $logger);
$this->dependencyFactory->freeze();
$dependencyFactory->setService(LoggerInterface::class, $logger);
$dependencyFactory->freeze();
}

protected function getDependencyFactory(): DependencyFactory
Expand All @@ -116,6 +117,7 @@ protected function canExecute(string $question, InputInterface $input): bool

private function setNamedEmOrConnection(InputInterface $input): void
{
assert($this->dependencyFactory !== null);
$emName = $input->getOption('em');
$connName = $input->getOption('conn');
if ($emName !== null && $connName !== null) {
Expand Down
Loading