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

ConsoleInstaller   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 112
Duplicated Lines 2.68 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 3
loc 112
rs 10
wmc 8
lcom 1
cbo 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A setOverride() 0 6 1
B install() 3 37 5
A bootstrap() 0 20 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace SymphonyCms\Installer\Lib;
4
5
use Configuration;
6
use DateTimeObj;
7
use Exception;
8
use Lang;
9
use Psr\Log\LoggerInterface;
10
use Symphony;
11
use SymphonyCms\Installer\Steps;
12
13
class ConsoleInstaller
14
{
15
    /**
16
     * @var LoggerInterface
17
     */
18
    protected $logger;
19
20
    /**
21
     * @var Configuration
22
     */
23
    protected $configuration;
24
25
    /**
26
     * @var bool
27
     */
28
    protected $overwrite = false;
29
30
    /**
31
     * @param LoggerInterface $logger
32
     * @param Configuration $configuration
33
     */
34
    public function __construct(LoggerInterface $logger, Configuration $configuration)
35
    {
36
        $this->logger = $logger;
37
        $this->configuration = $configuration;
38
39
        // Symphony expects a couple of constants to always exist, so lets do a basic bootstrap.
40
        $this->bootstrap();
41
    }
42
43
    /**
44
     * Allow the Installer and it's steps to attempt to install Symphony at all costs,
45
     * including removing and deleting existing data. Use with caution.
46
     *
47
     * @param bool $overwrite
48
     * @return $this
49
     */
50
    public function setOverride($overwrite = false)
51
    {
52
        $this->overwrite = $overwrite;
53
54
        return $this;
55
    }
56
57
    /**
58
     * Installs Symphony using the configuration information available.
59
     *
60
     * @param array $data
61
     * @return bool
62
     */
63
    public function install(array $data)
64
    {
65
        $steps = [
66
            // Create database
67
            Steps\CreateDatabase::class,
68
            // Create manifest folder structure
69
            Steps\CreateManifest::class,
70
            // Write .htaccess
71
            Steps\CreateHtaccess::class,
72
            // Create or import the workspace
73
            Steps\Workspace::class,
74
            // Enable extensions
75
            Steps\EnableExtensions::class
76
        ];
77
78
        try {
79
            foreach ($steps as $step) {
80
                $installStep = new $step($this->logger);
81
                $installStep->setOverride($this->overwrite);
82
83 View Code Duplication
                if (false === $installStep->handle($this->configuration, $data)) {
84
                    throw new Exception(sprintf('Aborting installation, %s step failed.', $step));
85
                }
86
            }
87
        } catch (Exception $ex) {
88
            $this->logger->error($ex->getMessage());
89
            return false;
90
        }
91
92
        if (false === Symphony::Configuration()->write(CONFIG, $this->configuration->get('write_mode', 'file'))) {
0 ignored issues
show
Documentation introduced by
$this->configuration->get('write_mode', 'file') is of type array|string, but the function expects a integer|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
93
            $this->logger->error('Could not create config file ‘' . CONFIG . '’. Check permission on /manifest.');
94
            return false;
95
        }
96
97
        $this->logger->info('Symphony has been installed.');
98
        return true;
99
    }
100
101
    /**
102
     * Bootstrap the environment to the bare minimum for Symphony to 'run'.
103
     */
104
    private function bootstrap()
105
    {
106
        // Initialize date/time
107
        define_safe('__SYM_DATE_FORMAT__', $this->configuration->get('date_format', 'region'));
0 ignored issues
show
Bug introduced by
It seems like $this->configuration->ge...date_format', 'region') targeting Configuration::get() can also be of type array; however, define_safe() 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...
108
        define_safe('__SYM_TIME_FORMAT__', $this->configuration->get('time_format', 'region'));
0 ignored issues
show
Bug introduced by
It seems like $this->configuration->ge...time_format', 'region') targeting Configuration::get() can also be of type array; however, define_safe() 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...
109
        define_safe(
110
            '__SYM_DATETIME_FORMAT__',
111
            __SYM_DATE_FORMAT__ . $this->configuration->get('datetime_separator', 'region') . __SYM_TIME_FORMAT__
112
        );
113
        DateTimeObj::setSettings($this->configuration->get('region'));
0 ignored issues
show
Bug introduced by
It seems like $this->configuration->get('region') targeting Configuration::get() can also be of type string; however, DateTimeObj::setSettings() does only seem to accept array, 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...
114
115
        Lang::initialize();
116
        Symphony::setDatabase();
117
        Symphony::initialiseExtensionManager();
118
        Symphony::initialiseConfiguration($this->configuration->get());
0 ignored issues
show
Bug introduced by
It seems like $this->configuration->get() targeting Configuration::get() can also be of type string; however, Symphony::initialiseConfiguration() does only seem to accept array, 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...
119
120
        define('INSTALL', DOCROOT . '/install');
121
        define('INSTALL_LOGS', MANIFEST . '/logs');
122
        define('INSTALL_URL', URL . '/install');
123
    }
124
}
125