Skip to content

Commit

Permalink
Merge pull request #4 from navarr/php8-annotation
Browse files Browse the repository at this point in the history
Bring in Version 2
  • Loading branch information
navarr authored Jul 11, 2021
2 parents b7d3419 + fcdea73 commit 9af08fc
Show file tree
Hide file tree
Showing 63 changed files with 3,546 additions and 258 deletions.
10 changes: 7 additions & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
WARDEN_ENV_NAME=depends
WARDEN_ENV_TYPE=laravel
WARDEN_WEB_ROOT=/
WARDEN_PHP=1
COMPOSER_VERSION=2
PHP_VERSION=7.4

TRAEFIK_DOMAIN=depends.test
TRAEFIK_SUBDOMAIN=app

WARDEN_PHP=1
PHP_VERSION=8.0
PHP_XDEBUG_3=1

COMPOSER_VERSION=2
WARDEN_COMPOSER_DIR=./.composer
74 changes: 67 additions & 7 deletions .github/workflows/commit.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,81 @@
name: Static Analysis Test
name: Continuous Integration
on: [push]

jobs:
phpunit:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: xdebug
tools: composer:v2

- name: Checkout Repository
uses: actions/checkout@v2

- name: Install Dependencies
run: composer install

- name: Test
run: vendor/bin/phpunit tests --testdox --coverage-clover coverage.xml

- name: Upload to CodeCov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
fail_ci_if_error: true

phpstan:
name: Static Analysis Check
runs-on: ubuntu-latest
container:
image: davidalger/php:7.2
image: davidalger/php:8.0
steps:
- name: Checkout Repository
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Install Dependencies
run: composer2 install

- name: Install Prestissimo
run: composer global require hirak/prestissimo
- name: Run PHPStan
run: vendor/bin/phpstan

phpcs:
name: Code Style (PSR-12)
runs-on: ubuntu-latest
container:
image: davidalger/php:8.0
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Install Dependencies
run: composer2 install

- name: PHP Code Sniffer
run: vendor/bin/phpcs

infection:
name: Infection Check
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: xdebug
tools: composer:v2

- name: Checkout Repository
uses: actions/checkout@v2

- name: Install dependencies
run: composer install

