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

CreateHtaccess   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 3
Bugs 1 Features 2
Metric Value
c 3
b 1
f 2
dl 0
loc 37
rs 10
wmc 5
lcom 1
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 31 5
1
<?php
2
namespace SymphonyCms\Installer\Steps;
3
4
use Configuration;
5
use Exception;
6
use General;
7
8
class CreateHtaccess extends DefaultStep
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13
    public function handle(Configuration $config, array $data)
0 ignored issues
show
Coding Style introduced by
handle uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
14
    {
15
        // Writing htaccess file
16
        $this->logger->info('CONFIGURING: Apache Rewrite Rules');
17
18
        if (APP_MODE === 'console') {
19
            $rewrite_base = basename(DOCROOT);
20
        } else {
21
            $rewrite_base = ltrim(preg_replace('/\/install$/i', null, dirname($_SERVER['PHP_SELF'])), '/');
22
        }
23
24
        $htaccess = str_replace(
25
            '<!-- REWRITE_BASE -->',
26
            $rewrite_base,
27
            file_get_contents(INSTALL . '/includes/htaccess.txt')
28
        );
29
30
        // If the step can override, replace the entire .htaccess file.
31
        if (file_exists(DOCROOT . "/.htaccess") && $this->override) {
32
            $this->logger->info('CONFIGURING: Replacing existing .htaccess file');
33
            $file_mode = 'w';
34
        } else {
35
            $file_mode = 'a';
36
        }
37
38
        if (!General::writeFile(DOCROOT . "/.htaccess", $htaccess, $config->get('write_mode', 'file'), $file_mode)) {
0 ignored issues
show
Documentation introduced by
$config->get('write_mode', 'file') is of type array|string, but the function expects a integer.

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...
39
            throw new Exception('Could not write ‘.htaccess’ file. Check permission on ' . DOCROOT);
40
        }
41
42
        return true;
43
    }
44
}
45