Skip to content

Commit

Permalink
Merge pull request #10 from MontealegreLuis/type-resolver
Browse files Browse the repository at this point in the history
Improve Type Resolution
  • Loading branch information
MontealegreLuis committed Aug 18, 2021
2 parents d46d5fb + 4543537 commit 674e237
Show file tree
Hide file tree
Showing 119 changed files with 2,373 additions and 1,002 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ jobs:
composer install --no-interaction --no-progress
- name: "Code quality checks"
run: "make check"
run: |
make check
env | grep GITHUB > .env
env | grep INFECTION >> .env
echo 'XDEBUG_MODE=coverage' >> .env
docker-compose run --rm ci php vendor/bin/infection --threads=4
env:
INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }}

- name: "Run tests with coverage"
run: "vendor/bin/phpunit --exclude-group=snapshot --coverage-text --coverage-clover=coverage.clover"
run: "docker-compose run --rm -e XDEBUG_MODE=coverage tests php vendor/bin/phpunit --exclude-group=snapshot --coverage-text --coverage-clover=coverage.clover"

- name: "Send code coverage to Scrutinizer"
run: |
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ jobs:
sudo apt-get install graphviz
composer install --optimize-autoloader --prefer-dist --no-interaction --no-progress --no-dev --no-plugins
- name: "Import GPG Key"
uses: crazy-max/ghaction-import-gpg@v3
with:
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}

- name: "Build PHAR file"
run: |
wget https://github.com/box-project/box/releases/download/3.13.0/box.phar
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
vendor
composer.*
build
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
currentMenu: changelog
---

# Changelog

All notable changes to phUML are documented using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

