diff --git a/.circleci/config.yml b/.circleci/config.yml index 648eed2dd4b..a27f2b178af 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -44,7 +44,7 @@ jobs: at: /home/docker/project/ - run: name: Build Phar file - command: bin/build-phar.sh + command: bin/ci/build-phar.sh - run: name: Smoke test Phar file # Change the root away from the project root to avoid conflicts with the Composer autoloader @@ -71,13 +71,13 @@ jobs: at: /home/docker/project/ - run: name: Analyse PHPUnit - command: bin/test-with-real-projects.sh phpunit + command: bin/ci/test-with-real-projects.sh phpunit - run: name: Analyse Psl - command: bin/test-with-real-projects.sh psl + command: bin/ci/test-with-real-projects.sh psl - run: name: Analyse Collections - command: bin/test-with-real-projects.sh collections + command: bin/ci/test-with-real-projects.sh collections # Orchestrate or schedule a set of jobs, see https://circleci.com/docs/2.0/workflows/ workflows: diff --git a/.github/workflows/build-phar.yml b/.github/workflows/build-phar.yml index 7168fa4b643..379d7aac759 100644 --- a/.github/workflows/build-phar.yml +++ b/.github/workflows/build-phar.yml @@ -74,7 +74,7 @@ jobs: # env: # COMPOSER_ROOT_VERSION: dev-master - - run: bin/build-phar.sh + - run: bin/ci/build-phar.sh env: GPG_SIGNING: 1 GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }} @@ -90,7 +90,7 @@ jobs: tag: ${{ github.ref }} - name: Release psalm/phar - run: bin/github-deploy-phar.sh + run: bin/ci/github-deploy-phar.sh env: PHAR_REPO_TOKEN: ${{ secrets.PHAR_REPO_TOKEN }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cfc2ddc5045..3dbcdb14ef2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -186,4 +186,4 @@ jobs: COMPOSER_ROOT_VERSION: dev-master - name: Run unit tests - run: bin/tests-github-actions.sh + run: bin/ci/tests-github-actions.sh diff --git a/.github/workflows/windows-ci.yml b/.github/workflows/windows-ci.yml index a56fe7263ab..88696ba49d3 100644 --- a/.github/workflows/windows-ci.yml +++ b/.github/workflows/windows-ci.yml @@ -100,7 +100,7 @@ jobs: COMPOSER_ROOT_VERSION: dev-master - name: Generate test suits - run: php bin/generate_testsuites.php $env:CHUNK_COUNT + run: php bin/ci/generate_testsuites.php $env:CHUNK_COUNT - name: Run unit tests run: vendor/bin/paratest --processes=$env:PARALLEL_PROCESSES --testsuite=chunk_$env:CHUNK_NUMBER --log-junit build/phpunit/phpunit.xml diff --git a/bin/build-phar.sh b/bin/ci/build-phar.sh similarity index 100% rename from bin/build-phar.sh rename to bin/ci/build-phar.sh diff --git a/bin/composer-require-checker-config.json b/bin/ci/composer-require-checker-config.json similarity index 100% rename from bin/composer-require-checker-config.json rename to bin/ci/composer-require-checker-config.json diff --git a/bin/generate_testsuites.php b/bin/ci/generate_testsuites.php similarity index 100% rename from bin/generate_testsuites.php rename to bin/ci/generate_testsuites.php diff --git a/bin/github-deploy-phar.sh b/bin/ci/github-deploy-phar.sh similarity index 100% rename from bin/github-deploy-phar.sh rename to bin/ci/github-deploy-phar.sh diff --git a/bin/improve_class_alias.php b/bin/ci/improve_class_alias.php similarity index 100% rename from bin/improve_class_alias.php rename to bin/ci/improve_class_alias.php diff --git a/bin/phar.psalm.xml b/bin/ci/phar.psalm.xml similarity index 100% rename from bin/phar.psalm.xml rename to bin/ci/phar.psalm.xml diff --git a/bin/test-with-real-projects.sh b/bin/ci/test-with-real-projects.sh similarity index 93% rename from bin/test-with-real-projects.sh rename to bin/ci/test-with-real-projects.sh index d22dc0c2d0a..686674e7b5b 100755 --- a/bin/test-with-real-projects.sh +++ b/bin/ci/test-with-real-projects.sh @@ -5,8 +5,8 @@ set -x SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" SCRIPT_DIR="$(realpath "$SCRIPT_DIR")" -PSALM="$(readlink -f "$SCRIPT_DIR/../psalm")" -PSALM_PHAR="$(readlink -f "$SCRIPT_DIR/../build/psalm.phar")" +PSALM="$(readlink -f "$SCRIPT_DIR/../../psalm")" +PSALM_PHAR="$(readlink -f "$SCRIPT_DIR/../../build/psalm.phar")" cd /tmp/ rm -Rf testing-with-real-projects diff --git a/bin/tests-github-actions.sh b/bin/ci/tests-github-actions.sh similarity index 100% rename from bin/tests-github-actions.sh rename to bin/ci/tests-github-actions.sh diff --git a/bin/generate_issues_list_doc.php b/bin/docs/generate_issues_list_doc.php similarity index 100% rename from bin/generate_issues_list_doc.php rename to bin/docs/generate_issues_list_doc.php diff --git a/bin/generate_levels_doc.php b/bin/docs/generate_levels_doc.php similarity index 100% rename from bin/generate_levels_doc.php rename to bin/docs/generate_levels_doc.php diff --git a/bin/max_used_shortcode.php b/bin/docs/max_used_shortcode.php similarity index 100% rename from bin/max_used_shortcode.php rename to bin/docs/max_used_shortcode.php diff --git a/bin/Dockerfile_7.0 b/bin/stubs/Dockerfile_7.0 similarity index 100% rename from bin/Dockerfile_7.0 rename to bin/stubs/Dockerfile_7.0 diff --git a/bin/Dockerfile_7.1 b/bin/stubs/Dockerfile_7.1 similarity index 100% rename from bin/Dockerfile_7.1 rename to bin/stubs/Dockerfile_7.1 diff --git a/bin/Dockerfile_7.2 b/bin/stubs/Dockerfile_7.2 similarity index 100% rename from bin/Dockerfile_7.2 rename to bin/stubs/Dockerfile_7.2 diff --git a/bin/Dockerfile_7.3 b/bin/stubs/Dockerfile_7.3 similarity index 100% rename from bin/Dockerfile_7.3 rename to bin/stubs/Dockerfile_7.3 diff --git a/bin/Dockerfile_7.4 b/bin/stubs/Dockerfile_7.4 similarity index 100% rename from bin/Dockerfile_7.4 rename to bin/stubs/Dockerfile_7.4 diff --git a/bin/Dockerfile_8.0 b/bin/stubs/Dockerfile_8.0 similarity index 100% rename from bin/Dockerfile_8.0 rename to bin/stubs/Dockerfile_8.0 diff --git a/bin/Dockerfile_8.1 b/bin/stubs/Dockerfile_8.1 similarity index 100% rename from bin/Dockerfile_8.1 rename to bin/stubs/Dockerfile_8.1 diff --git a/bin/Dockerfile_8.2 b/bin/stubs/Dockerfile_8.2 similarity index 100% rename from bin/Dockerfile_8.2 rename to bin/stubs/Dockerfile_8.2 diff --git a/bin/Dockerfile_8.3 b/bin/stubs/Dockerfile_8.3 similarity index 100% rename from bin/Dockerfile_8.3 rename to bin/stubs/Dockerfile_8.3 diff --git a/bin/Dockerfile_8.4 b/bin/stubs/Dockerfile_8.4 similarity index 100% rename from bin/Dockerfile_8.4 rename to bin/stubs/Dockerfile_8.4 diff --git a/bin/README-CALLMAP.md b/bin/stubs/README.md similarity index 100% rename from bin/README-CALLMAP.md rename to bin/stubs/README.md diff --git a/bin/gen_base_callmap.php b/bin/stubs/gen_base_callmap.php similarity index 100% rename from bin/gen_base_callmap.php rename to bin/stubs/gen_base_callmap.php diff --git a/bin/gen_callmap.php b/bin/stubs/gen_callmap.php similarity index 100% rename from bin/gen_callmap.php rename to bin/stubs/gen_callmap.php diff --git a/bin/gen_callmap.sh b/bin/stubs/gen_callmap.sh similarity index 100% rename from bin/gen_callmap.sh rename to bin/stubs/gen_callmap.sh diff --git a/bin/gen_callmap_utils.php b/bin/stubs/gen_callmap_utils.php similarity index 81% rename from bin/gen_callmap_utils.php rename to bin/stubs/gen_callmap_utils.php index 9a0ea1f7f2c..f10f6722f1b 100644 --- a/bin/gen_callmap_utils.php +++ b/bin/stubs/gen_callmap_utils.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\Namespace_; use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\Type\Comparator\UnionTypeComparator; use Psalm\Type; @@ -228,3 +230,54 @@ function writeCallMap(string $file, array $callMap): void return '.var_export($callMap, true).';'); } + +/** + * @template K as array-key + * @template V + * @param array $a + * @param array $b + * @return array + */ +function get_changed_functions(array $a, array $b): array +{ + $changed_functions = []; + + foreach (array_intersect_key($a, $b) as $function_name => $a_data) { + if (json_encode($b[$function_name]) !== json_encode($a_data)) { + $changed_functions[$function_name] = $b[$function_name]; + } + } + + return $changed_functions; +} + +function extractClassesFromStatements(array $statements): array +{ + $classes = []; + foreach ($statements as $statement) { + if ($statement instanceof Class_) { + $classes[strtolower($statement->namespacedName->toString())] = true; + } + if ($statement instanceof Namespace_) { + $classes += extractClassesFromStatements($statement->stmts); + } + } + + return $classes; +} + +function serializeArray(array $array, string $prefix): string +{ + uksort($array, fn(string $first, string $second): int => strtolower($first) <=> strtolower($second)); + $result = "[\n"; + $localPrefix = $prefix . ' '; + foreach ($array as $key => $value) { + $result .= $localPrefix . var_export((string) $key, true) . ' => ' . + (is_array($value) + ? serializeArray($value, $localPrefix) + : var_export($value, true)) . ",\n"; + } + $result .= $prefix . ']'; + + return $result; +} diff --git a/bin/php.ini b/bin/stubs/php.ini similarity index 100% rename from bin/php.ini rename to bin/stubs/php.ini diff --git a/bin/update-property-map.php b/bin/stubs/update-property-map.php similarity index 82% rename from bin/update-property-map.php rename to bin/stubs/update-property-map.php index 19c567f1728..5d7188458d7 100755 --- a/bin/update-property-map.php +++ b/bin/stubs/update-property-map.php @@ -11,8 +11,6 @@ // // What we are currently missing is properly parsing of directives. -use PhpParser\Node\Stmt\Class_; -use PhpParser\Node\Stmt\Namespace_; use PhpParser\NodeTraverser; use PhpParser\NodeVisitor\NameResolver; use PhpParser\ParserFactory; @@ -21,32 +19,18 @@ throw new ErrorException($str, 0, $num, $file, $line); }); -foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) { +foreach ([__DIR__ . '/../../../../autoload.php', __DIR__ . '/../../vendor/autoload.php'] as $file) { if (file_exists($file)) { require $file; break; } } +require __DIR__ . '/gen_callmap_utils.php'; $parser = (new ParserFactory)->createForNewestSupportedVersion(); $traverser = new NodeTraverser(); $traverser->addVisitor(new NameResolver); -function extractClassesFromStatements(array $statements): array -{ - $classes = []; - foreach ($statements as $statement) { - if ($statement instanceof Class_) { - $classes[strtolower($statement->namespacedName->toString())] = true; - } - if ($statement instanceof Namespace_) { - $classes += extractClassesFromStatements($statement->stmts); - } - } - - return $classes; -} - $stubbedClasses = []; foreach (new RecursiveDirectoryIterator( __DIR__ . '/../stubs', @@ -161,22 +145,6 @@ function extractClassesFromStatements(array $statements): array } } -function serializeArray(array $array, string $prefix): string -{ - uksort($array, fn(string $first, string $second): int => strtolower($first) <=> strtolower($second)); - $result = "[\n"; - $localPrefix = $prefix . ' '; - foreach ($array as $key => $value) { - $result .= $localPrefix . var_export((string) $key, true) . ' => ' . - (is_array($value) - ? serializeArray($value, $localPrefix) - : var_export($value, true)) . ",\n"; - } - $result .= $prefix . ']'; - - return $result; -} - $serialized = serializeArray($classes, ''); file_put_contents( dirname(__DIR__) . '/dictionaries/PropertyMap.php', diff --git a/dictionaries/scripts/update_signaturemap_from_other_tool.php b/bin/stubs/update_signaturemap_from_other_tool.php similarity index 77% rename from dictionaries/scripts/update_signaturemap_from_other_tool.php rename to bin/stubs/update_signaturemap_from_other_tool.php index d50e88ee0a8..161110a7eee 100644 --- a/dictionaries/scripts/update_signaturemap_from_other_tool.php +++ b/bin/stubs/update_signaturemap_from_other_tool.php @@ -1,5 +1,9 @@ strtolower($a) <=> strtolower($b)); @@ -51,16 +55,3 @@ echo '],' . "\n"; } - - -function get_changed_functions(array $a, array $b) { - $changed_functions = []; - - foreach (array_intersect_key($a, $b) as $function_name => $a_data) { - if (json_encode($b[$function_name]) !== json_encode($a_data)) { - $changed_functions[$function_name] = $b[$function_name]; - } - } - - return $changed_functions; -} diff --git a/composer.json b/composer.json index 7d5aa504ee3..8cbac81d307 100644 --- a/composer.json +++ b/composer.json @@ -129,6 +129,16 @@ "@cs", "@psalm", "@phpunit" + ], + "gen_callmap": "./bin/stubs/gen_callmap.sh", + "gen_propertymap": "@php ./bin/stubs/update-property-map.php", + "generate_issues_list_doc": "@php ./bin/docs/generate_issues_list_doc.php", + "generate_levels_doc": "@php ./bin/docs/generate_levels_doc.php", + "build": [ + "@gen_callmap", + "@gen_propertymap", + "@generate_issues_list_doc", + "@generate_levels_doc" ] }, "scripts-descriptions": { @@ -138,7 +148,8 @@ "phpunit": "Runs unit tests in parallel.", "phpunit-std": "Runs unit tests.", "psalm": "Runs static analysis.", - "tests": "Runs all available tests." + "tests": "Runs all available tests.", + "build": "Generates all autogenerated files." }, "support": { "docs": "https://psalm.dev/docs", diff --git a/src/Psalm/Internal/VersionUtils.php b/src/Psalm/Internal/VersionUtils.php index fcf7f279f86..61c27d15a8a 100644 --- a/src/Psalm/Internal/VersionUtils.php +++ b/src/Psalm/Internal/VersionUtils.php @@ -40,7 +40,7 @@ public static function getPhpParserVersion(): string return self::getVersions()[self::PHP_PARSER_PACKAGE]; } - /** @psalm-suppress UnusedMethod called from bin/build-phar.sh */ + /** @psalm-suppress UnusedMethod called from bin/ci/build-phar.sh */ public static function dump(): void { $versions = self::loadComposerVersions(); diff --git a/tests/DocumentationTest.php b/tests/DocumentationTest.php index 7e5554802d9..91d132913d5 100644 --- a/tests/DocumentationTest.php +++ b/tests/DocumentationTest.php @@ -433,7 +433,7 @@ protected function failureDescription(mixed $other): string /** * Tests that issues.md contains the expected links to issue documentation. - * issues.md can be generated automatically with bin/generate_documentation_issues_list.php. + * issues.md can be generated automatically with bin/docs/generate_documentation_issues_list.php. */ public function testIssuesIndex(): void {