Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: list_exists rules #169

Merged
merged 7 commits into from
Dec 26, 2024
Merged

Conversation

yogyrton
Copy link
Contributor

@yogyrton yogyrton assigned DenTray and yogyrton and unassigned DenTray Dec 18, 2024
@yogyrton yogyrton assigned DenTray and unassigned yogyrton Dec 19, 2024
return false;
}

$table = Arr::get($parameters, 0);
$keyField = Arr::get($parameters, 1, 'id');

if (!empty(Arr::get($parameters, 2))) {
$tableFields = DB::getSchemaBuilder()->getColumnListing($table);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not good, to get table data inside the validation rule, let's keep this case without user readable error

src/HelpersServiceProvider.php Outdated Show resolved Hide resolved
}
}

if ($isExistsParam) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's rename this var to hasFieldNameParam

@DenTray DenTray assigned yogyrton and unassigned DenTray Dec 23, 2024
@yogyrton yogyrton assigned DenTray and unassigned yogyrton Dec 24, 2024
if (count($parameters) < 1) {
$validator->errors()->add($attribute, 'You must add at least 1 parameter');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked it one more time and it's not good to fail validation in case the developer use validation rule incorrectly. Let's implement the separate InvalidValidationRuleUsageException for such cases

result: [[ 'aggregate' => count($result) ]],
bindings: [1, 2, 3],
);
DB::shouldReceive('table')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reasons to mock DB facade instead of asserting SQL?

@DenTray DenTray assigned yogyrton and unassigned DenTray Dec 25, 2024
@yogyrton yogyrton assigned DenTray and unassigned yogyrton Dec 25, 2024
@@ -3,6 +3,7 @@
namespace RonasIT\Support\Tests\Support\Traits;

use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use Illuminate\Support\Facades\DB;

@DenTray DenTray assigned yogyrton and unassigned DenTray Dec 25, 2024
@yogyrton yogyrton assigned DenTray and unassigned yogyrton Dec 25, 2024
src/HelpersServiceProvider.php Outdated Show resolved Hide resolved
src/HelpersServiceProvider.php Outdated Show resolved Hide resolved
@DenTray DenTray merged commit 2ec5162 into master Dec 26, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants