Skip to content

Commit 9af08fc

Browse files
authored
Merge pull request #4 from navarr/php8-annotation
Bring in Version 2
2 parents b7d3419 + fcdea73 commit 9af08fc

File tree

63 files changed

+3546
-258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3546
-258
lines changed

.env

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
WARDEN_ENV_NAME=depends
22
WARDEN_ENV_TYPE=laravel
33
WARDEN_WEB_ROOT=/
4-
WARDEN_PHP=1
5-
COMPOSER_VERSION=2
6-
PHP_VERSION=7.4
4+
75
TRAEFIK_DOMAIN=depends.test
86
TRAEFIK_SUBDOMAIN=app
7+
8+
WARDEN_PHP=1
9+
PHP_VERSION=8.0
10+
PHP_XDEBUG_3=1
11+
12+
COMPOSER_VERSION=2
913
WARDEN_COMPOSER_DIR=./.composer

.github/workflows/commit.yml

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,81 @@
1-
name: Static Analysis Test
1+
name: Continuous Integration
22
on: [push]
33

44
jobs:
5+
phpunit:
6+
name: Unit Tests
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Setup PHP
10+
uses: shivammathur/setup-php@v2
11+
with:
12+
php-version: 8.0
13+
coverage: xdebug
14+
tools: composer:v2
15+
16+
- name: Checkout Repository
17+
uses: actions/checkout@v2
18+
19+
- name: Install Dependencies
20+
run: composer install
21+
22+
- name: Test
23+
run: vendor/bin/phpunit tests --testdox --coverage-clover coverage.xml
24+
25+
- name: Upload to CodeCov
26+
uses: codecov/codecov-action@v1
27+
with:
28+
token: ${{ secrets.CODECOV_TOKEN }}
29+
files: coverage.xml
30+
fail_ci_if_error: true
31+
532
phpstan:
633
name: Static Analysis Check
734
runs-on: ubuntu-latest
835
container:
9-
image: davidalger/php:7.2
36+
image: davidalger/php:8.0
1037
steps:
1138
- name: Checkout Repository
12-
uses: actions/checkout@v1
39+
uses: actions/checkout@v2
40+
41+
- name: Install Dependencies
42+
run: composer2 install
1343

14-
- name: Install Prestissimo
15-
run: composer global require hirak/prestissimo
44+
- name: Run PHPStan
45+
run: vendor/bin/phpstan
46+
47+
phpcs:
48+
name: Code Style (PSR-12)
49+
runs-on: ubuntu-latest
50+
container:
51+
image: davidalger/php:8.0
52+
steps:
53+
- name: Checkout Repository
54+
uses: actions/checkout@v2
1655

1756
- name: Install Dependencies
57+
run: composer2 install
58+
59+
- name: PHP Code Sniffer
60+
run: vendor/bin/phpcs
61+
62+
infection:
63+
name: Infection Check
64+
runs-on: ubuntu-latest
65+
continue-on-error: true
66+
steps:
67+
- name: Setup PHP
68+
uses: shivammathur/setup-php@v2
69+
with:
70+
php-version: 8.0
71+
coverage: xdebug
72+
tools: composer:v2
73+
74+
- name: Checkout Repository
75+
uses: actions/checkout@v2
76+
77+
- name: Install dependencies
1878
run: composer install
1979

20-
- name: Run PHPStan
21-
run: vendor/bin/phpstan analyse src --level max
80+
- name: Check for Mutants
81+
run: vendor/bin/infection --threads=$(nproc) --no-progress --logger-github

