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