Skip to content

Commit 6f1a799

Browse files
committed
feat(global): New release 2.0.1
- Improve code style with Laravel Pint! - Upgrade php version from 8.1 to 8.2 in GitHub Action for run tests! - Upgrade phpunit configuration
1 parent 1be5276 commit 6f1a799

30 files changed

+145
-162
lines changed

.github/workflows/laravel.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111

1212
runs-on: ubuntu-latest
1313

14-
steps:
14+
steps:
1515
- uses: shivammathur/setup-php@v2
1616
with:
17-
php-version: '8.1'
17+
php-version: '8.2'
1818
extensions: mbstring, pdo, pdo_sqlite, xml, json, gd
1919
- uses: actions/checkout@v3
2020
- name: Copy .env

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ Homestead.yaml
1212
npm-debug.log
1313
yarn-error.log
1414
.idea
15+
etc/infrastructure/nginx/conf.d/
16+
.phpunit.cache/

app/Console/Commands/DatabaseCreate.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ public function handle()
4141
{
4242
$status = 0;
4343
$schema = $this->argument('name');
44-
$charset = config("database.connections.mysql.charset",'utf8mb4');
45-
$collation = config("database.connections.mysql.collation",'utf8mb4_unicode_ci');
44+
$charset = config('database.connections.mysql.charset', 'utf8mb4');
45+
$collation = config('database.connections.mysql.collation', 'utf8mb4_unicode_ci');
4646

47-
config(["database.connections.mysql.database" => null]);
47+
config(['database.connections.mysql.database' => null]);
4848
$query = "CREATE DATABASE IF NOT EXISTS $schema CHARACTER SET $charset COLLATE $collation;";
4949
try {
5050
$status = DB::statement($query);
@@ -53,6 +53,7 @@ public function handle()
5353
$this->error("An error occurred creating the DB: $schema");
5454
Log::error($t->getMessage());
5555
}
56+
5657
return $status;
5758
}
5859
}

app/Console/Commands/Install.php

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,31 @@ public function __construct()
3535

