Completed
Push — master ( fd5325...d7e193 )
by Schlaefer
05:54 queued 03:00
created

UpdaterStartForm::_buildValidator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
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 Installer\Form;
14
15
use Cake\Datasource\ConnectionManager;
16
use Cake\Form\Form;
17
use Cake\Form\Schema;
18
use Cake\Validation\Validator;
19
20
class UpdaterStartForm extends Form
21
{
22
    /**
23
     * {@inheritDoc}
24
     */
25
    protected function _buildSchema(Schema $schema)
26
    {
27
        return $schema
28
            ->addField('dbname', ['type' => 'string'])
29
            ->addField('dbpassword', ['type' => 'password']);
30
    }
31
32
    /**
33
     * {@inheritDoc}
34
     */
35
    protected function _buildValidator(Validator $validator)
36
    {
37
        $validator
0 ignored issues
show
Deprecated Code introduced by
The method Cake\Validation\Validator::notEmpty() has been deprecated with message: 3.7.0 Use notEmptyString(), notEmptyArray(), notEmptyFile(), notEmptyDate(), notEmptyTime() or notEmptyDateTime() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
38
            ->requirePresence('dbname')
39
            ->notEmpty('dbname')
40
            ->add('dbname', 'custom', [
41
                'rule' => [$this, 'validateDbName'],
42
            ])
43
            ->requirePresence('dbpassword')
44
            ->notEmpty('dbpassword')
45
            ->add('dbpassword', 'custom', [
46
                'rule' => [$this, 'validateDbPassword'],
47
            ]);
48
49
        return $validator;
50
    }
51
52
    /**
53
     * validate database-name
54
     *
55
     * @param string $data database-name
56
     * @return bool
57
     */
58
    public function validateDbName($data): bool
59
    {
60
        $connection = ConnectionManager::get('default');
61
        $dbConfig = $connection->config();
62
63
        return $data === $dbConfig['database'];
64
    }
65
66
    /**
67
     * validate database-password
68
     *
69
     * @param string $data database-password
70
     * @return bool
71
     */
72
    public function validateDbPassword($data): bool
73
    {
74
        $connection = ConnectionManager::get('default');
75
        $dbConfig = $connection->config();
76
77
        return $data === $dbConfig['password'];
78
    }
79
}
80