Skip to content

Commit 1554d84

Browse files
authored
Merge pull request #79 from ADmad/cake-5.3
Update for CakePHP 5.3
2 parents 7a7cf6c + ed3e333 commit 1554d84

6 files changed

Lines changed: 28 additions & 11 deletions

File tree

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
"issues":"https://github.com/ADmad/cakephp-i18n/issues"
2424
},
2525
"require": {
26-
"cakephp/cakephp": "^5.0"
26+
"cakephp/cakephp": "^5.3"
2727
},
2828
"require-dev": {
29-
"phpunit/phpunit": "^10.5.58 || ^11.5.3 || ^12.4"
29+
"phpunit/phpunit": "^11.5.3 || ^12.4 || ^13.0"
3030
},
3131
"autoload": {
3232
"psr-4": {

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 7
2+
level: 8
33
treatPhpDocTypesAsCertain: false
44
bootstrapFiles:
55
- tests/bootstrap.php

psalm.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,10 @@
2020
<PropertyNotSetInConstructor errorLevel="info" />
2121
<MissingConstructor errorLevel="info" />
2222
<RiskyTruthyFalsyComparison errorLevel="info" />
23+
<MissingOverrideAttribute errorLevel="info" />
24+
<ClassMustBeFinal errorLevel="info" />
25+
<PossiblyNullArrayAccess errorLevel="info" />
26+
<PossiblyNullArrayAssignment errorLevel="info" />
27+
<PossiblyNullArrayOffset errorLevel="info" />
2328
</issueHandlers>
2429
</psalm>

src/Command/I18nExtractCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class I18nExtractCommand extends CakeI18nExtractCommand
2222

2323
/**
2424
* Default model for storing translation messages.
25+
*
26+
* @var string
2527
*/
2628
public const DEFAULT_MODEL = 'I18nMessages';
2729

@@ -207,7 +209,7 @@ protected function _getLanguages(Arguments $args): array
207209
protected function _saveMessages(Arguments $args, ConsoleIo $io): void
208210
{
209211
$paths = $this->_paths;
210-
/** @psalm-suppress UndefinedConstant */
212+
/** @psalm-suppress UndefinedConstant, PossiblyFalseOperand */
211213
$paths[] = realpath(APP) . DIRECTORY_SEPARATOR;
212214

213215
usort($paths, function (string $a, string $b): int {

src/Validation/Validator.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,21 @@ public function validationDomain(?string $domain = null): ?string
4040
* @param \Cake\Validation\ValidationSet $rules the list of rules for a field
4141
* @param array $data the full data passed to the validator
4242
* @param bool $newRecord whether is it a new record or an existing one
43+
* @param array $context Additional validation context.
4344
* @return array<string, mixed>
4445
*/
45-
protected function _processRules(string $field, ValidationSet $rules, array $data, bool $newRecord): array
46-
{
46+
protected function _processRules(
47+
string $field,
48+
ValidationSet $rules,
49+
array $data,
50+
bool $newRecord,
51+
array $context = [],
52+
): array {
4753
$errors = [];
48-
// Loading default provider in case there is none
49-
$this->getProvider('default');
54+
$context = compact('newRecord', 'data', 'field') + $context;
5055

5156
foreach ($rules as $name => $rule) {
52-
$result = $rule->process($data[$field], $this->_providers, compact('newRecord', 'data', 'field'));
57+
$result = $rule->process($data[$field], $this->_providers, $context);
5358
if ($result === true) {
5459
continue;
5560
}
@@ -61,6 +66,10 @@ protected function _processRules(string $field, ValidationSet $rules, array $dat
6166
} else {
6267
$args = $rule->get('pass');
6368
$errors[$name] = __d($this->_validationDomain, $name, $this->_translateArgs($args));
69+
70+
if ($errors[$name] === $name) {
71+
$errors[$name] = __d('cake', 'The provided value is invalid');
72+
}
6473
}
6574

6675
if ($rule->isLast()) {

tests/TestCase/View/Widget/TimezoneWidgetTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use ADmad\I18n\View\Widget\TimezoneWidget;
77
use Cake\TestSuite\TestCase;
8+
use Cake\View\Form\ContextInterface;
89
use Cake\View\StringTemplate;
910
use DateTimeZone;
1011
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
@@ -14,7 +15,7 @@
1415
*/
1516
class TimezoneWidgetTest extends TestCase
1617
{
17-
protected $context;
18+
protected ContextInterface $context;
1819

1920
protected StringTemplate $templates;
2021

@@ -32,7 +33,7 @@ public function setUp(): void
3233
'option' => '<option value="{{value}}"{{attrs}}>{{text}}</option>',
3334
'optgroup' => '<optgroup label="{{label}}"{{attrs}}>{{content}}</optgroup>',
3435
];
35-
$this->context = $this->getMockBuilder('Cake\View\Form\ContextInterface')->getMock();
36+
$this->context = $this->createStub(ContextInterface::class);
3637
$this->templates = new StringTemplate($templates);
3738
}
3839

0 commit comments

Comments
 (0)