Skip to content

Commit

Permalink
added pint workflow and fixed style of existing files
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelhamiderrahmouni committed Feb 21, 2024
1 parent 89c53a9 commit c0e460d
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 14 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/pint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: pint

on: push

jobs:
pint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}

- name: Install Composer
run: composer install

- name: Run Laravel Pint
run: composer pint

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: fix code formatting
30 changes: 17 additions & 13 deletions app/Commands/VendorKill.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php

declare(strict_types=1);

namespace App\Commands;

use LaravelZero\Framework\Commands\Command;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

use function Laravel\Prompts\multiselect;

class VendorKill extends Command
Expand All @@ -23,7 +26,6 @@ class VendorKill extends Command
*
* @var string
*/

protected $description = 'Delete composer vendor directories.';

public function handle()
Expand All @@ -36,11 +38,11 @@ public function handle()
$process = new Process(['find', $search_path, '-maxdepth', $this->option('maxdepth'), '-type', 'd', '-name', 'vendor']);
$process->run();

if (!$process->isSuccessful()) {
if (! $process->isSuccessful()) {
throw new ProcessFailedException($process);
}

$this->info("⚗️ Filtering valid composer vendor directories...");
$this->info('⚗️ Filtering valid composer vendor directories...');

$vendor_dirs = explode(PHP_EOL, trim($process->getOutput()));

Expand All @@ -60,7 +62,7 @@ public function handle()

// Show the total size of the vendor directories
$this->showTotal($total_size_human, $vendor_dirs);
$counter = 1;
$counter = 1;
$selectOptions = [];
// List the vendor directories with their sizes and project names
foreach ($vendor_dirs as $dir) {
Expand All @@ -78,8 +80,9 @@ public function handle()
}

// Show the total size of the vendor directories again for convenience
if ($this->option('full'))
if ($this->option('full')) {
$this->showTotal($total_size_human, $vendor_dirs);
}

// Prompt the user to select directories to delete
$delete_numbers = multiselect(
Expand All @@ -90,7 +93,7 @@ public function handle()

// Delete the selected directories
foreach ($delete_numbers as $num) {
$dir_to_delete = $vendor_dirs[$num - 1];
$dir_to_delete = $vendor_dirs[$num - 1];
shell_exec("rm -rf {$dir_to_delete}");
$this->info("Deleted {$dir_to_delete}");
}
Expand All @@ -101,7 +104,7 @@ public function handle()
protected function getVendorTotalSize(array $vendor_dirs): string
{
// Calculate the total size of vendor directories
$total_size = 0;
$total_size = 0;
foreach ($vendor_dirs as $dir) {
$size = shell_exec("du -s $dir | cut -f1");
$total_size += $size;
Expand All @@ -112,19 +115,20 @@ protected function getVendorTotalSize(array $vendor_dirs): string
}

// Helper function to format the size
private function formatSize($size) {
private function formatSize($size)
{
$units = ['KB', 'MB', 'GB', 'TB'];

for ($i = 0; $size > 1024; $i++) {
$size /= 1024;
for ($i = 0; $size > 1024; $i++) {
$size /= 1024;
}

return round($size, 2) . ' ' . $units[$i];
return round($size, 2) . ' ' . $units[$i];
}

protected function showTotal(string $total_size_human, array $vendor_dirs): void
{
if (count($vendor_dirs) === 0) {
if (count($vendor_dirs) === 0) {
$this->info('🥳 No composer vendor directories found in this path.');
$this->thanks();
exit(0);
Expand Down
2 changes: 2 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
Expand Down
2 changes: 2 additions & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
|--------------------------------------------------------------------------
| Create The Application
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
"Tests\\": "tests/"
}
},
"scripts": {
"pint": "./vendor/bin/pint",
"pest": "./vendor/bin/pest"
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
Expand Down
2 changes: 2 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

return [

/*
Expand Down
2 changes: 2 additions & 0 deletions config/commands.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

return [

/*
Expand Down
2 changes: 2 additions & 0 deletions config/logo.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

return [

/*
Expand Down
12 changes: 12 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"preset": "laravel",
"rules": {
"blank_line_before_statement": true,
"concat_space": {
"spacing": "one"
},
"declare_strict_types": true,
"method_argument_space": true,
"single_trait_insert_per_statement": true
}
}
4 changes: 3 additions & 1 deletion tests/CreatesApplication.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Tests;

use Illuminate\Contracts\Console\Kernel;
Expand All @@ -12,7 +14,7 @@ trait CreatesApplication
*/
public function createApplication(): Application
{
$app = require __DIR__.'/../bootstrap/app.php';
$app = require __DIR__ . '/../bootstrap/app.php';

$app->make(Kernel::class)->bootstrap();

Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/InspireCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

it('inspires artisans', function () {
$this->artisan('inspire')->assertExitCode(0);
});
2 changes: 2 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
|--------------------------------------------------------------------------
| Test Case
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Tests;

use LaravelZero\Framework\Testing\TestCase as BaseTestCase;
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

test('example', function () {
expect(true)->toBeTrue();
});

0 comments on commit c0e460d

Please sign in to comment.