generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
166 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Msamgan\LaravelEnvKeysChecker\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Msamgan\LaravelEnvKeysChecker\Concerns\HelperFunctions; | ||
|
||
class EnvInGitIgnoreCommand extends Command | ||
{ | ||
use HelperFunctions; | ||
|
||
public $signature = 'env:in-git-ignore'; | ||
|
||
public $description = 'Check if .env file is in .gitignore file.'; | ||
|
||
public function handle(): int | ||
{ | ||
$gitIgnoreFile = base_path('.gitignore'); | ||
|
||
if (! file_exists($gitIgnoreFile)) { | ||
$this->showFailureInfo(message: '.gitignore file not found.'); | ||
|
||
return self::FAILURE; | ||
} | ||
|
||
$gitIgnoreContent = array_map('trim', file($gitIgnoreFile)); | ||
|
||
$filesToCheck = config('env-keys-checker.gitignore_files', ['.env']); | ||
|
||
$missingFiles = collect(); | ||
collect($filesToCheck)->each(function ($file) use ($gitIgnoreContent, $missingFiles) { | ||
if (! in_array($file, $gitIgnoreContent)) { | ||
$missingFiles->push($file); | ||
} | ||
}); | ||
|
||
if ($missingFiles->isEmpty()) { | ||
$this->showSuccessInfo(message: 'All files are present in .gitignore file.'); | ||
|
||
return self::SUCCESS; | ||
} | ||
|
||
$this->showFailureInfo(message: $missingFiles->implode(', ') . ' file(s) not found in .gitignore file.'); | ||
|
||
return self::FAILURE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Msamgan\LaravelEnvKeysChecker\Concerns; | ||
|
||
use function Laravel\Prompts\error; | ||
use function Laravel\Prompts\info; | ||
|
||
trait HelperFunctions | ||
{ | ||
private function showSuccessInfo(string $message): void | ||
{ | ||
info(' => ' . $message); | ||
} | ||
|
||
private function showFailureInfo(string $message): void | ||
{ | ||
error(' !! ' . $message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters