Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
InternationalisationsTable
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 initialize
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 validationDefault
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare(strict_types=1);
3
4namespace App\Model\Table;
5
6use Cake\ORM\Table;
7use Cake\Validation\Validator;
8
9/**
10 * Internationalisations Model
11 *
12 * @method \App\Model\Entity\Internationalisation newEmptyEntity()
13 * @method \App\Model\Entity\Internationalisation newEntity(array $data, array $options = [])
14 * @method array<\App\Model\Entity\Internationalisation> newEntities(array $data, array $options = [])
15 * @method \App\Model\Entity\Internationalisation get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
16 * @method \App\Model\Entity\Internationalisation findOrCreate($search, ?callable $callback = null, array $options = [])
17 * @method \App\Model\Entity\Internationalisation patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
18 * @method array<\App\Model\Entity\Internationalisation> patchEntities(iterable $entities, array $data, array $options = [])
19 * @method \App\Model\Entity\Internationalisation|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
20 * @method \App\Model\Entity\Internationalisation saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
21 * @method iterable<\App\Model\Entity\Internationalisation>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\Internationalisation>|false saveMany(iterable $entities, array $options = [])
22 * @method iterable<\App\Model\Entity\Internationalisation>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\Internationalisation> saveManyOrFail(iterable $entities, array $options = [])
23 * @method iterable<\App\Model\Entity\Internationalisation>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\Internationalisation>|false deleteMany(iterable $entities, array $options = [])
24 * @method iterable<\App\Model\Entity\Internationalisation>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\Internationalisation> deleteManyOrFail(iterable $entities, array $options = [])
25 */
26class InternationalisationsTable extends Table
27{
28    /**
29     * Initialize method
30     *
31     * @param array<string, mixed> $config The configuration for the Table.
32     * @return void
33     */
34    public function initialize(array $config): void
35    {
36        parent::initialize($config);
37
38        $this->setTable('internationalisations');
39        $this->setDisplayField('message_id');
40        $this->setPrimaryKey('id');
41    }
42
43    /**
44     * Default validation rules.
45     *
46     * @param \Cake\Validation\Validator $validator Validator instance.
47     * @return \Cake\Validation\Validator
48     */
49    public function validationDefault(Validator $validator): Validator
50    {
51        $validator
52            ->scalar('locale')
53            ->maxLength('locale', 10)
54            ->requirePresence('locale', 'create')
55            ->notEmptyString('locale');
56
57        $validator
58            ->scalar('message_id')
59            ->requirePresence('message_id', 'create')
60            ->notEmptyString('message_id')
61            ->add('message_id', 'unique', [
62                'rule' => function ($value, $context) {
63                    $count = $this->find()
64                        ->where(['message_id' => $value, 'locale' => $context['data']['locale']])
65                        ->count();
66
67                    return $count === 0;
68                },
69                'message' => __('This message_id must be unique for the given locale.'),
70            ]);
71
72        $validator
73            ->scalar('message_str')
74            ->allowEmptyString('message_str');
75
76        $validator
77            ->dateTime('created')
78            ->notEmptyDateTime('created');
79
80        $validator
81            ->dateTime('modified')
82            ->notEmptyDateTime('modified');
83
84        return $validator;
85    }
86}