Commit d6c4b74d authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

Issue #3306263 by bbrala: Phpstan should have a memory limit

parent 2f26241c
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -80,12 +80,13 @@ class UpgradeStatusCommands extends DrushCommands {
   * @option ignore-uninstalled Ignore uninstalled projects.
   * @option ignore-contrib Ignore contributed projects.
   * @option ignore-custom Ignore custom projects.
   * @option phpstan-memory-limit Set memory limit for PHPStan.
   * @aliases us-cs
   *
   * @throws \InvalidArgumentException
   *   Thrown when one of the passed arguments is invalid or no arguments were provided.
   */
  public function checkstyle(array $projects, array $options = ['all' => FALSE, 'skip-existing' => FALSE, 'ignore-uninstalled' => FALSE, 'ignore-contrib' => FALSE, 'ignore-custom' => FALSE]) {
  public function checkstyle(array $projects, array $options = ['all' => FALSE, 'skip-existing' => FALSE, 'ignore-uninstalled' => FALSE, 'ignore-contrib' => FALSE, 'ignore-custom' => FALSE, 'phpstan-memory-limit' => '1500M']) {
    $extensions = $this->doAnalyze($projects, $options);
    $xml = new \SimpleXMLElement("<?xml version='1.0'?><checkstyle/>");

@@ -136,12 +137,13 @@ class UpgradeStatusCommands extends DrushCommands {
   * @option ignore-uninstalled Ignore uninstalled projects.
   * @option ignore-contrib Ignore contributed projects.
   * @option ignore-custom Ignore custom projects.
   * @option phpstan-memory-limit Set memory limit for PHPStan.
   * @aliases us-a
   *
   * @throws \InvalidArgumentException
   *   Thrown when one of the passed arguments is invalid or no arguments were provided.
   */
  public function analyze(array $projects, array $options = ['all' => FALSE, 'skip-existing' => FALSE, 'ignore-uninstalled' => FALSE, 'ignore-contrib' => FALSE, 'ignore-custom' => FALSE]) {
  public function analyze(array $projects, array $options = ['all' => FALSE, 'skip-existing' => FALSE, 'ignore-uninstalled' => FALSE, 'ignore-contrib' => FALSE, 'ignore-custom' => FALSE, 'phpstan-memory-limit' => '1500M']) {
    $extensions = $this->doAnalyze($projects, $options);

    foreach ($extensions as $type => $list) {
@@ -177,11 +179,12 @@ class UpgradeStatusCommands extends DrushCommands {
   * @option ignore-uninstalled Ignore uninstalled projects.
   * @option ignore-contrib Ignore contributed projects.
   * @option ignore-custom Ignore custom projects.
   * @option phpstan-memory-limit Set memory limit for PHPStan (default: 1500M).
   *
   * @throws \InvalidArgumentException
   *   Thrown when one of the passed arguments is invalid or no arguments were provided.
   */
  public function doAnalyze(array $projects, array $options = ['all' => FALSE, 'skip-existing' => FALSE, 'ignore-uninstalled' => FALSE, 'ignore-contrib' => FALSE, 'ignore-custom' => FALSE]) {
  public function doAnalyze(array $projects, array $options = ['all' => FALSE, 'skip-existing' => FALSE, 'ignore-uninstalled' => FALSE, 'ignore-contrib' => FALSE, 'ignore-custom' => FALSE, 'phpstan-memory-limit' => '1500M']) {
    // Group by type here so we can tell loader what is type of each one of
    // these.
    $extensions = [];
@@ -258,7 +261,7 @@ class UpgradeStatusCommands extends DrushCommands {
          }
        }
        $this->logger()->info(dt('Processing @name.', ['@name' => $name]));
        $this->deprecationAnalyzer->analyze($extension);
        $this->deprecationAnalyzer->analyze($extension, $options);
      }
    }

+6 −3
Original line number Diff line number Diff line
@@ -334,11 +334,13 @@ final class DeprecationAnalyzer {
   *
   * @param \Drupal\Core\Extension\Extension $extension
   *   The extension to analyze.
   * @param array $options
   *   Options for the analysis.
   *
   * @return null
   *   Errors are logged to the logger, data is stored to keyvalue storage.
   */
  public function analyze(Extension $extension) {
  public function analyze(Extension $extension, array $options = []) {
    try {
      $this->initEnvironment();
    }
@@ -354,14 +356,15 @@ final class DeprecationAnalyzer {
    $project_dir = DRUPAL_ROOT . '/' . $extension->getPath();
    $this->logger->notice('Processing %path.', ['%path' => $project_dir]);

    $memory_limit = $options['phpstan-memory-limit'] ?? '1500M';
    $command = [
      $this->phpPath,
      $this->binPath . '/phpstan',
      'analyse',
      '--memory-limit=-1',
      '--memory-limit=' . $memory_limit,
      '--error-format=json',
      '--configuration=' . $this->phpstanNeonPath,
      $project_dir,
      $project_dir
    ];

    $process = new Process($command, DRUPAL_ROOT, NULL, NULL, NULL);