Skip to content

Commit 215592a

Browse files
mnoconadriendupuis
andauthored
[Composer] Added one command to run them all (checks) (#3271)
* [Composer] Added one command to run them all (checks) * Added YAML check * Added regemerate baseline commands * Added "fix" and "baseline" commands * Run PHP-CS-Fixer on PHP 8.4 * Update composer.json Co-authored-by: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> * Fix syntax error * Fixed CS * Add colors --------- Co-authored-by: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com>
1 parent 9c64fef commit 215592a

4 files changed

Lines changed: 57 additions & 35 deletions

File tree

.github/workflows/code_samples.yaml

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,11 @@ jobs:
4545
with:
4646
dependency-versions: highest
4747

48-
- name: Run PHPStan analysis
48+
- name: Run code sample quality tests
4949
id: phpstan
50-
continue-on-error: true
51-
run: composer phpstan
52-
53-
- name: Run Deptrac analysis
54-
id: deptrac
55-
continue-on-error: true
56-
run: composer deptrac
57-
58-
- name: Run Rector check
59-
id: rector
60-
continue-on-error: true
61-
run: composer check-rector
62-
63-
- name: Run YAML snippet tests
64-
id: check-yaml
65-
continue-on-error: true
66-
run: composer check-yaml
67-
68-
- name: Fail job if any check failed
69-
if: always()
70-
run: |
71-
if [[ "${{ steps.phpstan.outcome }}" == "failure" || "${{ steps.deptrac.outcome }}" == "failure" || "${{ steps.rector.outcome }}" == "failure" || "${{ steps.check-yaml.outcome }}" == "failure" ]]; then
72-
echo "One or more checks failed: PHPStan=${{ steps.phpstan.outcome }}, Deptrac=${{ steps.deptrac.outcome }}, Rector=${{ steps.rector.outcome }}, YAML=${{ steps.check-yaml.outcome }}"
73-
exit 1
74-
fi
50+
run: composer test --ansi
51+
env:
52+
PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.php == '8.4' && '1' || '' }}
7553

7654

7755
code-samples-inclusion-check:

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ composer phpstan
8787
```
8888

8989
Regenerate the baseline by running:
90+
9091
```bash
91-
composer phpstan -- --generate-baseline
92+
composer phpstan-update-baseline
9293
```
9394

9495
#### Skipping validation of inline PHP snippets
@@ -120,8 +121,9 @@ composer deptrac
120121
```
121122

122123
Regenerate the baseline by running:
124+
123125
```bash
124-
vendor/bin/deptrac --formatter=baseline
126+
composer deptrac-update-baseline
125127
```
126128

127129
## Checking links

