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.
Failed Conditions
Push — develop ( 644c7b...00ace3 )
by Maxime
05:13
created

Filesystem/ConnectionKeyAdapterFactory.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of Rocketeer
5
 *
6
 * (c) Maxime Fabre <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 */
12
13
namespace Rocketeer\Services\Filesystem;
14
15
use League\Flysystem\Adapter\Ftp;
16
use League\Flysystem\AdapterInterface;
17
use League\Flysystem\Sftp\SftpAdapter;
18
use Rocketeer\Services\Connections\Credentials\Keys\ConnectionKey;
19
20
/**
21
 * Creates the correct Flysystem adapter according
22
 * to a ConnectionKey instance.
23
 */
24
class ConnectionKeyAdapterFactory
25
{
26
    /**
27
     * @param ConnectionKey $connectionKey
28
     *
29
     * @return AdapterInterface
30
     */
31 7
    public function getAdapter(ConnectionKey $connectionKey)
0 ignored issues
show
getAdapter 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...
32
    {
33 7
        $adapter = $connectionKey->isFtp() ? Ftp::class : SftpAdapter::class;
34
35 7
        return new $adapter([
36 7
            'host' => $connectionKey->host,
37 7
            'username' => $connectionKey->username,
38 7
            'password' => $connectionKey->password,
39 7
            'privateKey' => $connectionKey->key,
40 7
            'useAgent' => (bool) $connectionKey->agent && isset($_SERVER['SSH_AUTH_SOCK']),
41 7
            'root' => '/',
42 7
            'timeout' => 60 * 60,
43 7
        ]);
44
    }
45
}
46