Skip to content

Commit

Permalink
Merge branch 'main' into leak-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
simivar authored Jan 30, 2025
2 parents 5e50455 + c82446b commit 8bb8a1f
Show file tree
Hide file tree
Showing 66 changed files with 929 additions and 160 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/architectural-rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Architectural test

on:
push:

jobs:
phparkitect:
name: PHPArkitect

runs-on: ubuntu-latest

steps:
- name: "Checkout"
uses: actions/checkout@v2

- name: PHPArkitect
uses: docker://phparkitect/arkitect-github-actions:latest
with:
args: check
10 changes: 2 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ jobs:
build:
runs-on: "ubuntu-22.04"
strategy:
fail-fast: false
matrix:
php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
coverage-driver: [ 'pcov' ]

steps:
Expand Down Expand Up @@ -56,13 +57,6 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Architectural Rules
uses: docker://phparkitect/arkitect-github-actions:latest
env:
PHP_VERSION: ${{ matrix.php-versions }}
with:
args: check

phar:
runs-on: "ubuntu-20.04"
needs: build
Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
'modernize_types_casting' => true, // Replaces intval, floatval, doubleval, strval and boolval function calls with according type casting operator.
'multiline_whitespace_before_semicolons' => true, // Forbid multi-line whitespace before the closing semicolon or move the semicolon to the new line for chained calls.
'no_unreachable_default_argument_value' => true, // In function arguments there must not be arguments with default values before non-default ones.
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],// To avoid problems of compatibility with the old php-cs-fixer version used on PHP 7.3
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true, // Orders the elements of classes/interfaces/traits.
Expand Down
17 changes: 13 additions & 4 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,31 @@ Shout out to our top contributors!

