Skip to content

Commit 22877c3

Browse files
committed
create workflow
1 parent ef79b22 commit 22877c3

File tree

16 files changed

+408
-90
lines changed

16 files changed

+408
-90
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: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,36 @@
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:
97

10-
- **Rector** (automated code refactoring)
11-
- **Pint** (code styling)
12-
- **PHPStan** (static analysis)
13-
- **PestPHP** (testing framework)
8+
## Installation
149

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
10+
Install the package as dev dependency:
11+
```
12+
composer require --dev codebuddyphp/codebuddy
2613
```
27-
This command sets up **Rector, PestPHP, Pint, and PHPStan** with standard configurations.
2814

29-
### Run CI Checks
30-
```sh
31-
php artisan codebuddy:ci [--fix]
15+
Publish the configuration:
3216
```
33-
Runs tests, performs static analysis, and checks code style in a **dry-run mode** (does not modify files). Optimized for CI/CD pipelines.
17+
php artisan vendor:publish --provider="Codebuddyphp\Codebuddy\CodebuddyServiceProvider" --tag="codebuddy-config" --force
18+
```
19+
3420

35-
- `--fix`: Automatically applies fixes for Rector and Pint where possible.
21+
## Usage
3622

37-
### Generate Code Quality Report
38-
```sh
39-
php artisan codebuddy:report [--show|--send-to=<email>]
23+
Configure essential tools (like Rector, Pint, Phpstan, Pest, etc):
24+
```
25+
php artisan cb:configure
4026
```
41-
- `--show`: Displays the overall code health report in the console.
42-
- `--send-to=<email>`: Sends the report to the specified email address.
4327

44-
---
28+
Find or fix codebase issues:
29+
```
30+
php artisan cb:review [--fix]
31+
```
4532

46-
This package simplifies code quality enforcement, making it easier to maintain a high standard across your Laravel projects.
33+
Get quick codebase insights:
34+
```
35+
php artisan cb:insights
36+
```

composer.json

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
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+
"keywords": ["testing", "development", "tool"],
6+
"license": "MIT",
57
"require": {
68
"php": "^8.2",
7-
"laravel/framework": "^11.0",
8-
"nunomaduro/termwind": "^2.3",
9-
"laravel/pint": "^1.20",
9+
"laravel/framework": "^11|^12",
10+
"laravel/pint": "^1.21",
11+
"driftingly/rector-laravel": "^2.0",
1012
"larastan/larastan": "^3.0",
11-
"rector/rector": "^2.0"
13+
"pestphp/pest": "^3.7"
14+
},
15+
"require-dev": {
1216
},
1317
"autoload": {
1418
"psr-4": {
1519
"Codebuddyphp\\Codebuddy\\": "src/"
1620
}
1721
},
1822
"scripts": {
23+
"lint": "pint --test",
24+
"lint.fix": "pint",
25+
"rector": "rector process --dry-run",
26+
"rector.fix": "rector process",
27+
"ci": [
28+
"@lint",
29+
"@rector"
30+
],
31+
"ci.fix": [
32+
"@rector.fix",
33+
"@lint.fix"
34+
]
1935
},
2036
"extra": {
2137
"laravel": {
@@ -27,7 +43,10 @@
2743
}
2844
},
2945
"config": {
30-
"preferred-install": "dist"
46+
"preferred-install": "dist",
47+
"allow-plugins": {
48+
"pestphp/pest-plugin": true
49+
}
3150
},
3251
"minimum-stability": "dev",
3352
"prefer-stable": true

config/codebuddy.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,38 @@
11
<?php
2+
3+
return [
4+
'checks' => [
5+
'rector' => [
6+
'package' => 'driftingly/rector-laravel',
7+
'stub_file' => 'rector.php.stub',
8+
'config_file' => 'rector.php',
9+
'dry_run' => 'vendor/bin/rector process --dry-run',
10+
'auto_fix' => 'vendor/bin/rector process',
11+
'tags' => ['code-quality', 'auto-upgrades'],
12+
],
13+
'pint' => [
14+
'package' => 'laravel/pint',
15+
'stub_file' => 'pint.json.stub',
16+
'config_file' => 'pint.json',
17+
'dry_run' => 'vendor/bin/pint --test',
18+
'auto_fix' => 'vendor/bin/pint',
19+
'tags' => ['code-styling'],
20+
],
21+
'phpstan' => [
22+
'package' => 'larastan/larastan',
23+
'stub_file' => 'phpstan.neon.stub',
24+
'config_file' => 'phpstan.neon',
25+
'dry_run' => 'vendor/bin/phpstan analyse',
26+
'auto_fix' => null,
27+
'tags' => ['static-analysis'],
28+
],
29+
'pest' => [
30+
'package' => 'pestphp/pest',
31+
'stub_file' => 'phpunit.xml.stub',
32+
'config_file' => 'phpunit.xml',
33+
'dry_run' => 'vendor/bin/pest --compact',
34+
'auto_fix' => null,
35+
'tags' => ['testing', 'unit-testing', 'feature-testing', 'mutation-testing'],
36+
],
37+
],
38+
];

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: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,46 @@
33
namespace Codebuddyphp\Codebuddy;
44

