Skip to content

Commit

Permalink
[DX] Add error message information for include full path to load inte…
Browse files Browse the repository at this point in the history
…rnal phpstan bleedingEdge.neon config (#5635)

* [DX] Add error message information for include internal phpstan bleedingEdge.neon config

* [ci-review] Rector Rectify

* fix phpstan

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Feb 18, 2024
1 parent 914349c commit a3d2375
Showing 1 changed file with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\NodeTypeResolver\DependencyInjection;

use Throwable;
use PhpParser\Lexer;
use PHPStan\Analyser\NodeScopeResolver;
use PHPStan\Analyser\ScopeFactory;
Expand All @@ -16,6 +17,9 @@
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Style\SymfonyStyle;
use Webmozart\Assert\Assert;

/**
Expand All @@ -27,16 +31,41 @@
{
private Container $container;

/**
* @var string
*/
private const INVALID_BLEEDING_EDGE_PATH_MESSAGE = <<<MESSAGE_ERROR
'%s, use full path bleedingEdge.neon config, eg:
includes:
- phar://vendor/phpstan/phpstan/phpstan.phar/conf/bleedingEdge.neon
in your included phpstan configuration.
MESSAGE_ERROR;

public function __construct()
{
$containerFactory = new ContainerFactory(getcwd());
$additionalConfigFiles = $this->resolveAdditionalConfigFiles();

$this->container = $containerFactory->create(
SimpleParameterProvider::provideStringParameter(Option::CONTAINER_CACHE_DIRECTORY),
$additionalConfigFiles,
[]
);
try {
$this->container = $containerFactory->create(
SimpleParameterProvider::provideStringParameter(Option::CONTAINER_CACHE_DIRECTORY),
$additionalConfigFiles,
[]
);
} catch (Throwable $throwable) {
if ($throwable->getMessage() === "File 'phar://phpstan.phar/conf/bleedingEdge.neon' is missing or is not readable.") {

$symfonyStyle = new SymfonyStyle(new ArrayInput([]), new ConsoleOutput());
$symfonyStyle->error(sprintf(self::INVALID_BLEEDING_EDGE_PATH_MESSAGE, $throwable->getMessage()));

exit(-1);
}

throw $throwable;
}
}

/**
Expand Down

0 comments on commit a3d2375

Please sign in to comment.