Skip to content

Update for Cake 5.x #1

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

Merged
merged 10 commits into from
Apr 21, 2025
Merged

Update for Cake 5.x #1

merged 10 commits into from
Apr 21, 2025

Conversation

Ridzuan94
Copy link

Improvement for CakePHP5

Comment on lines +11 to +19
/**
* @inheritDoc
*/
public function requirePresence(array|string $field, Closure|string|bool $mode = true, ?string $message = null): CakeValidator
{
$message = $message ?? __d('validation', 'requirePresence');

return parent::requirePresence($field, $mode, $message);
}
Copy link
Author

Choose a reason for hiding this comment

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

Fix indentation when running composer cs-fix.
Next, follow the argument data type based on the CakePHP5 Validator.
Refer: https://github.com/cakephp/validation/blob/5.x/Validator.php

Comment on lines -117 to +114
->isArray('column')
->array('column')
Copy link
Author

Choose a reason for hiding this comment

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

Validator::isArray() is deprecated in CakePHP5. Need to use Validator::array() instead.
Refer: https://book.cakephp.org/4/en/appendices/4-5-migration-guide.html#validation

'tmp_name' => 'tmp_name',
'error' => UPLOAD_ERR_NO_FILE,
],
'file' => new UploadedFile('', 0, UPLOAD_ERR_NO_FILE, null, null),
Copy link
Author

Choose a reason for hiding this comment

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

The file attachment already changed from an array to an UploadedFile object.
Refer: https://book.cakephp.org/5/en/appendices/5-0-migration-guide.html#http

Copy link

@TABTyrell TABTyrell left a comment

Choose a reason for hiding this comment

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

@mtak3 I'm sorry, we are unable to set you as reviewer in this PR at the moment. Once Ridzuan has made the necessary fixes, I would like to request your review of the updated PR. We'll keep you informed.

Thank you for your understanding!

@@ -323,7 +321,6 @@ public function testNotScalar()
'lessThan' => 'lessThan',
'lessThanOrEqual' => 'lessThanOrEqual',
'equals' => 'equals',
'notEquals' => 'notEquals',

Choose a reason for hiding this comment

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

For notEquals, the Validation::comparison() method uses the operator !=.

Currently, the values being compared are [] and 1. With these values, the comparison will always return true. Instead of removing notEquals, why not fix the following line:

https://github.com/Ridzuan94/cakephp-validator/blob/eb3ca1f6482e839e09001e1840939a95a592b7d2/tests/TestCase/Validation/ValidatorTest.php#L266

Ensure that the value being compared is consistent with what is used for validation in this line:

https://github.com/Ridzuan94/cakephp-validator/blob/eb3ca1f6482e839e09001e1840939a95a592b7d2/tests/TestCase/Validation/ValidatorTest.php#L312

This way, it will not be necessary to remove notEquals from the errors column. Please check.

Copy link
Author

Choose a reason for hiding this comment

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

@TABTyrell
Understood. For this fixed at 12d461c.
Already ran composer test and it worked as expected.
Thank you for the advice given appreciate it. 🙏

- Set notEquals value to the correct one.
Refer comment :
tyrellsys#1 (comment)
@mtak3 mtak3 changed the base branch from master to 5.x April 21, 2025 03:37
@mtak3 mtak3 merged commit f6b3347 into tyrellsys:5.x Apr 21, 2025
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.

3 participants