Passed
Branch feature/6.x (3df42d)
by Schlaefer
08:49
created

ContactFormOwner   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A _buildSchema() 0 6 1
A validationDefault() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Saito - The Threaded Web Forum
7
 *
8
 * @copyright Copyright (c) the Saito Project Developers
9
 * @link https://github.com/Schlaefer/Saito
10
 * @license http://opensource.org/licenses/MIT
11
 */
12
13
namespace App\Form;
14
15
use Cake\Form\Schema;
16
use Cake\Validation\Validator;
17
18
class ContactFormOwner extends ContactForm
19
{
20
21
    /**
22
     * {@inheritdoc}
23
     *
24
     * @param \Cake\Form\Schema $schema The schema to customize.
25
     * @return \Cake\Form\Schema The schema to use.
26
     */
27
    protected function _buildSchema(Schema $schema): Schema
28
    {
29
        $schema = parent::_buildSchema($schema);
30
        $schema->addField('sender_contact', 'string');
31
32
        return $schema;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     *
38
     * @param \Cake\Validation\Validator $validator The validator to customize.
39
     * @return \Cake\Validation\Validator The validator to use.
40
     */
41
    public function validationDefault(Validator $validator): Validator
42
    {
43
        $validator
44
            ->notEmptyString('sender_contact')
45
            ->add('sender_contact', [
46
                'isEmail' => [
47
                    'rule' => ['email', true],
48
                    'message' => __('error_email_not-valid'),
49
                ],
50
            ]);
51
52
        return $validator;
53
    }
54
}
55