- [AlessandroMinoccheri](https://api.github.com/users/AlessandroMinoccheri)
- [fain182](https://api.github.com/users/fain182)
- [micheleorselli](https://api.github.com/users/micheleorselli)
- [pfazzi](https://api.github.com/users/pfazzi)
- [github-actions[bot]](https://api.github.com/users/github-actions%5Bbot%5D)
- [ricfio](https://api.github.com/users/ricfio)
- [micheleorselli](https://api.github.com/users/micheleorselli)
- [sebastianstucke87](https://api.github.com/users/sebastianstucke87)
- [ricfio](https://api.github.com/users/ricfio)
- [szepeviktor](https://api.github.com/users/szepeviktor)
- [JulienRAVIA](https://api.github.com/users/JulienRAVIA)
- [annervisser](https://api.github.com/users/annervisser)
- [helyakin](https://api.github.com/users/helyakin)
- [ben-challis](https://api.github.com/users/ben-challis)
- [LuigiCardamone](https://api.github.com/users/LuigiCardamone)
- [annervisser](https://api.github.com/users/annervisser)
- [simivar](https://api.github.com/users/simivar)
- [stephpy](https://api.github.com/users/stephpy)
- [jdomenechbLendable](https://api.github.com/users/jdomenechbLendable)
- [dbu](https://api.github.com/users/dbu)
- [stephpy](https://api.github.com/users/stephpy)
- [marmichalski](https://api.github.com/users/marmichalski)
- [hgraca](https://api.github.com/users/hgraca)
- [frankverhoeven](https://api.github.com/users/frankverhoeven)
- [hectorespert](https://api.github.com/users/hectorespert)
- [kapersoft](https://api.github.com/users/kapersoft)
- [jerowork](https://api.github.com/users/jerowork)
- [jkrzefski](https://api.github.com/users/jkrzefski)
- [mloru](https://api.github.com/users/mloru)
- [nikow13](https://api.github.com/users/nikow13)
- [OskarStark](https://api.github.com/users/OskarStark)
- [smortexa](https://api.github.com/users/smortexa)
- [DonCallisto](https://api.github.com/users/DonCallisto)
- [notcgi](https://api.github.com/users/notcgi)
74 changes: 48 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Currently, you can check if a class:
### Depends on a namespace

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Domain'))
->should(new DependsOnlyOnTheseNamespaces('App\Domain', 'Ramsey\Uuid'))
->because('we want to protect our domain from external dependencies except for Ramsey\Uuid');
Expand All @@ -164,7 +164,7 @@ $rules = Rule::allClasses()
### Doc block contains a string

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Domain\Events'))
->should(new ContainDocBlockLike('@psalm-immutable'))
->because('we want to enforce immutability');
Expand All @@ -173,7 +173,7 @@ $rules = Rule::allClasses()
### Doc block not contains a string

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Controller'))
->should(new NotContainDocBlockLike('@psalm-immutable'))
->because('we don\'t want to enforce immutability');
Expand All @@ -182,16 +182,18 @@ $rules = Rule::allClasses()
### Extend another class

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Controller'))
->should(new Extend('App\Controller\AbstractController'))
->because('we want to be sure that all controllers extend AbstractController');

You can add multiple parameters, the violation will happen when none of them match
```

### Has an attribute (requires PHP >= 8.0)

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Controller'))
->should(new HaveAttribute('AsController'))
->because('it configures the service container');
Expand All @@ -200,7 +202,7 @@ $rules = Rule::allClasses()
### Have a name matching a pattern

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Service'))
->should(new HaveNameMatching('*Service'))
->because('we want uniform naming for services');
Expand All @@ -209,7 +211,7 @@ $rules = Rule::allClasses()
### Implements an interface

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Controller'))
->should(new Implement('ContainerAwareInterface'))
->because('all controllers should be container aware');
Expand All @@ -218,7 +220,7 @@ $rules = Rule::allClasses()
### Not implements an interface

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Infrastructure\RestApi\Public'))
->should(new NotImplement('ContainerAwareInterface'))
->because('all public controllers should not be container aware');
Expand All @@ -227,7 +229,7 @@ $rules = Rule::allClasses()
### Is abstract

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Customer\Service'))
->should(new IsAbstract())
->because('we want to be sure that classes are abstract in a specific namespace');
Expand All @@ -236,7 +238,7 @@ $rules = Rule::allClasses()
### Is trait

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Customer\Service\Traits'))
->should(new IsTrait())
->because('we want to be sure that there are only traits in a specific namespace');
Expand All @@ -245,16 +247,25 @@ $rules = Rule::allClasses()
### Is final

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Domain\Aggregates'))
->should(new IsFinal())
->because('we want to be sure that aggregates are final classes');
```

### Is readonly

```php
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Domain\ValueObjects'))
->should(new IsReadonly())
->because('we want to be sure that value objects are readonly classes');
```

### Is interface

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Interfaces'))
->should(new IsInterface())
->because('we want to be sure that all interfaces are in one directory');
Expand All @@ -263,7 +274,7 @@ $rules = Rule::allClasses()
### Is enum

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Enum'))
->should(new IsEnum())
->because('we want to be sure that all classes are enum');
Expand All @@ -272,7 +283,7 @@ $rules = Rule::allClasses()
### Is not abstract

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Domain'))
->should(new IsNotAbstract())
->because('we want to avoid abstract classes into our domain');
Expand All @@ -281,7 +292,7 @@ $rules = Rule::allClasses()
### Is not trait

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Domain'))
->should(new IsNotTrait())
->because('we want to avoid traits in our codebase');
Expand All @@ -290,16 +301,25 @@ $rules = Rule::allClasses()
### Is not final

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Infrastructure\Doctrine'))
->should(new IsNotFinal())
->because('we want to be sure that our adapters are not final classes');
```

### Is not readonly

```php
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Domain\Entity'))
->should(new IsNotReadonly())
->because('we want to be sure that there are no readonly entities');
```

### Is not interface

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('Tests\Integration'))
->should(new IsNotInterface())
->because('we want to be sure that we do not have interfaces in tests');
Expand All @@ -308,7 +328,7 @@ $rules = Rule::allClasses()
### Is not enum

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Controller'))
->should(new IsNotEnum())
->because('we want to be sure that all classes are not enum');
Expand All @@ -317,7 +337,7 @@ $rules = Rule::allClasses()
### Not depends on a namespace

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Application'))
->should(new NotDependsOnTheseNamespaces('App\Infrastructure'))
->because('we want to avoid coupling between application layer and infrastructure layer');
Expand All @@ -326,25 +346,27 @@ $rules = Rule::allClasses()
### Not extend another class

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Controller\Admin'))
->should(new NotExtend('App\Controller\AbstractController'))
->because('we want to be sure that all admin controllers not extend AbstractController for security reasons');

You can add multiple parameters, the violation will happen when one of them match
```

### Don't have dependency outside a namespace

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Domain'))
->should(new NotHaveDependencyOutsideNamespace('App\Domain', ['Ramsey\Uuid']))
->should(new NotHaveDependencyOutsideNamespace('App\Domain', ['Ramsey\Uuid'], true))
->because('we want protect our domain except for Ramsey\Uuid');
```

### Not have a name matching a pattern

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App'))
->should(new NotHaveNameMatching('*Manager'))
->because('*Manager is too vague in naming classes');
Expand All @@ -353,7 +375,7 @@ $rules = Rule::allClasses()
### Reside in a namespace

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new HaveNameMatching('*Handler'))
->should(new ResideInOneOfTheseNamespaces('App\Application'))
->because('we want to be sure that all CommandHandlers are in a specific namespace');
Expand All @@ -363,9 +385,9 @@ $rules = Rule::allClasses()
### Not reside in a namespace

```php
$rules = Rule::allClasses()
$rules[] = Rule::allClasses()
->that(new Extend('App\Domain\Event'))
->should(new NotResideInOneOfTheseNamespaces('App\Application', 'App\Infrastructure'))
->should(new NotResideInTheseNamespaces('App\Application', 'App\Infrastructure'))
->because('we want to be sure that all events not reside in wrong layers');
```

Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Enforce architectural constraints in your PHP applications",
"type": "library",
"license": "MIT",
"version": "0.3.25",
"version": "0.3.33",
"authors": [
{
"name": "Pietro Campagnano",
Expand All @@ -24,9 +24,9 @@
],
"require": {
"php": "^7.1|^8",
"symfony/finder": "^3.0|^4.0|^5.0|^6.0",
"symfony/event-dispatcher": "^3.0|^4.0|^5.0|^6.0",
"symfony/console": "^3.0|^4.0|^5.0|^6.0",
"symfony/finder": "^3.0|^4.0|^5.0|^6.0|^7.0",
"symfony/event-dispatcher": "^3.0|^4.0|^5.0|^6.0|^7.0",
"symfony/console": "^3.0|^4.0|^5.0|^6.0|^7.0",
"symfony/polyfill-php80": "^1.20",
"nikic/php-parser": "~4",
"webmozart/assert": "^1.9",
Expand All @@ -36,7 +36,7 @@
},
"require-dev": {
"roave/security-advisories": "dev-master",
"symfony/var-dumper": "^3.0|^4.0|^5.0|^6.0",
"symfony/var-dumper": "^3.0|^4.0|^5.0|^6.0|^7.0",
"vimeo/psalm": "^4.6",
"friendsofphp/php-cs-fixer": "^3.0",
"phpunit/phpunit": "^7.5|^9.0|^10.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Analyzer/ClassDependency.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ClassDependency
/** @var int */
private $line;

/** @var \Arkitect\Analyzer\FullyQualifiedClassName */
/** @var FullyQualifiedClassName */
private $FQCN;

public function __construct(string $FQCN, int $line)
Expand Down
Loading

0 comments on commit 8bb8a1f

Please sign in to comment.