README.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
1-
# The @dependency Annotation
2-
![Static Analysis Test](https://github.com/navarr/dependency-annotation/workflows/Static%20Analysis%20Test/badge.svg)
1+
# The #[Dependency] Attribute
2+
[![Latest Stable Version](http://poser.pugx.org/navarr/dependency-annotation/v)](https://packagist.org/packages/navarr/dependency-annotation)
3+
[![Total Downloads](http://poser.pugx.org/navarr/dependency-annotation/downloads)](https://packagist.org/packages/navarr/dependency-annotation)
4+
[![Latest Unstable Version](http://poser.pugx.org/navarr/dependency-annotation/v/unstable)](https://packagist.org/packages/navarr/dependency-annotation)
5+
[![License](http://poser.pugx.org/navarr/dependency-annotation/license)](https://packagist.org/packages/navarr/dependency-annotation)
6+
![Tests](https://github.com/navarr/dependency-annotation/actions/workflows/commit.yml/badge.svg)
7+
![Code Coverage](https://codecov.io/gh/navarr/dependency-annotation/branch/main/graph/badge.svg?token=BHTKOZZDR3)
38

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

7-
## How to use the `@dependency` annotation
12+
## How to use the `#[Dependency]` annotation
813

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

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

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

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

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

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

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

2530
## How to install
2631

2732
`composer global require navarr/dependency-annotation`
33+
34+
## Compatibility with v1
35+
36+
For speed, version 2 automatically excludes the legacy `@dependency` annotation in favor of the PHP8 `#[Dependency]`
37+
attribute. While transitioning, you may specify the `-l` or `--include-legacy-annotations` flag to the `why-block`
38+
command to force it to process v1 annotations as well.

composer.json

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,47 @@
44
"type": "composer-plugin",
55
"license": "MIT",
66
"require": {
7-
"php": "^7.2",
8-
"composer-plugin-api": "^1|^2",
9-
"composer/composer": "^1|^2",
7+
"php": "^7.1|^8",
8+
"composer-plugin-api": "^2",
9+
"composer/composer": "^2",
1010
"composer/semver": "^1|^2|^3",
11-
"symfony/console": "^5"
11+
"symfony/console": "^5",
12+
"nikic/php-parser": "^4",
13+
"navarr/attribute-dependency": "^1.0.1",
14+
"php-di/php-di": "^6"
15+
},
16+
"suggest": {
17+
"ext-fileinfo": "Use MIME types for PHP file detection",
18+
"ext-json": "Required to use JSON Output",
19+
"ext-simplexml": "Required to use XML Output"
1220
},
1321
"require-dev": {
22+
"php": "^8",
1423
"roave/security-advisories": "dev-master",
15-
"phpstan/phpstan": "^0.12.32"
24+
"phpstan/phpstan": "^0.12.32",
25+
"phpunit/phpunit": "^9.5",
26+
"infection/infection": "^0.23.0",
27+
"squizlabs/php_codesniffer": "^3.6",
28+
"jetbrains/phpstorm-attributes": "^1.0"
1629
},
1730
"autoload": {
1831
"psr-4": {
1932
"Navarr\\Depends\\": "src/"
33+
},
34+
"files": [
35+
"src/polyfills/preg_last_error_msg.func.php"
36+
]
37+
},
38+
"autoload-dev": {
39+
"psr-4": {
40+
"Navarr\\Depends\\Test\\": "tests/"
2041
}
2142
},
2243
"extra": {
23-
"class": "Navarr\\Depends\\Plugin"
44+
"class": "Navarr\\Depends\\Controller\\Composer\\ComposerPlugin",
45+
"branch-alias": {
46+
"dev-php8-annotation": "2.x-dev"
47+
}
2448
},
2549
"archive": {
2650
"exclude": [

infection.json.dist

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"source": {
3+
"directories": [
4+
"src"
5+
]
6+
},
7+
"phpUnit": {
8+
"configDir": "."
9+
},
10+
"mutators": {
11+
"@default": true,
12+
"ConcatOperandRemoval": {
13+
"ignore": [
14+
"Navarr\\Depends\\Parser\\AstParser::parse::82",
15+
"Navarr\\Depends\\Parser\\AstParser::parse::83"
16+
]
17+
},
18+
"Concat": {
19+
"ignore": [
20+
"Navarr\\Depends\\Parser\\AstParser::parse::82",
21+
"Navarr\\Depends\\Parser\\AstParser::parse::83"
22+
]
23+
}
24+
}
25+
}

phpcs.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
3+
<rule ref="PSR12"/>
4+
<file>src</file>
5+
</ruleset>

phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 8
3+
paths:
4+
- src

phpunit.xml.dist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<testsuite name="unit">
4+
<directory>tests</directory>
5+
</testsuite>
6+
<coverage cacheDirectory="/tmp">
7+
<include>
8+
<directory suffix=".php">src</directory>
9+
</include>
10+
<exclude>
11+
<directory suffix=".php">src/polyfills</directory>
12+
<file>src/Proxy/MimeDeterminer.php</file>
13+
</exclude>
14+
</coverage>
15+
</phpunit>

0 commit comments

Comments
 (0)