Skip to content

Commit

Permalink
Merge pull request #8 from MontealegreLuis/attribute-types
Browse files Browse the repository at this point in the history
Support for attribute types
  • Loading branch information
MontealegreLuis authored Jul 5, 2021
2 parents f58adda + e402155 commit 4aa999a
Show file tree
Hide file tree
Showing 228 changed files with 1,761 additions and 1,374 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ jobs:
- name: "Install PHP with extensions"
uses: "shivammathur/setup-php@v2"
with:
php-version: "7.2"
php-version: "7.4"
extensions: imagick
ini-values: memory_limit=-1
coverage: xdebug
tools: composer:v1
tools: composer

- name: "Install dependencies with composer"
run: |
sudo apt-get install graphviz
composer install --no-interaction --no-progress --no-suggest
composer install --no-interaction --no-progress
- name: "Code quality checks"
run: "make check"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "7.1"
php-version: "7.4"
ini-values: memory_limit=-1
tools: composer:v1
tools: composer

- name: "Generate documentation"
run: |
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ jobs:
- name: "Install PHP with extensions"
uses: "shivammathur/setup-php@v2"
with:
php-version: "7.2"
php-version: "7.4"
extensions: imagick
ini-values: memory_limit=-1, phar.readonly=Off
tools: composer:v1

