UpdaterStartForm::validateDbName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 10
c 1
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 function Cake\Validation\Validator::notEmpty() has been deprecated: 3.7.0 Use notEmptyString(), notEmptyArray(), notEmptyFile(), notEmptyDate(), notEmptyTime() or notEmptyDateTime() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

37
        /** @scrutinizer ignore-deprecated */ $validator

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

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

Loading history...
38
            ->requirePresence('dbname')
39
            ->notEmpty('dbname')
40
            ->add('dbname', 'custom', [
41
                'rule' => [$this, 'validateDbName'],
42
            ]);
43
44
        $validator
0 ignored issues
show
Deprecated Code introduced by
The function Cake\Validation\Validator::allowEmpty() has been deprecated: 3.7.0 Use allowEmptyString(), allowEmptyArray(), allowEmptyFile(), allowEmptyDate(), allowEmptyTime() or allowEmptyDateTime() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

44
        /** @scrutinizer ignore-deprecated */ $validator

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

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

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