composer.json

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,35 @@
123123
"check-rector": "php tools/extract-inline-php.php && rector process --dry-run --ansi",
124124
"check-yaml": "phpunit --group yaml",
125125
"phpunit": "phpunit --exclude-group=yaml",
126-
"yaml-update-baseline": "php tests/generate-yaml-baseline.php"
126+
"yaml-update-baseline": "php tests/generate-yaml-baseline.php",
127+
"phpstan-update-baseline": "@phpstan --generate-baseline",
128+
"deptrac-update-baseline": "@deptrac --formatter=baseline",
129+
"composer-update": "[ -d vendor ] || composer update",
130+
"yarn-install": "[ -d node_modules ] || yarn install",
131+
"markdownlint": [
132+
"@yarn-install",
133+
"yarn markdownlint"
134+
],
135+
"fix-markdownlint": [
136+
"@yarn-install",
137+
"yarn markdownlint --fix"
138+
],
139+
"test": [
140+
"@composer-update",
141+
"EXIT=0; FAILED=''; { composer check-cs; } || { EXIT=1; FAILED=\"$FAILED check-cs\"; }; { composer phpstan; } || { EXIT=1; FAILED=\"$FAILED phpstan\"; }; { composer deptrac; } || { EXIT=1; FAILED=\"$FAILED deptrac\"; }; { composer check-rector; } || { EXIT=1; FAILED=\"$FAILED check-rector\"; }; { composer markdownlint; } || { EXIT=1; FAILED=\"$FAILED markdownlint\"; }; { composer check-yaml; } || { EXIT=1; FAILED=\"$FAILED check-yaml\"; }; if [ 1 -eq $EXIT ]; then echo \"Failed:$FAILED\"; fi; exit $EXIT;"
142+
],
143+
"fix": [
144+
"@composer-update",
145+
"@composer fix-rector",
146+
"@composer fix-cs",
147+
"@composer fix-markdownlint"
148+
],
149+
"baseline": [
150+
"@composer-update",
151+
"@composer phpstan-update-baseline",
152+
"@composer deptrac-update-baseline",
153+
"@composer yaml-update-baseline"
154+
]
127155
},
128156
"scripts-descriptions": {
129157
"fix-cs": "Automatically fixes code style in all files",
@@ -133,7 +161,16 @@
133161
"fix-rector": "Automatically applies Rector refactoring to code samples and syncs back to Markdown",
134162
"check-rector": "Check for code refactoring opportunities",
135163
"check-yaml": "Run PHPUnit tests (YAML validation)",
136-
"yaml-update-baseline": "Regenerate tests/yaml-validation-baseline.yaml from current failures"
164+
"yaml-update-baseline": "Regenerate tests/yaml-validation-baseline.yaml from current failures",
165+
"phpstan-update-baseline": "Regenerate PHPStan baseline from current failures",
166+
"deptrac-update-baseline": "Regenerate Deptrac baseline from current failures",
167+
"composer-update": "Install composer dependencies if not already installed",
168+
"yarn-install": "Install yarn dependencies if not already installed",
169+
"markdownlint": "Run Markdownlint on all documentation files",
170+
"fix-markdownlint": "Automatically fixes Markdownlint issues in all documentation files",
171+
"test": "Run all checks (CS-Fixer, PHPStan, Deptrac, Rector, Markdownlint, YAML checks), continuing past failures and reporting failure overall if any check failed",
172+
"fix": "Run all automatic fixes (Rector, CS-Fixer, Markdownlint)",
173+
"baseline": "Regenerate all baselines (PHPStan, Deptrac, YAML) from current failures"
137174
},
138175
"config": {
139176
"allow-plugins": false

docs/templating/twig_function_reference/recommendations_twig_functions.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,30 @@ To resolve `websiteId` on the project level, implement the interface as follows:
108108

109109
``` php
110110
namespace App\Tracking;
111-
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
112-
use Ibexa\Contracts\Core\Repository\PermissionResolver;
111+
113112
use Ibexa\Contracts\ConnectorRaptor\Tracking\ContextProvider\WebsiteIdContextProviderInterface;
113+
use Ibexa\Contracts\Core\Repository\PermissionResolver;
114+
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
115+
114116
final readonly class MyCrmWebsiteUserIdProvider implements WebsiteIdContextProviderInterface
115117
{
116118
public function __construct(
117-
private ConfigResolverInterface $configResolver,
119+
private ConfigResolverInterface $configResolver,
118120
private PermissionResolver $permissionResolver,
119-
)
120-
{
121+
) {
121122
}
123+
122124
public function getWebsiteId(): ?string
123125
{
124126
$currentUserId = $this->permissionResolver->getCurrentUserReference()->getUserId();
125127
// Don't resolve for anynomous user
126128
if ($this->isAnonymousUser($currentUserId)) {
127129
return null;
128130
}
131+
129132
return $this->getWebsiteUserIdForCurrentUser($currentUserId);
130133
}
134+
131135
/**
132136
* @phpstan-return non-empty-string
133137
*/
@@ -136,6 +140,7 @@ final readonly class MyCrmWebsiteUserIdProvider implements WebsiteIdContextProvi
136140
// Implement custom logic resolving user identifier from the CRM
137141
return 'custom-identifier-for-the-user-retrieved-from-the-CRM';
138142
}
143+
139144
private function isAnonymousUser(int $userId): bool
140145
{
141146
return (int) $this->configResolver->getParameter('anonymous_user_id') === $userId;

0 commit comments

Comments
 (0)