PHPackages                             hgraca/phparkitect - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hgraca/phparkitect

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hgraca/phparkitect
==================

Enforce architectural constraints in your PHP applications

1.0.0(11mo ago)02MITPHPPHP ^7.4|^8CI failing

Since Jul 29Pushed 10mo agoCompare

[ Source](https://github.com/hgraca/arkitect)[ Packagist](https://packagist.org/packages/hgraca/phparkitect)[ GitHub Sponsors](https://github.com/AlessandroMinoccheri)[ GitHub Sponsors](https://github.com/micheleorselli)[ RSS](/packages/hgraca-phparkitect/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (15)Versions (22)Used By (0)

📐 PHPArkitect
=============

[](#-phparkitect)

[![Latest Stable Version](https://camo.githubusercontent.com/f8c42f1137854ae137cb862049f584674e754db47fca0c571da921cd1e69859a/68747470733a2f2f706f7365722e707567782e6f72672f70687061726b69746563742f70687061726b69746563742f762f737461626c65)](https://packagist.org/packages/phparkitect/phparkitect) [![PHPArkitect](https://github.com/phparkitect/arkitect/workflows/Arkitect/badge.svg?branch=master)](https://github.com/phparkitect/arkitect/workflows/Arkitect/badge.svg?branch=master)[![Packagist](https://camo.githubusercontent.com/d6dae0170ef1857b87a36450709bd6a00e5311a1919c58c2fc8444f6c0bbd6e0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70687061726b69746563742f70687061726b69746563742e737667)](https://packagist.org/packages/phparkitect/phparkitect)[![codecov](https://camo.githubusercontent.com/021d7a380d501dad159354fa836b2dbba52ddf187438ff8d17beb0c9508b3af3/68747470733a2f2f636f6465636f762e696f2f67682f70687061726b69746563742f61726b69746563742f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/phparkitect/arkitect)

CREDITS
=======

[](#credits)

> This project is a clone of [phparkitect/arkitect](https://github.com/phparkitect/arkitect), with some extra features on top of it.
>
> We decided to make a fork because our PRs were becoming stale, which means that either the original project is not maintained or they do not wish to go in the direction we need the project to go.
>
> In any case, the initial work is commendable and very appreciated.
>
> As much as possible, this project will comply to upstream, this is just a way to get the features I need, quickly incorporated.
>
> I will periodically rebase on the original project (upstream), and also periodically open PRs onto upstream, to incorporate the features I build.
>
> This means the **history on master will change**. The tags will be stable, though.
>
> This project uses semantic versioning, but completely independent of the upstream versioning.

Index
=====

[](#index)

1. [Introduction](#introduction)
2. [Installation](#installation)
3. [Usage](#usage)
4. [Available rules](#available-rules)
5. [Rule Builders](#rule-builders)
6. [Integrations](#integrations)

Introduction
============

[](#introduction)

PHPArkitect helps you to keep your PHP codebase coherent and solid, by permitting to add some architectural constraint check to your workflow. You can express the constraint that you want to enforce, in simple and readable PHP code, for example:

```
Rule::allClasses()
    ->that(new ResideInOneOfTheseNamespaces('App\Controller'))
    ->should(new HaveNameMatching('*Controller'))
    ->because('it\'s a symfony naming convention');
```

This project is a clone of [phparkitect/arkitect](https://github.com/phparkitect/arkitect), with some extra features on top of it.

As much as possible, this project will comply to upstream, this is just a way to get the features I need, quickly incorporated.

I will periodically rebase on the original project (upstream), and also periodically open PRs, to incorporate the features I build, onto upstream. This means the **history on master will change**. The tags will be stable though.

This project uses semantic versioning, but completely independent of the upstream versioning.

Installation
============

[](#installation)

Using Composer
--------------

[](#using-composer)

```
composer require --dev hgraca/phparkitect
```

Using a Phar
------------

[](#using-a-phar)

Sometimes your project can conflict with one or more of PHPArkitect's dependencies. In that case you may find the Phar (a self-contained PHP executable) useful.

The Phar can be downloaded from GitHub:

```
wget https://github.com/hgraca/arkitect/releases/latest/download/phparkitect.phar
chmod +x phparkitect.phar
./phparkitect.phar check

```

When you run phparkitect as phar and you have custom rules in need of autoloading the project classes you'll need to specify the option `--autoload=[AUTOLOAD_FILE]`.

Usage
=====

[](#usage)

To use this tool you need to launch a command via Bash:

```
phparkitect check

```

With this command `phparkitect` will search all rules in the root of your project the default config file called `phparkitect.php`. You can also specify your configuration file using `--config` option like this:

```
phparkitect check --config=/project/yourConfigFile.php

```

By default, a progress bar will show the status of the ongoing analysis.

### Using a baseline file

[](#using-a-baseline-file)

If there are a lot of violations in your codebase and you can't fix them now, you can use the baseline feature to instruct the tool to ignore past violations.

To create a baseline file, run the `check` command with the `generate-baseline` parameter as follows:

```
phparkitect check --generate-baseline

```

This will create a `phparkitect-baseline.json`, if you want a different file name you can do it with:

```
phparkitect check --generate-baseline=my-baseline.json

```

It will produce a json file with the current list of violations.

If is present a baseline file with the default name will be used automatically.

To use a different baseline file, run the `check` command with the `use-baseline` parameter as follows:

```
phparkitect check --use-baseline=my-baseline.json

```

To avoid using the default baseline file, you can use the `skip-baseline` option:

```
phparkitect check --skip-baseline

```

### Line numbers in baseline

[](#line-numbers-in-baseline)

By default, the baseline check also looks at line numbers of known violations. When a line before the offending line changes, the line numbers change and the check fails despite the baseline.

With the optional flag `ignore-baseline-linenumbers`, you can ignore the line numbers of violations:

```
phparkitect check --ignore-baseline-linenumbers

```

*Warning*: When ignoring line numbers, phparkitect can no longer discover if a rule is violated additional times in the same file.

Output format
-------------

[](#output-format)

Output format can be controlled using the parameter `format=[FORMAT]`. There are two available output formats

- `text`: the default one
- `json`: this format allows custom report using github action or another platform as Sonarqube and so on... Note that this will suppress any output apart from the violation reporting.
- `gitlab`: this follows Gitlab's [code quality format](https://docs.gitlab.com/ci/testing/code_quality/#code-quality-report-format). Note that this will suppress any output apart from the violation reporting.

Configuration
-------------

[](#configuration)

Example of configuration file `phparkitect.php`

```