55
use Codebuddyphp\Codebuddy\Commands\Configure;
6+
use Codebuddyphp\Codebuddy\Commands\Insights;
7+
use Codebuddyphp\Codebuddy\Commands\Review;
68
use Illuminate\Support\ServiceProvider;
79

8-
class CodebuddyServiceProvider extends ServiceProvider
10+
final class CodebuddyServiceProvider extends ServiceProvider
911
{
10-
public function register()
11-
{
12-
// Register bindings if any
13-
}
12+
public function register(): void {}
1413

15-
public function boot()
14+
public function boot(): void
1615
{
1716
if ($this->app->runningInConsole()) {
18-
$this->commands([
19-
Configure::class,
20-
]);
2117

22-
$this->publishes([
23-
__DIR__.'/../config/codebuddy.php' => config_path('codebuddy.php'),
24-
]);
18+
$this->commands(
19+
[
20+
Configure::class,
21+
Review::class,
22+
Insights::class,
23+
]
24+
);
25+
26+
$this->publishes(
27+
[
28+
__DIR__.'/../config/codebuddy.php' => config_path('codebuddy.php'),
29+
],
30+
'codebuddy-config'
31+
);
2532
}
33+
34+
$this->loadViewsFrom(__DIR__.'/../resources/views', 'codebuddy');
2635
}
2736

28-
public function provides()
37+
/**
38+
* @return array<string>
39+
*/
40+
public function provides(): array
2941
{
3042
return [
3143
Configure::class,
44+
Review::class,
45+
Insights::class,
3246
];
3347
}
34-
}
48+
}

src/Commands/Configure.php

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,52 @@
33
namespace Codebuddyphp\Codebuddy\Commands;
44

55
use Illuminate\Console\Command;
6-
use Illuminate\Filesystem\Filesystem;
7-
use function Termwind\render;
6+
use Illuminate\Support\Facades\Config;
7+
use Illuminate\Support\Facades\File;
88

9-
class Configure extends Command
9+
use function Laravel\Prompts\confirm;
10+
use function Laravel\Prompts\spin;
11+
12+
final class Configure extends Command
1013
{
11-
protected $signature = 'codebuddy:configure';
14+
protected $signature = 'cb:configure';
1215

13-
protected $description = 'Configure Rector, Larastan (PHPStan) & Pint';
16+
protected $description = 'Configures essential packages for your project';
1417

1518
public function handle(): void
1619
{
17-
$filesystem = new Filesystem();
18-
19-
$configs = [
20-
'rector.php',
21-
'phpstan.neon',
22-
'pint.json',
23-
];
24-
25-
foreach ($configs as $file) {
26-
$sourceFile = __DIR__ . "/../../config/laravel/{$file}";
27-
$destinationFile = base_path($file);
28-
29-
if (!$filesystem->exists($sourceFile)) {
30-
$this->error("Source file not found: {$sourceFile}");
31-
continue;
32-
}
33-
34-
if ($filesystem->exists($destinationFile)) {
35-
$overwrite = $this->confirmOverwrite($destinationFile);
36-
if (!$overwrite) {
37-
$this->warn("Skipped: {$destinationFile} already exists");
38-
continue;
39-
}
40-
}
20+
$packages = Config::get('codebuddy.checks');
21+
22+
foreach ($packages as $package) {
23+
$this->configurePackage($package);
24+
}
25+
26+
$confirmed = confirm('Setup completed. Do you want to review codebase?');
4127

42-
$filesystem->copy($sourceFile, $destinationFile);
43-
$this->info("Copied: {$file} to project root");
44-
$this->newLine();
28+
if ($confirmed) {
29+
$this->call(Review::class);
4530
}
4631
}
4732

48-
private function confirmOverwrite(string $file): bool
33+
private function configurePackage(array $package): void
4934
{
50-
$this->info(
51-
sprintf('%s already exists. Do you want to overwrite it?', $file)
52-
);
35+
$this->newLine();
36+
37+
spin(
38+
callback: function () use ($package): void {
39+
sleep(1);
40+
$result = File::copy(
41+
__DIR__.'/../../stubs/'.$package['stub_file'],
42+
base_path($package['config_file'])
43+
);
44+
if (! $result) {
45+
self::fail(
46+
sprintf('%s: failed to configure', $package['package'])
47+
);
48+
}
49+
},
50+
message: sprintf('🚀 Configuring %s...', $package['package']));
5351

54-
return $this->ask('Overwrite?', false);
52+
$this->info(sprintf('✅ %s: configured', $package['package']));
5553
}
5654
}

0 commit comments

Comments
 (0)