- name: "Install dependencies with composer"
run: |
sudo apt-get install graphviz
composer install --optimize-autoloader --prefer-dist --no-interaction --no-progress --no-suggest --no-dev
composer install --optimize-autoloader --prefer-dist --no-interaction --no-progress --no-suggest --no-dev --no-plugins
- name: "Build PHAR file"
run: |
wget https://github.com/box-project/box/releases/download/3.13.0/box.phar
chmod +x box.phar
./box.phar compile -vv
gpg -u [email protected] --detach-sign --output phuml.phar.asc phuml.phar
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ box.phar
phuml.phar
phuml.phar.pubkey
phuml.phar.version
infection.log
2 changes: 1 addition & 1 deletion .php-cs-fixer-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
'blank_line_after_opening_tag' => false,
'declare_strict_types' => true,
'header_comment' => [
'header' => 'PHP version 7.2
'header' => 'PHP version 7.4
This source file is subject to the license that is bundled with this package in the file LICENSE.',
'comment_type' => 'PHPDoc',
Expand Down
2 changes: 1 addition & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
'blank_line_after_opening_tag' => false,
'declare_strict_types' => true,
'header_comment' => [
'header' => 'PHP version 7.2
'header' => 'PHP version 7.4
This source file is subject to the license that is bundled with this package in the file LICENSE.',
'comment_type' => 'PHPDoc',
Expand Down
19 changes: 18 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ By participating in this project you agree to abide by its terms.

Pull requests for bug fixes must be based on the current stable branch whereas pull requests for new features must be based on the `master` branch.

### Git commit format

Commit messages must follow the [Conventional Commits Specification](https://www.conventionalcommits.org/en/v1.0.0-beta.2/) which is enforced as a Git pre-commit hook via [GrumPHP](https://github.com/phpro/grumphp).

The allowed commit types are:

- `build` for changes to Github Actions or Scrutinizer (CI Pipeline)
- `chore` for changes to the configuration any of the code quality tools used by this project (PHPUnit, PHP CS Fixer, Rector, Composer Normalize, Composer Require Checker, etc.)
- `docs` for updates or additions to the documentation
- `feat` for new features
- `fix` for a fix to an existing console command
- `refactor` for refactoring changes
- `style` for changes that only format code
- `test` for tests only changes

It is recommended to follow the [7 rules of a good commit message](https://chris.beams.io/posts/git-commit/#seven-rules).

## Coding Guidelines

This project follows the coding standards proposed in [PSR-2][psr2]
Expand All @@ -24,7 +41,7 @@ Run the following command if you modified either production code or tests.
make format
```

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

## Using phUML from a Git checkout

Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ test:
@docker-compose run --rm tests php vendor/bin/phpunit --testdox

coverage:
@docker-compose run --rm tests php vendor/bin/phpunit --coverage-html build/coverage
@docker-compose run --rm -e XDEBUG_MODE=coverage tests php vendor/bin/phpunit --coverage-html build/coverage

infection:
@docker-compose run --rm -e XDEBUG_MODE=coverage tests php vendor/bin/infection --threads=4

diagram:
@docker-compose run --rm tests php bin/phuml phuml:diagram $(ARGS)
Expand All @@ -26,8 +28,8 @@ format:
@vendor/bin/php-cs-fixer fix --config=.php-cs-fixer-tests.php -v --using-cache no

check:
@vendor/bin/grumphp run
@vendor/bin/grumphp run --no-interaction
@vendor/bin/composer-require-checker check
@docker-compose run --rm tests vendor/bin/phpunit --testsuite 'Integration tests'
@vendor/bin/php-cs-fixer fix --config=.php-cs-fixer-tests.php -v --dry-run --using-cache=no
@vendor/bin/rector process --dry-run
@docker-compose run --rm -e XDEBUG_MODE=coverage tests php vendor/bin/infection --threads=4
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +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://infection.github.io)
[![Latest Stable Version][stable-badge]][packagist]
[![Minimum PHP Version][php-version-badge]][php]

Expand Down Expand Up @@ -68,7 +69,7 @@ Special thanks to all of these [awesome contributors][contributors].
[codebase]: https://github.com/jakobwesthoff/phuml/tree/master/src
[stable-badge]: https://img.shields.io/packagist/v/phuml/phuml.svg?style=flat-square
[packagist]: https://packagist.org/packages/phuml/phuml
[php-version-badge]: https://img.shields.io/badge/php-%3E%3D%207.1-8892BF.svg?style=flat-square
[php-version-badge]: https://img.shields.io/badge/php-%3E%3D%207.4-8892BF.svg?style=flat-square
[php]: https://php.net/
[luis]: https://github.com/MontealegreLuis
[jakob]: https://github.com/jakobwesthoff
Expand Down
30 changes: 16 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,42 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.4",
"ext-tokenizer": "*",
"nikic/php-parser": "^4.10.5",
"symfony/console": "^5.3.0",
"symfony/filesystem": "^5.3.0",
"nikic/php-parser": "^4.11.0",
"symfony/console": "^5.3.2",
"symfony/filesystem": "^5.3.3",
"symfony/finder": "^5.3.0",
"symfony/process": "^5.3.0",
"symfony/process": "^5.3.2",
"twig/twig": "^3.3.2",
"webmozart/assert": "^1.10.0"
},
"require-dev": {
"ext-imagick": "*",
"ergebnis/composer-normalize": "^2.14.0",
"ergebnis/composer-normalize": "^2.15.0",
"friendsofphp/php-cs-fixer": "^3.0.0",
"infection/infection": "^0.23.0",
"lupka/phpunit-compare-images": "^1.0.0",
"maglnet/composer-require-checker": "^2.1.0",
"phpro/grumphp": "^0.19.1",
"maglnet/composer-require-checker": "^3.3.0",
"phpro/grumphp": "^1.3.3",
"phpspec/prophecy-phpunit": "^2.0.1",
"phpstan/extension-installer": "^1.1.0",
"phpstan/phpstan": "^0.12.88",
"phpstan/phpstan-strict-rules": "^0.12.9",
"phpunit/phpunit": "^8.5.15",
"phpstan/phpstan": "^0.12.90",
"phpstan/phpstan-strict-rules": "^0.12.10",
"phpunit/phpunit": "^9.5.6",
"pyrech/composer-changelogs": "^1.7.1",
"rector/rector": "^0.11.8"
"rector/rector": "0.11.32"
},
"config": {
"optimize-autoloader": true,
"platform": {
"php": "7.2.34"
"php": "7.4.20"
},
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
"dev-master": "5.0-dev"
}
},
"autoload": {
Expand Down
6 changes: 4 additions & 2 deletions containers/tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM php:7.2.34-cli-alpine3.12
FROM php:7.4.20-cli-alpine3.12

RUN apk add --update --no-cache autoconf g++ pkgconfig imagemagick imagemagick-dev make ttf-freefont graphviz \
&& printf "\n" | pecl install imagick \
&& echo "extension=imagick.so" >> /usr/local/etc/php/php.ini
&& echo "extension=imagick.so" >> /usr/local/etc/php/php.ini \
&& printf "\n" | pecl install xdebug \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini

RUN mkdir -p /usr/src/phuml

Expand Down
2 changes: 2 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ Alternatively, you may use [Composer](https://getcomposer.org/) to download and

```bash
composer require phuml/phuml
# or globally
composer global require phuml/phuml
```
31 changes: 29 additions & 2 deletions docs/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ The class below will show type information for all of its attributes and methods
<?php
final class WithTypes
{
/** @var string $name */
private $name;
// In this case type is taken from its declaration
private string $name;

/** @var DateTime */
private $dob;
Expand All @@ -35,3 +35,30 @@ final class WithTypes
}
}
```

## 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.

```php
<?php
final class WithTypeDeclarationsForArray
{
/** @var ClassDefinition[] */
private array $classes;

/** @param ClassDefinition[] */
public function __construct(array $classes)
{
$this->classes = $classes;
}

/** @return ClassDefinition[] */
public function classes(): array
{
return $this->classes;
}
}
```

In the 3 cases above, phUML will use `ClassDefinition[]` instead of `array`.
14 changes: 14 additions & 0 deletions grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ grumphp:
max_subject_width: 50
case_insensitive: true
multiline: true
type_scope_conventions:
- types:
- build
- chore
- docs
- feat
- fix
- refactor
- style
- test
composer:
composer_normalize:
phpstan:
Expand All @@ -26,3 +36,7 @@ grumphp:
config_contains_finder: true
config: .php-cs-fixer.php
triggered_by: ['php']
phpcsfixer2_test:
config: .php-cs-fixer-tests.php
metadata:
task: phpcsfixer2
5 changes: 3 additions & 2 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
![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://infection.github.io)
[![Latest Stable Version][stable-badge]][packagist]
[![Minimum PHP Version][php-badge]][php]

phUML is a fully automatic [UML][uml] class diagram generator written [PHP][php].
It creates a class diagram from an OO codebase based on the UML specification.
It creates a class diagram from an Object-Oriented codebase based on the UML specification.

To successfully create UML diagrams with phUML you will need to install the [graphviz][graphviz] toolkit.

Expand All @@ -32,5 +33,5 @@ You can take a look at the complete image by clicking [here][diagram].
[coverage]: https://scrutinizer-ci.com/g/MontealegreLuis/phuml/?branch=master
[stable-badge]: https://img.shields.io/packagist/v/phuml/phuml.svg?style=flat-square
[packagist]: https://packagist.org/packages/phuml/phuml
[php-badge]: https://img.shields.io/badge/php-%3E%3D%207.1-8892BF.svg?style=flat-square
[php-badge]: https://img.shields.io/badge/php-%3E%3D%207.4-8892BF.svg?style=flat-square
[php]: https://php.net/
21 changes: 21 additions & 0 deletions infection.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"source": {
"directories": [
"src"
],
"excludes": [
"resources"
]
},
"logs": {
"text": "infection.log",
"badge": {
"branch": "master"
}
},
"mutators": {
"@default": true
},
"minMsi": 85,
"minCoveredMsi": 85
}
35 changes: 0 additions & 35 deletions phar.sh

This file was deleted.

1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ parameters:
inferPrivatePropertyTypeFromConstructor: true
ignoreErrors:
- "#Strict comparison using === between '@package_version@' and '@package_version@' will always evaluate to true#"
- "#Unsafe usage of new static#"
Loading

0 comments on commit 4aa999a

Please sign in to comment.