diff --git a/docs/README.md b/docs/README.md index 15e2ec2645e..2d7171d4f34 100644 --- a/docs/README.md +++ b/docs/README.md @@ -19,7 +19,7 @@ Psalm also has a few features to make it perform as well as possible on large co Wherever possible Psalm will run its analysis in parallel to save time. Useful for large codebases, it has a massive impact on performance. - **Incremental checks**
- When using the `--diff` command line option, Psalm will only analyse files that have changed *and* files that reference them. + By default Psalm only analyses files that have changed and files that reference those changed files. ## Example output diff --git a/docs/running_psalm/command_line_usage.md b/docs/running_psalm/command_line_usage.md index d5492fc6099..e2f97a4e6eb 100644 --- a/docs/running_psalm/command_line_usage.md +++ b/docs/running_psalm/command_line_usage.md @@ -30,10 +30,11 @@ Psalm has a couple of command-line options that will result in faster builds: - `--threads=[n]` to run Psalm’s analysis in a number of threads - `--diff` which only checks files you’ve updated since the last run (and their dependents). -- `--diff-methods` which only checks methods you’ve updated since the last run (and their dependents). + +In Psalm 4 `--diff` is turned on by default (you can disable it with `--no-diff`). Data from the last run is stored in the *cache directory*, which may be set in [configuration](./configuration.md). If you are running Psalm on a build server, you may want to configure the server to ensure that the cache directory is preserved between runs. -Running them together (e.g. `--threads=8 --diff --diff-methods`) will result in the fastest possible Psalm run. +Running them together (e.g. `--threads=8 --diff`) will result in the fastest possible Psalm run. diff --git a/docs/running_psalm/installation.md b/docs/running_psalm/installation.md index 801bcd8d2f0..da19f34b204 100644 --- a/docs/running_psalm/installation.md +++ b/docs/running_psalm/installation.md @@ -1,6 +1,6 @@ # Installation -The latest version of Psalm requires PHP >= 7.1 and [Composer](https://getcomposer.org/). +The latest version of Psalm requires PHP >= 7.3 and [Composer](https://getcomposer.org/). ```bash composer require --dev vimeo/psalm diff --git a/src/command_functions.php b/src/command_functions.php index ded3087aa86..01fa3892aee 100644 --- a/src/command_functions.php +++ b/src/command_functions.php @@ -317,8 +317,8 @@ function getPsalmHelpText(): string --threads=INT If greater than one, Psalm will run analysis on multiple threads, speeding things up. - --diff - Runs Psalm in diff mode, only checking files that have changed since last run (and their dependents) + --no-diff + Turns off Psalm’s diff mode, checks all files regardless of whether they've changed --diff-methods Only checks methods that have changed since last run (and their dependents) diff --git a/src/psalm.php b/src/psalm.php index 88c16014df5..7e066b14ffe 100644 --- a/src/psalm.php +++ b/src/psalm.php @@ -83,7 +83,6 @@ 'debug-performance', 'debug-emitted-issues', 'diff', - 'diff-methods', 'disable-extension:', 'find-dead-code::', 'find-unused-code::', @@ -94,6 +93,7 @@ 'init', 'memory-limit:', 'monochrome', + 'no-diff', 'no-cache', 'no-reflection-cache', 'no-file-cache', @@ -483,7 +483,9 @@ function (string $arg): bool { ? $options['show-info'] === 'true' || $options['show-info'] === '1' : false; -$is_diff = isset($options['diff']); +$is_diff = !isset($options['no-diff']) + && !isset($options['set-baseline']) + && !isset($options['update-baseline']); /** @var false|'always'|'auto' $find_unused_code */ $find_unused_code = false; @@ -680,67 +682,59 @@ function (string $arg): bool { } if (isset($options['set-baseline']) && is_string($options['set-baseline'])) { - if ($is_diff) { - fwrite(STDERR, 'Cannot set baseline in --diff mode' . PHP_EOL); - } else { - fwrite(STDERR, 'Writing error baseline to file...' . PHP_EOL); + fwrite(STDERR, 'Writing error baseline to file...' . PHP_EOL); - ErrorBaseline::create( - new \Psalm\Internal\Provider\FileProvider, - $options['set-baseline'], - IssueBuffer::getIssuesData(), - $config->include_php_versions_in_error_baseline || isset($options['include-php-versions']) - ); + ErrorBaseline::create( + new \Psalm\Internal\Provider\FileProvider, + $options['set-baseline'], + IssueBuffer::getIssuesData(), + $config->include_php_versions_in_error_baseline || isset($options['include-php-versions']) + ); - fwrite(STDERR, "Baseline saved to {$options['set-baseline']}."); + fwrite(STDERR, "Baseline saved to {$options['set-baseline']}."); - update_config_file( - $config, - $path_to_config ?? $current_dir, - $options['set-baseline'] - ); + update_config_file( + $config, + $path_to_config ?? $current_dir, + $options['set-baseline'] + ); - fwrite(STDERR, PHP_EOL); - } + fwrite(STDERR, PHP_EOL); } $issue_baseline = []; if (isset($options['update-baseline'])) { - if ($is_diff) { - fwrite(STDERR, 'Cannot update baseline in --diff mode' . PHP_EOL); - } else { - $baselineFile = Config::getInstance()->error_baseline; + $baselineFile = Config::getInstance()->error_baseline; - if (empty($baselineFile)) { - die('Cannot update baseline, because no baseline file is configured.' . PHP_EOL); - } + if (empty($baselineFile)) { + die('Cannot update baseline, because no baseline file is configured.' . PHP_EOL); + } - try { - $issue_current_baseline = ErrorBaseline::read( - new \Psalm\Internal\Provider\FileProvider, - $baselineFile - ); - $total_issues_current_baseline = ErrorBaseline::countTotalIssues($issue_current_baseline); + try { + $issue_current_baseline = ErrorBaseline::read( + new \Psalm\Internal\Provider\FileProvider, + $baselineFile + ); + $total_issues_current_baseline = ErrorBaseline::countTotalIssues($issue_current_baseline); - $issue_baseline = ErrorBaseline::update( - new \Psalm\Internal\Provider\FileProvider, - $baselineFile, - IssueBuffer::getIssuesData(), - $config->include_php_versions_in_error_baseline || isset($options['include-php-versions']) - ); - $total_issues_updated_baseline = ErrorBaseline::countTotalIssues($issue_baseline); + $issue_baseline = ErrorBaseline::update( + new \Psalm\Internal\Provider\FileProvider, + $baselineFile, + IssueBuffer::getIssuesData(), + $config->include_php_versions_in_error_baseline || isset($options['include-php-versions']) + ); + $total_issues_updated_baseline = ErrorBaseline::countTotalIssues($issue_baseline); - $total_fixed_issues = $total_issues_current_baseline - $total_issues_updated_baseline; + $total_fixed_issues = $total_issues_current_baseline - $total_issues_updated_baseline; - if ($total_fixed_issues > 0) { - echo str_repeat('-', 30) . "\n"; - echo $total_fixed_issues . ' errors fixed' . "\n"; - } - } catch (\Psalm\Exception\ConfigException $exception) { - fwrite(STDERR, 'Could not update baseline file: ' . $exception->getMessage() . PHP_EOL); - exit(1); + if ($total_fixed_issues > 0) { + echo str_repeat('-', 30) . "\n"; + echo $total_fixed_issues . ' errors fixed' . "\n"; } + } catch (\Psalm\Exception\ConfigException $exception) { + fwrite(STDERR, 'Could not update baseline file: ' . $exception->getMessage() . PHP_EOL); + exit(1); } }