From e36d128c21b03108c06cc1fc40b0bdaf4571a7d1 Mon Sep 17 00:00:00 2001 From: Luis Montealegre Date: Tue, 17 Aug 2021 22:16:36 -0500 Subject: [PATCH 1/4] build: Add glob flag to upload binary step - Added missing glob flag to the Github action step that uploads the phar files as attachments to the release --- .github/workflows/publish.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 336277f..29a5405 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -39,6 +39,7 @@ jobs: chmod +x box.phar ./box.phar compile -vv gpg -u montealegreluis@gmail.com --detach-sign --output phuml.phar.asc phuml.phar + ls -alh phuml* - name: "Upload binaries to distribute phUML via PHIVE" uses: "svenstaro/upload-release-action@v2" @@ -46,3 +47,4 @@ jobs: repo_token: ${{ secrets.GITHUB_TOKEN }} file: phuml.phar* tag: ${{ github.ref }} + file_glob: true From c2398d2d9fec4fa48c5060bb50fc73d22c660c57 Mon Sep 17 00:00:00 2001 From: Luis Montealegre Date: Tue, 17 Aug 2021 22:19:48 -0500 Subject: [PATCH 2/4] docs: Fix path to MSI badge/report --- README.md | 2 +- index.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0c74a41..f40533a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![CI workflow](https://github.com/montealegreluis/phuml/actions/workflows/ci.yml/badge.svg)](https://github.com/montealegreluis/phuml/actions/workflows/ci.yml) [![Scrutinizer Code Quality][scrutinizer-badge]][scrutinizer] [![Code Coverage][coverage-badge]][coverage] -[![Infection MSI](https://badge.stryker-mutator.io/github.com/montealegreluis/phuml/master)](https://dashboard.stryker-mutator.io/reports/github.com/montealegreluis/phuml/master) +[![Infection MSI](https://badge.stryker-mutator.io/github.com/MontealegreLuis/phuml/master)](https://dashboard.stryker-mutator.io/reports/github.com/MontealegreLuis/phuml/master) [![Latest Stable Version][stable-badge]][packagist] [![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.0-8892BF.svg?style=flat-square)](https://php.net/) diff --git a/index.md b/index.md index 02620c8..1df89cc 100644 --- a/index.md +++ b/index.md @@ -3,7 +3,7 @@ ![CI workflow](https://github.com/montealegreluis/phuml/actions/workflows/ci.yml/badge.svg) [![Scrutinizer Code Quality][scrutinizer-badge]][scrutinizer] [![Code Coverage][coverage-badge]][coverage] -[![Infection MSI](https://badge.stryker-mutator.io/github.com/montealegreluis/phuml/master)](https://dashboard.stryker-mutator.io/reports/github.com/montealegreluis/phuml/master) +[![Infection MSI](https://badge.stryker-mutator.io/github.com/MontealegreLuis/phuml/master)](https://dashboard.stryker-mutator.io/reports/github.com/MontealegreLuis/phuml/master) [![Latest Stable Version][stable-badge]][packagist] [![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.0-8892BF.svg?style=flat-square)](https://php.net/) From cb222342d8af621680e1507a159c86c3eff3c4e5 Mon Sep 17 00:00:00 2001 From: Luis Montealegre Date: Sun, 22 Aug 2021 12:58:15 -0500 Subject: [PATCH 3/4] fix: Resolve FQN from relative name - Some classes were overwritten when using relative paths in DocBlock, for instance: `Node\Param[]` and `Param` were resolved to the same class --- src/Code/Name.php | 11 ++++++ src/Code/UseStatement.php | 12 +++++- src/Code/UseStatements.php | 3 ++ src/Parser/Code/Builders/TagType.php | 2 +- src/Parser/Code/Builders/TagTypeFactory.php | 3 +- .../unit/Parser/Code/Builders/TagTypeTest.php | 39 +++++++++++++++++++ 6 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 tests/unit/Parser/Code/Builders/TagTypeTest.php diff --git a/src/Code/Name.php b/src/Code/Name.php index 7f59306..368b708 100644 --- a/src/Code/Name.php +++ b/src/Code/Name.php @@ -21,6 +21,11 @@ public function __construct(string $name) $this->parts = explode('\\', trim($name)); } + public function first(): string + { + return $this->parts[0]; + } + public function fullName(): string { return implode('\\', $this->parts); @@ -40,4 +45,10 @@ public function __toString(): string { return $this->parts[count($this->parts) - 1]; } + + public function packageName(): string + { + $package = array_slice($this->parts, 0, -1); + return implode('\\', $package); + } } diff --git a/src/Code/UseStatement.php b/src/Code/UseStatement.php index c4c2fc1..0ac4aeb 100644 --- a/src/Code/UseStatement.php +++ b/src/Code/UseStatement.php @@ -18,6 +18,11 @@ public function endsWith(Name $name): bool return str_ends_with(haystack: (string) $this->name, needle: $name->removeArraySuffix()); } + public function includes(Name $name): bool + { + return str_ends_with(haystack: (string) $this->name, needle: $name->first()); + } + public function isAliasedAs(Name $name): bool { return $this->alias !== null && (string) $this->alias === $name->removeArraySuffix(); @@ -25,6 +30,11 @@ public function isAliasedAs(Name $name): bool public function fullyQualifiedName(Name $name): string { - return $name->isArray() ? $this->name->fullName() . '[]' : $this->name->fullName(); + return $name->isArray() ? "{$this->name->fullName()}[]" : $this->name->fullName(); + } + + public function merge(Name $name): string + { + return "{$this->name->packageName()}\\{$name->fullName()}"; } } diff --git a/src/Code/UseStatements.php b/src/Code/UseStatements.php index 44a525e..4bfd394 100644 --- a/src/Code/UseStatements.php +++ b/src/Code/UseStatements.php @@ -20,6 +20,9 @@ public function fullyQualifiedNameFor(Name $name): string if ($useStatement->endsWith($name)) { return $useStatement->fullyQualifiedName($name); } + if ($useStatement->includes($name)) { + return $useStatement->merge($name); + } if ($useStatement->isAliasedAs($name)) { return $useStatement->fullyQualifiedName($name); } diff --git a/src/Parser/Code/Builders/TagType.php b/src/Parser/Code/Builders/TagType.php index f7240f4..cfbcbba 100644 --- a/src/Parser/Code/Builders/TagType.php +++ b/src/Parser/Code/Builders/TagType.php @@ -30,7 +30,7 @@ public static function named(string $type): TagType } /** @param string[] $types */ - public function __construct(private array $types, private bool $isNullable = false) + private function __construct(private array $types, private bool $isNullable = false) { } diff --git a/src/Parser/Code/Builders/TagTypeFactory.php b/src/Parser/Code/Builders/TagTypeFactory.php index 8945800..5352341 100644 --- a/src/Parser/Code/Builders/TagTypeFactory.php +++ b/src/Parser/Code/Builders/TagTypeFactory.php @@ -14,6 +14,7 @@ use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\Types\Compound; use phpDocumentor\Reflection\Types\Nullable; +use phpDocumentor\Reflection\Types\Object_; final class TagTypeFactory { @@ -88,7 +89,7 @@ private function resolveType(?Type $type): ?TagType $type === null => null, $type instanceof Nullable => TagType::nullable((string) $type->getActualType()), $type instanceof Compound => TagType::compound(array_map('strval', $type->getIterator()->getArrayCopy())), - default => TagType::named((string) $type) + default => TagType::named((string) ($type instanceof Object_ ? $type->getFqsen() : $type)) }; } } diff --git a/tests/unit/Parser/Code/Builders/TagTypeTest.php b/tests/unit/Parser/Code/Builders/TagTypeTest.php new file mode 100644 index 0000000..6ba1c3c --- /dev/null +++ b/tests/unit/Parser/Code/Builders/TagTypeTest.php @@ -0,0 +1,39 @@ +resolve($useStatements); + + $this->assertEquals(TypeDeclaration::from('PhpParser\Node\Param[]'), $type); + } + + /** @test */ + function it_resolves_fully_qualified_names_from_relative_names_with_multiple_prefix() + { + $useStatements = new UseStatements([new UseStatement(new Name('PhpParser\Node'), null)]); + $tagType = TagType::named('Node\Another\Param[]'); + + $type = $tagType->resolve($useStatements); + + $this->assertEquals(TypeDeclaration::from('PhpParser\Node\Another\Param[]'), $type); + } +} From 152faa636d61216f53802e3d9d2f4b1290ddcbb0 Mon Sep 17 00:00:00 2001 From: Luis Montealegre Date: Sun, 22 Aug 2021 21:41:45 -0500 Subject: [PATCH 4/4] chore: Cleanup menu and Makefile - Fix highlighted menu in installation page - Remove unused variable from Makefile --- .scrutinizer.yml | 3 +-- Makefile | 1 - docs/installation.md | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index c20e035..d2bd928 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -20,5 +20,4 @@ build: tools: external_code_coverage: - timeout: 600 - runs: 3 + timeout: 1200 diff --git a/Makefile b/Makefile index 0f94b53..51f5340 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ SHELL = /bin/bash ARGS="" -INFECTION_BADGE_API_KEY="" .PHONY: help help: ## Show help diff --git a/docs/installation.md b/docs/installation.md index 8aaa61b..c1d7a1b 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -1,5 +1,5 @@ --- -currentMenu: index +currentMenu: installation --- # Installation