Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.

Commit bf62c0c

Browse files
committed
Refactoring to v2
1 parent 7ceb554 commit bf62c0c

17 files changed

+720
-320
lines changed

.gitattributes

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.gitattributes export-ignore
22
.gitignore export-ignore
3-
phpstan.neon export-ignore
4-
.travis.yml export-ignore
3+
.github export-ignore
54
tests export-ignore
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Code Analysis
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
code_analysis:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
actions:
15+
- name: PHPStan
16+
run: composer phpstan
17+
18+
- name: Easy Coding Standard
19+
run: composer ecs
20+
21+
- name: Unit tests
22+
run: composer tests
23+
24+
name: ${{ matrix.actions.name }}
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v2
30+
31+
- name: Setup PHP
32+
# see https://github.com/shivammathur/setup-php
33+
uses: shivammathur/setup-php@v2
34+
with:
35+
php-version: 7.3
36+
coverage: none
37+
38+
- name: Install Composer
39+
run: composer install --no-progress
40+
41+
- run: ${{ matrix.actions.run }}

.phpstorm.meta.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace PHPSTORM_META {
4+
5+
expectedArguments(
6+
\JakubBoucek\ComposerConsistency\ComposerConsistency::__construct(),
7+
5,
8+
true,
9+
false,
10+
E_USER_ERROR,
11+
E_USER_WARNING,
12+
E_USER_NOTICE,
13+
);
14+
15+
expectedArguments(
16+
\JakubBoucek\ComposerConsistency\Builder::errorMode(),
17+
0,
18+
E_USER_ERROR,
19+
E_USER_WARNING,
20+
E_USER_NOTICE,
21+
);
22+
}

.travis.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 73 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,76 +7,112 @@ Package for your app – it allows your App to check himself has consistent vend
77
For small teams can be difficult to cooperate and keep `/vendor` directory synchronized with requirements
88
in `composer.json`. Your colleagues can be a junior or can be not accustomed to right use the Composer.
99

10-
You can force refresh Composer via git-hooks, or push all `/vendor` into your repo, but it's very dirty way.
11-
Don't do it!
10+
You can force refresh Composer via git-hooks, but it requires careful preparation on each developer station.
11+
You can push all `/vendor` into your repo, but it's very very dirty way. Don't do it!
1212

1313
Or… just add this package to you project. It checks if you `/vendor` is consistent with project and can
1414
notify you and your colleagues to forgotten refresh.
1515

1616
## Usage
1717
Add this package to project as dev-dependency:
18-
```bash
19-
composer require --dev jakubboucek/composer-vendor-checker
18+
```shell
19+
composer require --dev jakubboucek/composer-consistency-checker
2020
```
2121

22-
In your app just call `validateReqs()` method:
22+
In your app just call `validate()` method:
2323
```php
2424
<?php
25-
use JakubBoucek\ComposerConsistency\Checker;
25+
use JakubBoucek\ComposerConsistency\ComposerConsistency;
2626