3636
/**
3737
* Execute the console command.
38-
*
39-
* @return int
4038
*/
41-
public function handle() :int
39+
public function handle(): int
4240
{
4341
//1 - Check if .env file exist or created based in the example file
4442
$envPath = base_path('.env');
45-
if(File::exists($envPath))
46-
{
43+
if (File::exists($envPath)) {
4744
$this->info('.env ENVIRONMENT file exist');
4845
}
4946

50-
if(!File::exists($envPath))
51-
{
52-
if(File::copy(base_path('.env.example'), base_path('.env'))){
47+
if (! File::exists($envPath)) {
48+
if (File::copy(base_path('.env.example'), base_path('.env'))) {
5349
$this->info('Copy default .env.example > .env');
5450
}
5551
}
5652

5753
//2- Generate APP_KEY
58-
if(empty(env('APP_KEY')))
59-
{
54+
if (empty(env('APP_KEY'))) {
6055
Artisan::call('key:generate');
6156
$this->info('Application key generated');
6257
}
6358

6459
//3 - Check if DB_PASSWORD is set
65-
if(empty(env('DB_PASSWORD')))
66-
{
60+
if (empty(env('DB_PASSWORD'))) {
6761
$yesno = $this->ask('DB_PASSWORD is in blank. Do you want to setup? (Y/N)');
68-
if(strtoupper($yesno) == 'Y') {
62+
if (strtoupper($yesno) == 'Y') {
6963
$password = $this->ask('Setup DB_PASSWORD:');
7064
$this->setEnv('DB_PASSWORD', $password);
7165
}
@@ -78,33 +72,32 @@ public function handle() :int
7872
}
7973

8074
/**
81-
* @param string $key
82-
* @param string $value
8375
* @return void
8476
*/
8577
private function setEnv(string $key, string $value)
8678
{
8779
file_put_contents(app()->environmentFilePath(), str_replace(
88-
$key . '=' . env($value),
89-
$key . '=' . $value,
80+
$key.'='.env($value),
81+
$key.'='.$value,
9082
file_get_contents(app()->environmentFilePath())
9183
));
9284
}
9385

94-
private function databaseExist() : bool
86+
private function databaseExist(): bool
9587
{
9688
$exist = false;
9789
try {
9890
DB::connection()->getPdo();
99-
if(DB::connection()->getDatabaseName()){
100-
$this->info("Yes! Successfully connected to the DB: " . DB::connection()->getDatabaseName());
91+
if (DB::connection()->getDatabaseName()) {
92+
$this->info('Yes! Successfully connected to the DB: '.DB::connection()->getDatabaseName());
10193
$exist = true;
102-
}else{
103-
$this->error("Could not find the database. Please check your configuration.");
94+
} else {
95+
$this->error('Could not find the database. Please check your configuration.');
10496
}
10597
} catch (\Throwable $t) {
106-
$this->info("Could not open connection to database server. Please check your configuration.");
98+
$this->info('Could not open connection to database server. Please check your configuration.');
10799
}
100+
108101
return $exist;
109102
}
110103
}

app/Console/Commands/UserCreate.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace App\Console\Commands;
44

5-
use Illuminate\Console\Command;
65
use App\Models\User;
6+
use Illuminate\Console\Command;
77
use Illuminate\Support\Facades\Hash;
88

99
class UserCreate extends Command
@@ -49,10 +49,11 @@ public function handle()
4949
'name' => $name,
5050
'email' => $email,
5151
'password' => Hash::make($pwd),
52-
'lang' => $lang
52+
'lang' => $lang,
5353
]);
5454

5555
$this->info('Account created for '.$name);
56+
5657
return 0;
5758
}
5859
}

app/Console/Commands/WebsiteCreate.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
namespace App\Console\Commands;
44

5+
use App\Models\Website;
56
use Illuminate\Console\Command;
6-
use Symfony\Component\Process\Exception\ProcessFailedException;
77
use Symfony\Component\Process\Process;
8-
use App\Models\Website;
98

109
class WebsiteCreate extends Command
1110
{
@@ -51,7 +50,7 @@ public function handle()
5150
$php_version = $this->argument('php');
5251

5352
$website = Website::where('url', $domain)->first();
54-
if (!$website) {
53+
if (! $website) {
5554
$website = new Website();
5655
$website->url = $domain;
5756
$website->created_at = now();
@@ -66,13 +65,11 @@ public function handle()
6665
}
6766

6867
$destination = "/etc/$server";
69-
if (is_dir("/etc/$server/sites-available"))
70-
{
68+
if (is_dir("/etc/$server/sites-available")) {
7169
$destination = "/etc/$server/sites-available/$domain.conf";
7270
}
7371

74-
if (is_dir("/etc/$server/conf.d"))
75-
{
72+
if (is_dir("/etc/$server/conf.d")) {
7673
$destination = "/etc/$server/conf.d/$domain.conf";
7774
}
7875

@@ -91,13 +88,13 @@ public function handle()
9188
}
9289

9390
// Enable virtual host
94-
if (is_dir("/etc/$server/sites-available"))
95-
{
91+
if (is_dir("/etc/$server/sites-available")) {
9692
$virtual_host_path = "/etc/$server/sites-enabled/";
9793
chdir($virtual_host_path);
9894
$process = new Process(['ln', '-s', $destination]);
9995
$process->run();
10096
}
97+
10198
// TODO: check nginx -t
10299
// TODO: service nginx reload
103100
return $status;

app/Console/Kernel.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class Kernel extends ConsoleKernel
1919
/**
2020
* Define the application's command schedule.
2121
*
22-
* @param \Illuminate\Console\Scheduling\Schedule $schedule
2322
* @return void
2423
*/
2524
protected function schedule(Schedule $schedule)

app/Helpers/File.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
namespace App\Helpers;
4+
45
/**
56
* File Helper
67
*/
@@ -9,33 +10,33 @@ class File
910
/**
1011
* Return human formated file size
1112
*
12-
* @param int $size bytes
13-
*
13+
* @param int $size bytes
1414
* @return string formated size for humans
1515
*/
1616
public static function formatSize($size)
1717
{
1818
$suffix = '';
1919
switch ($size) {
20-
case ($size > 1099511627776):
21-
$size /= 1099511627776;
22-
$suffix = 'TB';
23-
break;
24-
case ($size > 1073741824):
25-
$size /= 1073741824;
26-
$suffix = 'GB';
27-
break;
28-
case ($size > 1048576):
29-
$size /= 1048576;
30-
$suffix = 'MB';
31-
break;
32-
case ($size > 1024):
33-
$size /= 1024;
34-
$suffix = 'KB';
35-
break;
36-
default:
37-
$suffix = 'B';
20+
case $size > 1099511627776:
21+
$size /= 1099511627776;
22+
$suffix = 'TB';
23+
break;
24+
case $size > 1073741824:
25+
$size /= 1073741824;
26+
$suffix = 'GB';
27+
break;
28+
case $size > 1048576:
29+
$size /= 1048576;
30+
$suffix = 'MB';
31+
break;
32+
case $size > 1024:
33+
$size /= 1024;
34+
$suffix = 'KB';
35+
break;
36+
default:
37+
$suffix = 'B';
3838
}
39-
return round($size, 2) . " " . $suffix;
39+
40+
return round($size, 2).' '.$suffix;
4041
}
4142
}

app/Helpers/Linux.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace App\Helpers;
34

45
use Symfony\Component\Process\Exception\ProcessFailedException;
@@ -9,7 +10,6 @@
910
*
1011
* https://symfony.com/doc/current/components/process.html
1112
* https://linuxize.com/post/how-to-create-users-in-linux-using-the-useradd-command/
12-
*
1313
*/
1414
class Linux
1515
{
@@ -18,38 +18,42 @@ class Linux
1818
*
1919
* @return string formated server uptime
2020
*/
21-
public static function getUptime() : string
21+
public static function getUptime(): string
2222
{
23-
$str = @file_get_contents('/proc/uptime');
24-
$num = floatval($str);
25-
$secs = fmod($num, 60); $num = intdiv($num, 60);
26-
$mins = $num % 60; $num = intdiv($num, 60);
27-
$hours = $num % 24; $num = intdiv($num, 24);
28-
$days = $num;
29-
return sprintf("%03dd: %02dh: %02dm: %02ds", $days, $hours, $mins, $secs);
23+
$str = @file_get_contents('/proc/uptime');
24+
$num = floatval($str);
25+
$secs = fmod($num, 60);
26+
$num = intdiv($num, 60);
27+
$mins = $num % 60;
28+
$num = intdiv($num, 60);
29+
$hours = $num % 24;
30+
$num = intdiv($num, 24);
31+
$days = $num;
32+
33+
return sprintf('%03dd: %02dh: %02dm: %02ds', $days, $hours, $mins, $secs);
3034
}
3135

3236
/**
3337
* Add Linux user to the system
3438
*
35-
* @param string $username linux username
36-
*
37-
* @return string
39+
* @param string $username linux username
3840
*/
39-
public static function userAdd(string $username = '') : string
41+
public static function userAdd(string $username = ''): string
4042
{
41-
if (!empty($username)) {
43+
if (! empty($username)) {
4244
// -m generate home directory
4345
$process = new Process(['useradd', '-m', $username]);
4446
$process->run();
4547

4648
// executes after the command finishes
47-
if (!$process->isSuccessful()) {
49+
if (! $process->isSuccessful()) {
4850
throw new ProcessFailedException($process);
4951
}
5052

5153
$output = $process->getOutput();
54+
5255
return $output;
5356
}
57+
return 'ERROR: username can\'t be empty';
5458
}
5559
}

app/Http/Controllers/Auth/RegisterController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace App\Http\Controllers\Auth;
44

55
use App\Http\Controllers\Controller;
6-
use App\Providers\RouteServiceProvider;
76
use App\Models\User;
7+
use App\Providers\RouteServiceProvider;
88
use Illuminate\Foundation\Auth\RegistersUsers;
99
use Illuminate\Support\Facades\Hash;
1010
use Illuminate\Support\Facades\Validator;
@@ -44,7 +44,6 @@ public function __construct()
4444
/**
4545
* Get a validator for an incoming registration request.
4646
*
47-
* @param array $data
4847
* @return \Illuminate\Contracts\Validation\Validator
4948
*/
5049
protected function validator(array $data)
@@ -59,7 +58,6 @@ protected function validator(array $data)
5958
/**
6059
* Create a new user instance after a valid registration.
6160
*
62-
* @param array $data
6361
* @return \App\Models\User
6462
*/
6563
protected function create(array $data)

0 commit comments

Comments
 (0)