Skip to content

Commit bf00463

Browse files
committed
create workflow
1 parent ef79b22 commit bf00463

File tree

15 files changed

+285
-108
lines changed

15 files changed

+285
-108
lines changed

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/tests export-ignore
2-
/config export-ignore
32
/.github export-ignore
43
.gitattributes export-ignore
54
.gitignore export-ignore
65
README.md export-ignore
6+
rector.php export-ignore
7+
phpstan.neon export-ignore

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
ci:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Cache Composer packages
21+
id: composer-cache
22+
uses: actions/cache@v3
23+
with:
24+
path: vendor
25+
key: ${{ runner.os }}-ci-${{ hashFiles('**/composer.json') }}
26+
restore-keys: |
27+
${{ runner.os }}-ci-
28+
29+
- name: Install dependencies
30+
run: composer install --prefer-dist --no-progress
31+
32+
- name: Run ci checks
33+
run: composer ci

README.md

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,17 @@
11
# CodeBuddy
22

3-
## All-in-One Code Quality Tool for Laravel
3+
## All-in-one code quality tool for your codebase
44

5-
> **Note:** This package is currently compatible only with the Laravel framework.
5+
> **Note:** This package is currently compatible only with the Laravel framework 11 & 12.
66
7-
## About
8-
CodeBuddy is a wrapper around essential development tools that help maintain code quality in your Laravel projects. It integrates:
7+
## Installation
98

10-
- **Rector** (automated code refactoring)
11-
- **Pint** (code styling)
12-
- **PHPStan** (static analysis)
13-
- **PestPHP** (testing framework)
14-
15-
## Features
16-
- One command setup for essential tools.
17-
- CI/CD optimized validation.
18-
- Automated fixes for coding standards.
19-
- Code health reporting with email support.
20-
21-
## Commands
22-
23-
### Configure Code Quality Tools
24-
```sh
25-
php artisan codebuddy:configure
269
```
27-
This command sets up **Rector, PestPHP, Pint, and PHPStan** with standard configurations.
28-
29-
### Run CI Checks
30-
```sh
31-
php artisan codebuddy:ci [--fix]
10+
composer require codebuddyphp/codebuddy --dev
3211
```
33-
Runs tests, performs static analysis, and checks code style in a **dry-run mode** (does not modify files). Optimized for CI/CD pipelines.
3412

35-
- `--fix`: Automatically applies fixes for Rector and Pint where possible.
13+
## Commands
3614