27-
Checker::validateReqs(__DIR__);
27+
ComposerConsistency::rootDir(__DIR__)->validate();
2828
```
2929

3030
When `/vendor` is not consistent with `composer.json`, checker throws an Exception.
3131

3232
![Exception from Checker](https://cdn.jakub-boucek.cz/screenshot/190703-jptvw.png)
3333

34-
## Modes
34+
## Usage
35+
36+
```php
37+
use JakubBoucek\ComposerConsistency\ComposerConsistency;
38+
39+
\JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
40+
->validate();
41+
```
42+
43+
### Directories
44+
- **Root dir** - directory which contains `composer.json`, rspt. `composer.lock` file,
45+
usually root directory od project.
46+
- **Vendor dir** - directory which contains Composer's `autoload.php` file.
47+
48+
By default checker is assumes Verdor dir at `vendor/` from root dir, you can change by method `vendorDir()`.
3549

36-
### Strict/Lax mode
37-
Nehlásí chybu, pokud nenajde soubory
50+
```php
51+
\JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
52+
->vendorDir(__DIR__ . '/../vendor')
53+
->validate();
54+
```
3855

39-
POPZOR? výchozéí stan není striktní - vysvětlit v readme
56+
### Error severity
57+
When checker detects incosistence, it throws `ComposerInconsitencyException`.
4058

41-
### Silent mode
42-
Vyhodí pouze chybu E_USER_ERROR, ne vyjímku
59+
You can change exception throwing to emit user error by method `errorMode($severity)` where `$severity` is Severity of
60+
emitted error, default is `E_USER_ERROR`, you can change it to any of `E_USER` family severity
61+
([read more](https://www.php.net/manual/en/function.trigger-error.php#refsect1-function.trigger-error-parameters)).
4362

4463
```php
45-
Composer::validateConsistency($rootDir, $vendorDir, true, false);
46-
(new Composer($rootDir))->strict(false)->validate($debugMode, E_USER_ERROR);
64+
\JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
65+
->errorMode(E_USER_WARNING)
66+
->validate();
4767
```
4868

49-
### Warning
50-
Because you install Checker as dev-dependency, you should be very careful to hard-linking dependency
51-
insinde your App. Is highly recommended to call validation only on development stage, not on production:
69+
Also you can disable checking by `errorMode(false)` – that's cause to completelly disable checking.
5270

5371
```php
54-
if(Debugger::$productionMode === false) {
55-
Checker::validateReqs(__DIR__);
56-
}
72+
\JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
73+
->errorMode(false)
74+
->validate();
5775
```
5876

59-
Or check if dependency exists:
77+
### Strict mode
78+
In strict mode Checker throws Exception when is unable to read Composer's files used to
79+
compute vendor consistency. Default value: `off`.
80+
81+
Turn on Strict mode:
6082
```php
61-
if(class_exists(Checker::class)) {
62-
Checker::validateReqs(__DIR__);
63-
}
83+
\JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
84+
->strict()
85+
->validate();
6486
```
6587

66-
## Reference
88+
Scrict mode is by default disabled, because:
89+
- it can break production if you ignore some files (like `composer.lock`) during deploy -
90+
that's false positive,
91+
- is not important to guard these files, for example when is missing whole `vendor/` directory,
92+
is unable to load this package too,
93+
- main purpose of package is watching to subtle nuances in packages consistency, not fatals
94+
in Composer's file system.
6795

68-
### Class `Checker`
96+
### Cache
97+
Checking vendor consistency on every request consume unnecessarily huge CPU power. Ceche is store last success check
98+
only check is composer files stay without change. It does not check consincy of packages until these files keep same
99+
content. Default value: off.
69100

70-
#### `__constructor($rootDir, ?string $vendorDir = null)`
71-
Contructor creates Checker instance.\
72-
Only required argument is absolute path to root directory (directory where checker search the `composer.lock` file).\
73-
Optional argument is absolute path do `vendor` directory. Default is `{$rootDir}/vendor`.
101+
```php
102+
\JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
103+
->cache(__DIR__ . '/temp')
104+
->validate();
105+
```
74106

75-
#### `validate(): void`
76-
Check if `/vendor` is consitent with app requirements and throw an Exception if is not.
107+
### Froze mode
108+
Checking vendor consistency on every request consume unnecessarily huge CPU power. Froze mode is usable when you
109+
guarantee the deploy process to production is always purge the temp directory. Default value: off.
77110

78-
#### `isReqsValid(): bool`
79-
Check if `/vendor` is consitent with app requirements and return boolean of consistency status.
111+
```php
112+
\JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
113+
->froze(__DIR__ . '/temp')
114+
->validate();
115+
```
80116

81-
#### `validateReqs(string $rootDir, ?string $vendorDir = null): void`
82-
Shortcut to call `validate()` without creating Checker instance before.
117+
In Froze mode is vendor consistenty checked only once, then is state saved to temp directory and
118+
no more checks are performed until is temp directory purged.

composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@
1919
}
2020
},
2121
"require-dev": {
22-
"phpstan/phpstan": "^0.12.10",
23-
"nette/tester": "^2.3"
22+
"phpstan/phpstan": "^0.12.48",
23+
"nette/tester": "^2.3",
24+
"symplify/easy-coding-standard": "^8.3"
25+
},
26+
"scripts": {
27+
"phpstan": "phpstan analyze src --level 6",
28+
"ecs": "ecs check src --set psr12",
29+
"ecs-fix": "ecs check src --set psr12 --fix",
30+
"tests": "tester tests"
2431
},
2532
"replace": {
2633
"jakubboucek/composer-vendor-checker": "self.version"

examples.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
## Usage
2+
3+
```php
4+
use JakubBoucek\ComposerConsistency\ComposerConsistency;
5+
6+
\JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
7+
->validate();
8+
```
9+
10+
### Directories
11+
- **Root dir** - directory which contains `composer.json`, rspt. `composer.lock` file,
12+
usually root directory od project.
13+
- **Vendor dir** - directory which contains Composer's `autoload.php` file.
14+
15+
By default checker is assumes Verdor dir at `vendor/` from root dir, you can change by method `vendorDir()`.
16+
17+
```php
18+
\JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
19+
->vendorDir(__DIR__ . '/../vendor')
20+
->validate();
21+
```
22+
23+
### Error severity
24+
When checker detects incosistence, it throws `ComposerInconsitencyException`.
25+
26+
You can change exception throwing to emit user error by method `errorMode($severity)` where `$severity` is Severity of
27+
emitted error, default is `E_USER_ERROR`, you can change it to any of `E_USER` family severity
28+
([read more](https://www.php.net/manual/en/function.trigger-error.php#refsect1-function.trigger-error-parameters)).
29+
30+
```php
31+
\JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
32+
->errorMode(E_USER_WARNING)
33+
->validate();
34+
```
35+
36+
Also you can disable checking by `errorMode(false)` – that's cause to completelly disable checking.
37+
38+
```php
39+
\JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
40+
->errorMode(false)
41+
->validate();
42+
```
43+
44+
### Strict mode
45+
In strict mode Checker throws Exception when is unable to read Composer's files used to
46+
compute vendor consistency. Default value: `off`.
47+
48+
Turn on Strict mode:
49+
```php
50+
\JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
51+
->strict()
52+
->validate();
53+
```
54+
55+
Scrict mode is by default disabled, because:
56+
- it can break production if you ignore some files (like `composer.lock`) during deploy -
57+
that's false positive,
58+
- is not important to guard these files, for example when is missing whole `vendor/` directory,
59+
is unable to load this package too,
60+
- main purpose of package is watching to subtle nuances in packages consistency, not fatals
61+
in Composer's file system.
62+
63+
### Cache
64+
Checking vendor consistency on every request consume unnecessarily huge CPU power. Ceche is store last success check
65+
only check is composer files stay without change. It does not check consincy of packages until these files keep same
66+
content. Default value: off.
67+
68+
```php
69+
\JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
70+
->cache(__DIR__ . '/temp')
71+
->validate();
72+
```
73+
74+
### Froze mode
75+
Checking vendor consistency on every request consume unnecessarily huge CPU power. Froze mode is usable when you
76+
guarantee the deploy process to production is always purge the temp directory. Default value: off.
77+
78+
```php
79+
\JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
80+
->froze(__DIR__ . '/temp')
81+
->validate();
82+
```
83+
84+
In Froze mode is vendor consistenty checked only once, then is state saved to temp directory and
85+
no more checks are performed until is temp directory purged.

loader.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

phpstan.neon

Whitespace-only changes.

0 commit comments

Comments
 (0)