Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
23 / 23 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| UserAccountConfirmationsTable | |
100.00% |
23 / 23 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| initialize | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| validationDefault | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| buildRules | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | |
| 4 | namespace App\Model\Table; |
| 5 | |
| 6 | use Cake\ORM\RulesChecker; |
| 7 | use Cake\ORM\Table; |
| 8 | use Cake\Validation\Validator; |
| 9 | |
| 10 | /** |
| 11 | * UserAccountConfirmations Model |
| 12 | * |
| 13 | * @property \App\Model\Table\UsersTable&\Cake\ORM\Association\BelongsTo $Users |
| 14 | * @method \App\Model\Entity\UserAccountConfirmation newEmptyEntity() |
| 15 | * @method \App\Model\Entity\UserAccountConfirmation newEntity(array $data, array $options = []) |
| 16 | * @method array<\App\Model\Entity\UserAccountConfirmation> newEntities(array $data, array $options = []) |
| 17 | * @method \App\Model\Entity\UserAccountConfirmation get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args) |
| 18 | * @method \App\Model\Entity\UserAccountConfirmation findOrCreate($search, ?callable $callback = null, array $options = []) |
| 19 | * @method \App\Model\Entity\UserAccountConfirmation patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = []) |
| 20 | * @method array<\App\Model\Entity\UserAccountConfirmation> patchEntities(iterable $entities, array $data, array $options = []) |
| 21 | * @method \App\Model\Entity\UserAccountConfirmation|false save(\Cake\Datasource\EntityInterface $entity, array $options = []) |
| 22 | * @method \App\Model\Entity\UserAccountConfirmation saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = []) |
| 23 | * @method iterable<\App\Model\Entity\UserAccountConfirmation>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\UserAccountConfirmation>|false saveMany(iterable $entities, array $options = []) |
| 24 | * @method iterable<\App\Model\Entity\UserAccountConfirmation>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\UserAccountConfirmation> saveManyOrFail(iterable $entities, array $options = []) |
| 25 | * @method iterable<\App\Model\Entity\UserAccountConfirmation>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\UserAccountConfirmation>|false deleteMany(iterable $entities, array $options = []) |
| 26 | * @method iterable<\App\Model\Entity\UserAccountConfirmation>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\UserAccountConfirmation> deleteManyOrFail(iterable $entities, array $options = []) |
| 27 | * @mixin \Cake\ORM\Behavior\TimestampBehavior |
| 28 | */ |
| 29 | class UserAccountConfirmationsTable extends Table |
| 30 | { |
| 31 | /** |
| 32 | * Initialize method |
| 33 | * |
| 34 | * @param array<string, mixed> $config The configuration for the Table. |
| 35 | * @return void |
| 36 | */ |
| 37 | public function initialize(array $config): void |
| 38 | { |
| 39 | parent::initialize($config); |
| 40 | |
| 41 | $this->setTable('user_account_confirmations'); |
| 42 | $this->setDisplayField('id'); |
| 43 | $this->setPrimaryKey('id'); |
| 44 | |
| 45 | $this->addBehavior('Timestamp'); |
| 46 | |
| 47 | $this->belongsTo('Users', [ |
| 48 | 'foreignKey' => 'user_id', |
| 49 | 'joinType' => 'INNER', |
| 50 | ]); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Default validation rules. |
| 55 | * |
| 56 | * @param \Cake\Validation\Validator $validator Validator instance. |
| 57 | * @return \Cake\Validation\Validator |
| 58 | */ |
| 59 | public function validationDefault(Validator $validator): Validator |
| 60 | { |
| 61 | $validator |
| 62 | ->scalar('user_id') |
| 63 | ->maxLength('user_id', 36) |
| 64 | ->notEmptyString('user_id'); |
| 65 | |
| 66 | $validator |
| 67 | ->scalar('confirmation_code') |
| 68 | ->maxLength('confirmation_code', 36) |
| 69 | ->requirePresence('confirmation_code', 'create') |
| 70 | ->notEmptyString('confirmation_code') |
| 71 | ->add('confirmation_code', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']); |
| 72 | |
| 73 | return $validator; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns a rules checker object that will be used for validating |
| 78 | * application integrity. |
| 79 | * |
| 80 | * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. |
| 81 | * @return \Cake\ORM\RulesChecker |
| 82 | */ |
| 83 | public function buildRules(RulesChecker $rules): RulesChecker |
| 84 | { |
| 85 | $rules->add($rules->isUnique(['confirmation_code']), ['errorField' => 'confirmation_code']); |
| 86 | $rules->add($rules->existsIn(['user_id'], 'Users'), ['errorField' => 'user_id']); |
| 87 | |
| 88 | return $rules; |
| 89 | } |
| 90 | } |