Please refer to the [releases](https://github.com/MontealegreLuis/phuml/releases) page for specific details.
4 changes: 4 additions & 0 deletions CODE-OF-CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
currentMenu: conduct
---

# Contributor Covenant Code of Conduct

## Our Pledge
Expand Down
14 changes: 12 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
currentMenu: contributing
---

# Contributing to phUML

## Code of Conduct
Expand Down Expand Up @@ -33,15 +37,21 @@ It is recommended to follow the [7 rules of a good commit message](https://chris

## Coding Guidelines

This project follows the coding standards proposed in [PSR-12][https://www.php-fig.org/psr/psr-12/].
This project follows the coding standards proposed in [PSR-12](https://www.php-fig.org/psr/psr-12/).

Run the following command if you modified either production code or tests.

```bash
make format
```

[Make][make] will run [PHP CS fixer][cs-fixer] and [Rector](https://getrector.org/) in both folders `src` and `tests`.
[Make][make] will run [PHP CS fixer][cs-fixer] in both folders `src` and `tests`.

We also use [Rector](https://getrector.org/) to automatically refactor test and production code.

```bash
make refactor
```

## Using phUML from a Git checkout

Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ check: ## Execute all code quality checks
@vendor/bin/composer-require-checker check
@docker-compose run --rm tests vendor/bin/phpunit --testsuite 'Integration tests'
@vendor/bin/rector process --dry-run
@docker-compose run --rm -e XDEBUG_MODE=coverage -e INFECTION_BADGE_API_KEY=$(INFECTION_BADGE_API_KEY) tests php vendor/bin/infection --threads=4

.PHONY: diagram
diagram: ## Generate a class diagram with phUML using a Docker container
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ It creates a class diagram from an Object-Oriented codebase based on the UML spe
The official phUML Docker image can be found on [Docker Hub](https://hub.docker.com/r/montealegreluis/phuml/).

```bash
docker pull montealegreluis/phuml:5.0.0
docker pull montealegreluis/phuml:5.1.0
```

You can replace `5.0.0` with any of the available [tags](https://hub.docker.com/r/montealegreluis/phuml/tags?page=1&ordering=last_updated)
You can replace `5.1.0` with any of the available [tags](https://hub.docker.com/r/montealegreluis/phuml/tags?page=1&ordering=last_updated)

### Composer

Expand All @@ -30,7 +30,7 @@ Alternatively, you may use [Composer][composer] to download and install phUML as
composer require phuml/phuml
```

It can also be installed globally.
phUML can also be installed globally.

```bash
composer global require phuml/phuml
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"ext-tokenizer": "*",
"league/pipeline": "^1.0.0",
"nikic/php-parser": "^4.11.0",
"phpdocumentor/reflection-docblock": "^5.2",
"phpdocumentor/type-resolver": "^1.4",
"symfony/console": "^5.3.2",
"symfony/finder": "^5.3.0",
"symfony/process": "^5.3.2",
Expand All @@ -36,11 +38,12 @@
"phpro/grumphp": "^1.4.0",
"phpspec/prophecy-phpunit": "^2.0.1",
"phpstan/extension-installer": "^1.1.0",
"phpstan/phpstan": "^0.12.91",
"phpstan/phpstan": "^0.12.94",
"phpstan/phpstan-strict-rules": "^0.12.10",
"phpstan/phpstan-webmozart-assert": "^0.12.15",
"phpunit/phpunit": "^9.5.6",
"pyrech/composer-changelogs": "^1.7.1",
"rector/rector": "0.11.36"
"rector/rector": "0.11.47"
},
"config": {
"optimize-autoloader": true,
Expand Down
9 changes: 9 additions & 0 deletions couscous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,12 @@ menu:
dot_file:
text: Generate a DOT file
relativeUrl: docs/dot-file.html
contributing:
text: Contributing
relativeUrl: contributing.html
conduct:
text: Code of conduct
relativeUrl: code-of-conduct.html
changelog:
text: Changelog
relativeUrl: changelog.html
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,21 @@ services:
image: phuml/tests
volumes:
- .:/usr/src/phuml
ci:
container_name: phuml_ci
build:
context: containers/tests
image: phuml/ci
volumes:
- .:/usr/src/phuml
environment:
XDEBUG_MODE: ${XDEBUG_MODE}
INFECTION_BADGE_API_KEY: ${INFECTION_BADGE_API_KEY}
GITHUB_ACTIONS: ${GITHUB_ACTIONS}
GITHUB_EVENT_NAME: ${GITHUB_EVENT_NAME}
GITHUB_RUN_NUMBER: ${GITHUB_RUN_NUMBER}
GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}
GITHUB_SHA: ${GITHUB_SHA}
GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}
GITHUB_REF: ${GITHUB_REF}
GITHUB_BASE_REF: ${GITHUB_BASE_REF}
4 changes: 4 additions & 0 deletions docs/class-diagram.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
currentMenu: class_diagram
---

# Generate a class diagram

The `phuml:diagram` command will generate a class diagram by scanning the code from a given directory.
Expand Down
4 changes: 4 additions & 0 deletions docs/dot-file.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
currentMenu: dot_file
---

# Generate a DOT file

The `phuml:dot` command will generate a [DOT][dot] file by scanning the code from a given directory.
Expand Down
6 changes: 5 additions & 1 deletion docs/format.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Format
---
currentMenu: format
---

# Diagram Format

## Interfaces and classes

Expand Down
10 changes: 7 additions & 3 deletions docs/installation.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
---
currentMenu: index
---

# Installation

## Docker

The official phUML Docker image can be found on [Docker Hub](https://hub.docker.com/r/montealegreluis/phuml/).

```bash
docker pull montealegreluis/phuml:5.0.0
docker pull montealegreluis/phuml:5.1.0
```

You can replace `5.0.0` with any of th available [tags](https://hub.docker.com/r/montealegreluis/phuml/tags?page=1&ordering=last_updated)
You can replace `5.1.0` with any of th available [tags](https://hub.docker.com/r/montealegreluis/phuml/tags?page=1&ordering=last_updated)

## Composer

Expand All @@ -18,7 +22,7 @@ Alternatively, you may use [Composer](https://getcomposer.org/) to download and
composer require phuml/phuml
```

It can also be installed globally.
phUML can also be installed globally.

```bash
composer global require phuml/phuml
Expand Down
4 changes: 4 additions & 0 deletions docs/statistics.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
currentMenu: statistics
---

# Generate statistics

The `phuml:statistics` command will generate a text file with statistics about the code from a given directory.
Expand Down
27 changes: 26 additions & 1 deletion docs/types.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Type hints
---
currentMenu: types
---

# Type Information

phUML can extract type information from doc blocks

Expand Down Expand Up @@ -36,6 +40,27 @@ final class WithTypes
}
```

## Nullable and union types from DocBlocks

If you can't migrate to a recent PHP version, phUML can extract, nullable and union types from DocBlocks that follow [PSR-5](https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc.md), as shown in the example below.

```php
final class FilteredAttributesBuilders
{
/** @var ?VisibilityFilter */
private $filter;

/**
* @param Stmt|Param $parsedAttribute
* @param UseStatements $useStatements
* @return ?Attribute
*/
public function build($parsedAttribute, $useStatements)
{
}
}
```

## How phUML handles `array`

If `array` is found in a type declaration for an attribute or parameter, phUML will try to extract a more accurate type from the doc block, if present.
Expand Down
6 changes: 3 additions & 3 deletions infection.json.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"timeout": 25,
"timeout": 30,
"source": {
"directories": [
"src"
Expand All @@ -17,6 +17,6 @@
"mutators": {
"@default": true
},
"minMsi": 94,
"minCoveredMsi": 94
"minMsi": 95,
"minCoveredMsi": 95
}
44 changes: 0 additions & 44 deletions src/Code/Attributes/AttributeDocBlock.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Code/ClassDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,6 @@ public function hasAttributes(): bool
*/
public function isAbstract(): bool
{
return \count(array_filter($this->methods(), static fn (Method $method): bool => $method->isAbstract())) > 0;
return array_filter($this->methods(), static fn (Method $method): bool => $method->isAbstract()) !== [];
}
}
6 changes: 3 additions & 3 deletions src/Code/Codebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ public function __construct()

public function add(Definition $definition): void
{
$this->definitions[(string) $definition->name()] = $definition;
$this->definitions[$definition->name()->fullName()] = $definition;
}

public function has(Name $name): bool
{
return isset($this->definitions[(string) $name]);
return isset($this->definitions[$name->fullName()]);
}

public function get(Name $name): Definition
{
return $this->definitions[(string) $name];
return $this->definitions[$name->fullName()];
}

/** @return Definition[] */
Expand Down
4 changes: 2 additions & 2 deletions src/Code/InterfaceDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function parents(): array
*/
public function hasParent(): bool
{
return count($this->parents) > 0;
return $this->parents !== [];
}

/**
Expand All @@ -70,6 +70,6 @@ public function hasParent(): bool
*/
public function hasAttributes(): bool
{
return \count($this->constants) > 0;
return $this->constants !== [];
}
}
2 changes: 1 addition & 1 deletion src/Code/Methods/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __toString(): string
'%s%s%s%s',
$this->modifier,
$this->name,
count($this->parameters) === 0 ? '()' : '(' . implode(', ', $this->parameters) . ')',
$this->parameters === [] ? '()' : '(' . implode(', ', $this->parameters) . ')',
$this->returnType->isPresent() ? ": {$this->returnType}" : ''
);
}
Expand Down
Loading

0 comments on commit 674e237

Please sign in to comment.