GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — integration (#2604)
by Brendan
05:28
created

CreateDatabase   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 3
Bugs 1 Features 2
Metric Value
c 3
b 1
f 2
dl 0
loc 78
rs 10
wmc 7
lcom 1
cbo 7

1 Method

Rating   Name   Duplication   Size   Complexity  
C handle() 0 72 7
1
<?php
2
namespace SymphonyCms\Installer\Steps;
3
4
use Author;
5
use Configuration;
6
use Cryptography;
7
use DatabaseException;
8
use Exception;
9
use Symphony;
10
11
class CreateDatabase extends DefaultStep
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function handle(Configuration $config, array $data)
17
    {
18
        // MySQL: Establishing connection
19
        $this->logger->info('MYSQL: Establishing Connection');
20
21
        try {
22
            Symphony::Database()->connect(
23
                $config->get('host', 'database'),
0 ignored issues
show
Bug introduced by
It seems like $config->get('host', 'database') targeting Configuration::get() can also be of type array; however, MySQL::connect() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
24
                $config->get('user', 'database'),
0 ignored issues
show
Bug introduced by
It seems like $config->get('user', 'database') targeting Configuration::get() can also be of type array; however, MySQL::connect() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
25
                $config->get('password', 'database'),
0 ignored issues
show
Bug introduced by
It seems like $config->get('password', 'database') targeting Configuration::get() can also be of type array; however, MySQL::connect() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
26
                $config->get('port', 'database'),
0 ignored issues
show
Bug introduced by
It seems like $config->get('port', 'database') targeting Configuration::get() can also be of type array; however, MySQL::connect() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
27
                $config->get('db', 'database')
28
            );
29
        } catch (DatabaseException $e) {
30
            throw new Exception(
31
                'There was a problem while trying to establish a connection to the MySQL server. Please check your settings.'
32
            );
33
        }
34
35
        if (Symphony::Database()->tableExists($config->get('tbl_prefix', 'database') . '%') && !$this->override) {
36
            $this->logger->error('MYSQL: Database table prefix is already in use. Change prefix or run installation with the `--override` flag.', [
37
                'prefix' => $config->get('tbl_prefix', 'database'),
38
                'db' => $config->get('db', 'database')
39
            ]);
40
41
            return false;
42
        }
43
44
        // MySQL: Setting prefix & importing schema
45
        Symphony::Database()->setPrefix($config->get('tbl_prefix', 'database'));
0 ignored issues
show
Bug introduced by
It seems like $config->get('tbl_prefix', 'database') targeting Configuration::get() can also be of type array; however, MySQL::setPrefix() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
46
        $this->logger->info('MYSQL: Importing Table Schema');
47
48
        try {
49
            Symphony::Database()->import(file_get_contents(INSTALL . '/includes/install.sql'));
50
        } catch (DatabaseException $e) {
51
            throw new Exception(sprintf(
52
                'There was an error while trying to import data to the database. MySQL returned: %s:%s',
53
                $e->getDatabaseErrorCode(),
54
                $e->getDatabaseErrorMessage()
55
            ));
56
        }
57
58
        // MySQL: Creating default author
59
        if (isset($data['user'])) {
60
            $this->logger->info('MYSQL: Creating Default Author');
61
62
            try {
63
                // Clean all the user data.
64
                $userData = array_map([Symphony::Database(), 'cleanValue'], $data['user']);
65
66
                $author = new Author;
67
                $author->set('user_type', 'developer');
68
                $author->set('primary', 'yes');
69
                $author->set('username', $userData['username']);
70
                $author->set('password', Cryptography::hash($userData['password']));
71
                $author->set('first_name', $userData['firstname']);
72
                $author->set('last_name', $userData['lastname']);
73
                $author->set('email', $userData['email']);
74
                $author->commit();
75
            } catch (DatabaseException $e) {
76
                throw new Exception(sprintf(
77
                    'There was an error while trying create the default author. MySQL returned: %s:%s',
78
                    $e->getDatabaseErrorCode(),
79
                    $e->getDatabaseErrorMessage()
80
                ));
81
            }
82
        } else {
83
            $this->logger->info('MYSQL: Skipping Default Author creation');
84
        }
85
86
        return true;
87
    }
88
}
89