Skip to content

Commit ef7afdd

Browse files
committed
ci: add deptrac support
1 parent 3c1be89 commit ef7afdd

File tree

11 files changed

+219
-55
lines changed

11 files changed

+219
-55
lines changed

.github/assets/deptrac.svg

Lines changed: 70 additions & 0 deletions
Loading

.github/workflows/dependency-analysis.yml

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ jobs:
3636
- '8.3'
3737
dependencies:
3838
- locked
39-
4039
steps:
4140
- name: 📦 Check out the codebase
4241
uses: actions/[email protected]
@@ -84,3 +83,66 @@ jobs:
8483
- name: 🔬 Run maglnet/composer-require-checker
8584
working-directory: app
8685
run: .phive/composer-require-checker check --ansi --config-file="$(pwd)/composer-require-checker.json" --verbose
86+
87+
deptrac:
88+
timeout-minutes: 4
89+
runs-on: ${{ matrix.os }}
90+
concurrency:
91+
cancel-in-progress: true
92+
group: deptrac-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
93+
strategy:
94+
fail-fast: true
95+
matrix:
96+
os:
97+
- ubuntu-latest
98+
php-version:
99+
- '8.3'
100+
dependencies:
101+
- locked
102+
steps:
103+
- name: 📦 Check out the codebase
104+
uses: actions/[email protected]
105+
106+
- name: 🛠️ Setup PHP
107+
uses: shivammathur/[email protected]
108+
with:
109+
php-version: ${{ matrix.php-version }}
110+
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql
111+
ini-values: error_reporting=E_ALL
112+
coverage: none
113+
tools: phive
114+
115+
- name: 🛠️ Setup problem matchers
116+
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
117+
118+
- name: 🤖 Validate composer.json and composer.lock
119+
run: make validate-composer
120+
121+
- name: 🔍 Get composer cache directory
122+
uses: wayofdev/gh-actions/actions/composer/[email protected]
123+
with:
124+
working-directory: app
125+
126+
- name: ♻️ Restore cached dependencies installed with composer
127+
uses: actions/[email protected]
128+
with:
129+
path: ${{ env.COMPOSER_CACHE_DIR }}
130+
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
131+
restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-
132+
133+
- name: 📥 Install "${{ matrix.dependencies }}" dependencies with composer
134+
uses: wayofdev/gh-actions/actions/composer/[email protected]
135+
with:
136+
working-directory: app
137+
dependencies: ${{ matrix.dependencies }}
138+
139+
- name: 📥 Install dependencies with phive
140+
working-directory: app
141+
env:
142+
PHIVE_HOME: .phive
143+
run: phive install --trust-gpg-keys 0xC00543248C87FB13,0x033E5F8D801A2F8D,0x47436587D82C4A39
144+
shell: bash
145+
146+
- name: 🔬 Run deptrac
147+
working-directory: app
148+
run: make lint-deptrac-ci

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,15 @@ lint-deps: ## Runs composer-require-checker – checks for dependencies that are
274274
.PHONY: lint-deps
275275

276276
lint-deptrac: ## Runs deptrac – static analysis tool
277-
$(APP_RUNNER) .phive/deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache
277+
$(APP_RUNNER) .phive/deptrac analyse --config-file=deptrac.yaml -vvv --cache-file=.build/.deptrac.cache
278278
.PHONY: lint-deptrac
279279

280280
lint-deptrac-ci: ## Runs deptrac – static analysis tool with github output (CI mode)
281281
$(APP_RUNNER) .phive/deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache --formatter github-actions
282282
.PHONY: lint-deptrac-ci
283283

284284
lint-deptrac-gv: ## Runs deptrac – static analysis tool and generates graphviz image
285-
$(APP_RUNNER) .phive/deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache --formatter graphviz-image --output ../.github/assets/deptrac.svg
285+
$(APP_RUNNER) .phive/deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache --formatter graphviz-image --output /assets/deptrac.svg
286286
.PHONY: lint-deptrac-gv
287287

288288
lint-composer: ## Normalize composer.json and composer.lock files
@@ -297,6 +297,14 @@ validate-composer: ## Validates composer.json and composer.lock files
297297
$(APP_COMPOSER) validate --ansi --strict
298298
.PHONY: validate-composer
299299

300+
refactor: ## Runs rector – code refactoring tool
301+
$(APP_COMPOSER) refactor
302+
.PHONY: refactor
303+
304+
refactor-ci: ## Runs rector – code refactoring tool with github output (CI mode)
305+
$(APP_COMPOSER) refactor:ci
306+
.PHONY: refactor-ci
307+
300308
#
301309
# Testing
302310
# ------------------------------------------------------------------------------------

app/deptrac.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
3+
deptrac:
4+
paths:
5+
- ./src/
6+
- ./database/factories
7+
- ./database/seeders
8+
- ./tests/
9+
10+
exclude_files:
11+
- '#.*test.*#'
12+
13+
layers:
14+
- name: Domain
15+
collectors:
16+
- type: directory
17+
value: src/Domain/.*
18+
19+
- name: Bridge
20+
collectors:
21+
- type: directory
22+
value: src/Bridge/.*
23+
24+
- name: Support
25+
collectors:
26+
- type: directory
27+
value: src/Support/.*
28+
29+
- name: DatabaseSeeders
30+
collectors:
31+
- type: directory
32+
value: database/seeders/.*
33+
34+
- name: DatabaseFactories
35+
collectors:
36+
- type: directory
37+
value: database/factories/.*
38+
39+
- name: Tests
40+
collectors:
41+
- type: directory
42+
value: tests/src/.*
43+
44+
ruleset:
45+
Domain: ~
46+
Bridge:
47+
- Domain
48+
- Support
49+
Support:
50+
- Domain
51+
DatabaseSeeders:
52+
- DatabaseFactories
53+
- Domain
54+
DatabaseFactories:
55+
- Domain
56+
Tests:
57+
- Domain
58+
- Bridge
59+
- Support
60+
- DatabaseSeeders
61+
- DatabaseFactories

