Skip to content

Commit

Permalink
fix: Refactor to method
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmellor committed Aug 1, 2022
1 parent 0fc62ca commit e9248ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions src/Concerns/MustBeApproved.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,8 @@ protected static function insertApprovalRequest($model)
*/
protected static function approvalModelExists($model): bool
{
$driver = Approval::make()->getConnection()->getConfig()['driver'] ?? 'sqlite';

if ($driver === 'sqlite') {
return Approval::where([
['state', '=', ApprovalStatus::Pending],
['new_data', '=', json_encode($model->getDirty())],
['original_data', '=', json_encode($model->getOriginalMatchingChanges())],
])->exists();
if ($model->make()->getConnection()->getConfig()['driver'] === 'sqlite') {
return self::checkDatabaseDriver($model);
}

return Approval::where('state', ApprovalStatus::Pending)
Expand Down Expand Up @@ -85,6 +79,19 @@ public function isApprovalBypassed(): bool
return $this->bypassApproval;
}

/**
* @param $model
* @return bool
*/
protected static function checkDatabaseDriver($model): bool
{
return Approval::where([
['state', '=', ApprovalStatus::Pending],
['new_data', '=', json_encode($model->getDirty())],
['original_data', '=', json_encode($model->getOriginalMatchingChanges())],
])->exists();
}

/**
* Approval is ignored and persisted to the database.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
return new class() extends Migration {
public function up()
{
Schema::create('fake_models', function (Blueprint $table) {
Expand Down

0 comments on commit e9248ae

Please sign in to comment.