37-
### Generate Code Quality Report
38-
```sh
39-
php artisan codebuddy:report [--show|--send-to=<email>]
4015
```
41-
- `--show`: Displays the overall code health report in the console.
42-
- `--send-to=<email>`: Sends the report to the specified email address.
43-
44-
---
45-
46-
This package simplifies code quality enforcement, making it easier to maintain a high standard across your Laravel projects.
16+
php artisan codebuddy:configure
17+
```

composer.json

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
11
{
22
"name": "codebuddyphp/codebuddy",
3-
"description": "All-in-one tool for your codebase",
3+
"description": "All-in-one code quality tool for your codebase",
44
"type": "library",
5+
"license": "MIT",
56
"require": {
67
"php": "^8.2",
7-
"laravel/framework": "^11.0",
8-
"nunomaduro/termwind": "^2.3",
9-
"laravel/pint": "^1.20",
8+
"laravel/framework": "^11|^12",
9+
"laravel/pint": "^1.21",
10+
"driftingly/rector-laravel": "^2.0",
1011
"larastan/larastan": "^3.0",
11-
"rector/rector": "^2.0"
12+
"pestphp/pest": "^3.7"
13+
},
14+
"require-dev": {
1215
},
1316
"autoload": {
1417
"psr-4": {
1518
"Codebuddyphp\\Codebuddy\\": "src/"
1619
}
1720
},
1821
"scripts": {
22+
"lint": "pint --test",
23+
"lint.fix": "pint",
24+
"rector": "rector process --dry-run",
25+
"rector.fix": "rector process",
26+
"ci": [
27+
"@lint",
28+
"@rector"
29+
],
30+
"ci.fix": [
31+
"@rector.fix",
32+
"@lint.fix"
33+
]
1934
},
2035
"extra": {
2136
"laravel": {
@@ -27,7 +42,10 @@
2742
}
2843
},
2944
"config": {
30-
"preferred-install": "dist"
45+
"preferred-install": "dist",
46+
"allow-plugins": {
47+
"pestphp/pest-plugin": true
48+
}
3149
},
3250
"minimum-stability": "dev",
3351
"prefer-stable": true

phpstan.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
includes:
2+
- vendor/larastan/larastan/extension.neon
3+
- vendor/nesbot/carbon/extension.neon
4+
5+
parameters:
6+
7+
paths:
8+
- src/
9+
10+
level: max

rector.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
7+
return RectorConfig::configure()
8+
->withPaths([
9+
__DIR__.'/config',
10+
__DIR__.'/src',
11+
__DIR__.'/tests',
12+
])
13+
->withPhpSets()
14+
->withPreparedSets(
15+
deadCode: true,
16+
codeQuality: true,
17+
typeDeclarations: true,
18+
privatization: true,
19+
earlyReturn: true,
20+
strictBooleans: true,
21+
);

resources/views/banner.blade.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="m-1">
2+
<div class="px-1 bg-sky-600">CodeBuddy</div>
3+
<em class="ml-1 underline">
4+
All-in-one code quality tool for your codebase
5+
</em>
6+
</div>

src/CodebuddyServiceProvider.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,44 @@
22

33
namespace Codebuddyphp\Codebuddy;
44

5-
use Codebuddyphp\Codebuddy\Commands\Configure;
5+
use Codebuddyphp\Codebuddy\Commands\Scan;
6+
use Codebuddyphp\Codebuddy\Commands\Setup;
67
use Illuminate\Support\ServiceProvider;
78

89
class CodebuddyServiceProvider extends ServiceProvider
910
{
10-
public function register()
11+
public function register(): void
1112
{
1213
// Register bindings if any
1314
}
1415

15-
public function boot()
16+
public function boot(): void
1617
{
1718
if ($this->app->runningInConsole()) {
18-
$this->commands([
19-
Configure::class,
20-
]);
19+
20+
$this->commands(
21+
[
22+
Setup::class,
23+
Scan::class,
24+
]
25+
);
2126

2227
$this->publishes([
2328
__DIR__.'/../config/codebuddy.php' => config_path('codebuddy.php'),
2429
]);
2530
}
31+
32+
$this->loadViewsFrom(__DIR__.'/../resources/views', 'codebuddy');
2633
}
2734

28-
public function provides()
35+
/**
36+
* @return array<string>
37+
*/
38+
public function provides(): array
2939
{
3040
return [
31-
Configure::class,
41+
Setup::class,
42+
Scan::class,
3243
];
3344
}
34-
}
45+
}

src/Commands/Configure.php

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

src/Commands/Scan.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace Codebuddyphp\Codebuddy\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Process;
7+
8+
use function Laravel\Prompts\spin;
9+
10+
class Scan extends Command
11+
{
12+
protected $signature = 'cb:scan';
13+
14+
protected $description = 'Scan codebase issues';
15+
16+
public function handle(): void
17+
{
18+
$this->info('Starting code review...');
19+
20+
$checks = [
21+
'rector' => [
22+
'command' => 'vendor/bin/rector process --dry-run',
23+
'message' => 'Running Rector analysis...',
24+
],
25+
'pint' => [
26+
'command' => 'vendor/bin/pint --test',
27+
'message' => 'Running Pint analysis...',
28+
],
29+
'phpstan' => [
30+
'command' => 'vendor/bin/phpstan analyse',
31+
'message' => 'Running PHPStan analysis...',
32+
],
33+
'pest' => [
34+
'command' => 'vendor/bin/pest',
35+
'message' => 'Running Pest tests...',
36+
],
37+
];
38+
39+
foreach ($checks as $check) {
40+
$this->review($check);
41+
}
42+
43+
$this->info('Code review completed!');
44+
}
45+
46+
private function review(array $check): void
47+
{
48+
$process = spin(
49+
fn () => Process::run($check['command']),
50+
$check['message']
51+
);
52+
53+
$this->info($process->output());
54+
}
55+
}

0 commit comments

Comments
 (0)