app/psalm-baseline.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,9 @@
178178
<code><![CDATA[UserController]]></code>
179179
</UnusedClass>
180180
</file>
181-
<file src="src/Domain/Category/Models/Category.php">
182-
<PossiblyUnusedMethod>
183-
<code><![CDATA[resolveFactoryName]]></code>
184-
</PossiblyUnusedMethod>
185-
</file>
186181
<file src="src/Domain/Product/Models/Product.php">
187182
<PossiblyUnusedMethod>
188183
<code><![CDATA[category]]></code>
189-
<code><![CDATA[resolveFactoryName]]></code>
190184
</PossiblyUnusedMethod>
191185
</file>
192186
<file src="src/Domain/Shared/StringEnum.php">
@@ -201,9 +195,6 @@
201195
<code><![CDATA[$casts]]></code>
202196
<code><![CDATA[$hidden]]></code>
203197
</NonInvariantDocblockPropertyType>
204-
<PossiblyUnusedMethod>
205-
<code><![CDATA[resolveFactoryName]]></code>
206-
</PossiblyUnusedMethod>
207198
</file>
208199
<file src="src/Support/Filters/FuzzyFilter.php">
209200
<MixedAssignment>
@@ -237,6 +228,15 @@
237228
<MixedOperand>
238229
<code><![CDATA[$category->uuid]]></code>
239230
</MixedOperand>
231+
<PossiblyUnusedMethod>
232+
<code><![CDATA[it_gets_list_of_categories]]></code>
233+
<code><![CDATA[it_gets_single_category]]></code>
234+
</PossiblyUnusedMethod>
235+
</file>
236+
<file src="tests/src/Functional/Bridge/Laravel/ExampleTest.php">
237+
<PossiblyUnusedMethod>
238+
<code><![CDATA[the_application_returns_a_successful_response]]></code>
239+
</PossiblyUnusedMethod>
240240
</file>
241241
<file src="tests/src/Functional/CreatesApplication.php">
242242
<MixedAssignment>

app/src/Domain/Category/Models/Category.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,4 @@
1010

1111
final class Category extends Model
1212
{
13-
use HasFactory;
14-
15-
public static function resolveFactoryName(): string
16-
{
17-
return CategoryFactory::class;
18-
}
19-
20-
protected static function newFactory(): CategoryFactory
21-
{
22-
return CategoryFactory::new();
23-
}
2413
}

app/src/Domain/Product/Models/Product.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@
1212

1313
final class Product extends Model
1414
{
15-
use HasFactory;
16-
17-
public static function resolveFactoryName(): string
18-
{
19-
return ProductFactory::class;
20-
}
21-
22-
protected static function newFactory(): ProductFactory
23-
{
24-
return ProductFactory::new();
25-
}
26-
2715
public function category(): BelongsTo
2816
{
2917
return $this->belongsTo(Category::class);

app/src/Domain/User/Models/User.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
final class User extends Authenticatable
1313
{
14-
use HasFactory;
1514
use Notifiable;
1615

1716
/**
@@ -43,14 +42,4 @@ final class User extends Authenticatable
4342
protected $casts = [
4443
'email_verified_at' => 'datetime',
4544
];
46-
47-
public static function resolveFactoryName(): string
48-
{
49-
return UserFactory::class;
50-
}
51-
52-
protected static function newFactory(): UserFactory
53-
{
54-
return UserFactory::new();
55-
}
5645
}

app/tests/src/Functional/Bridge/Laravel/Admin/Category/Controllers/CategoryControllerTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66

77
use Domain\Category\Models\Category;
88
use Illuminate\Testing\Fluent\AssertableJson;
9+
use PHPUnit\Framework\Attributes\Test;
910
use Tests\Functional\TestCase;
1011

1112
final class CategoryControllerTest extends TestCase
1213
{
1314
private const string API_BASE_PATH = '/api/admin/categories';
1415

15-
/**
16-
* @test
17-
*/
16+
#[Test]
1817
public function it_gets_list_of_categories(): void
1918
{
2019
$category = Category::findOrFail(1);
@@ -48,9 +47,7 @@ public function it_gets_list_of_categories(): void
4847
);
4948
}
5049

51-
/**
52-
* @test
53-
*/
50+
#[Test]
5451
public function it_gets_single_category(): void
5552
{
5653
$category = Category::findOrFail(1);

app/tests/src/Functional/Bridge/Laravel/ExampleTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44

55
namespace Tests\Functional\Bridge\Laravel;
66

7-
// use Illuminate\Foundation\Testing\RefreshDatabase;
7+
use PHPUnit\Framework\Attributes\Test;
88
use Tests\Functional\TestCase;
99

1010
class ExampleTest extends TestCase
1111
{
1212
/**
1313
* A basic test example.
14-
*
15-
* @test
1614
*/
15+
#[Test]
1716
public function the_application_returns_a_successful_response(): void
1817
{
1918
$response = $this->get('/');

0 commit comments

Comments
 (0)