- name: Run PHPStan
run: vendor/bin/phpstan analyse src --level max
- name: Check for Mutants
run: vendor/bin/infection --threads=$(nproc) --no-progress --logger-github
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
# The @dependency Annotation
![Static Analysis Test](https://github.com/navarr/dependency-annotation/workflows/Static%20Analysis%20Test/badge.svg)
# The #[Dependency] Attribute
[![Latest Stable Version](http://poser.pugx.org/navarr/dependency-annotation/v)](https://packagist.org/packages/navarr/dependency-annotation)
[![Total Downloads](http://poser.pugx.org/navarr/dependency-annotation/downloads)](https://packagist.org/packages/navarr/dependency-annotation)
[![Latest Unstable Version](http://poser.pugx.org/navarr/dependency-annotation/v/unstable)](https://packagist.org/packages/navarr/dependency-annotation)
[![License](http://poser.pugx.org/navarr/dependency-annotation/license)](https://packagist.org/packages/navarr/dependency-annotation)
![Tests](https://github.com/navarr/dependency-annotation/actions/workflows/commit.yml/badge.svg)
![Code Coverage](https://codecov.io/gh/navarr/dependency-annotation/branch/main/graph/badge.svg?token=BHTKOZZDR3)

This project supplies a Composer plugin that adds a command (`why-block`) that interprets the PHP `@dependency`
annotation.
This project supplies a Composer plugin that adds a command (`why-block`) that interprets a PHP `#[Dependency]`
attribute.

## How to use the `@dependency` annotation
## How to use the `#[Dependency]` annotation

Simply include a `@dependency` annotation in any slash-based comment block, in the following format:
Simply include a `#[Dependency]` attribute on any attributable target in the following format:

@dependency composer-package:version-constraint [Explanation]
#[Navarr\Depends\Annotation\Dependency('package', 'versionConstraint', 'reason')]

All fields except the explanation are mandatory. Adding an explanation is _highly recommended_, however.
This FQN may be imported, in which case you can simply use `#[Dependency(...)]`

The version-constraint field cannot contain spaces (even if surrounded by quotes).
All fields except the explanation are mandatory. Adding an explanation is _highly recommended_, however.

## How to process reasons not to upgrade a composer dependency

If you are using the `@dependency` annotation thoroughly, and you are having issues updating a composer dependency, you
If you are using the `#[Dependency]` annotation thoroughly, and you are having issues updating a composer dependency, you
can use the command `composer why-block composer-package version`

This will output a list of files containing a `@dependency` annotation on composer-package with a version-constraint
that cannot be fulfilled by your specified version.
This will output a list of files containing a `#[Dependency]` annotation on composer-package with a version-constraint
that cannot be fulfilled by the specified version.

## How to install

`composer global require navarr/dependency-annotation`

## Compatibility with v1

For speed, version 2 automatically excludes the legacy `@dependency` annotation in favor of the PHP8 `#[Dependency]`
attribute. While transitioning, you may specify the `-l` or `--include-legacy-annotations` flag to the `why-block`
command to force it to process v1 annotations as well.
36 changes: 30 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,47 @@
"type": "composer-plugin",
"license": "MIT",
"require": {
"php": "^7.2",
"composer-plugin-api": "^1|^2",
"composer/composer": "^1|^2",
"php": "^7.1|^8",
"composer-plugin-api": "^2",
"composer/composer": "^2",
"composer/semver": "^1|^2|^3",
"symfony/console": "^5"
"symfony/console": "^5",
"nikic/php-parser": "^4",
"navarr/attribute-dependency": "^1.0.1",
"php-di/php-di": "^6"
},
"suggest": {
"ext-fileinfo": "Use MIME types for PHP file detection",
"ext-json": "Required to use JSON Output",
"ext-simplexml": "Required to use XML Output"
},
"require-dev": {
"php": "^8",
"roave/security-advisories": "dev-master",
"phpstan/phpstan": "^0.12.32"
"phpstan/phpstan": "^0.12.32",
"phpunit/phpunit": "^9.5",
"infection/infection": "^0.23.0",
"squizlabs/php_codesniffer": "^3.6",
"jetbrains/phpstorm-attributes": "^1.0"
},
"autoload": {
"psr-4": {
"Navarr\\Depends\\": "src/"
},
"files": [
"src/polyfills/preg_last_error_msg.func.php"
]
},
"autoload-dev": {
"psr-4": {
"Navarr\\Depends\\Test\\": "tests/"
}
},
"extra": {
"class": "Navarr\\Depends\\Plugin"
"class": "Navarr\\Depends\\Controller\\Composer\\ComposerPlugin",
"branch-alias": {
"dev-php8-annotation": "2.x-dev"
}
},
"archive": {
"exclude": [
Expand Down
25 changes: 25 additions & 0 deletions infection.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"source": {
"directories": [
"src"
]
},
"phpUnit": {
"configDir": "."
},
"mutators": {
"@default": true,
"ConcatOperandRemoval": {
"ignore": [
"Navarr\\Depends\\Parser\\AstParser::parse::82",
"Navarr\\Depends\\Parser\\AstParser::parse::83"
]
},
"Concat": {
"ignore": [
"Navarr\\Depends\\Parser\\AstParser::parse::82",
"Navarr\\Depends\\Parser\\AstParser::parse::83"
]
}
}
}
5 changes: 5 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<rule ref="PSR12"/>
<file>src</file>
</ruleset>
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 8
paths:
- src
15 changes: 15 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<testsuite name="unit">
<directory>tests</directory>
</testsuite>
<coverage cacheDirectory="/tmp">
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory suffix=".php">src/polyfills</directory>
<file>src/Proxy/MimeDeterminer.php</file>
</exclude>
</coverage>
</phpunit>
Loading

0 comments on commit 9af08fc

Please sign in to comment.