LegacyAdapter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 55
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B attach() 0 35 2
1
<?php
2
namespace Buttress\Concrete\Client\Adapter;
3
4
use Buttress\Concrete\Client\Connection\LegacyConnection;
5
use Buttress\Concrete\Console\Console;
6
use Buttress\Concrete\Exception\VersionMismatchException;
7
use Buttress\Concrete\Locator\Site;
8
9
/**
10
 * An adapter that connects to legacy concrete5 sites
11
 * @todo Determine the lowest version of c5 we support
12
 */
13
class LegacyAdapter implements Adapter
14
{
15
16
    /** @var \Buttress\Concrete\Locator\Site $site */
17
    protected $site;
18
19
    /** @var \Buttress\Concrete\Console\Console */
20
    protected $console;
21
22
    public function __construct(Site $site, Console $console)
23
    {
24
        $this->site = $site;
25
        $this->console = $console;
26
    }
27
28
    /**
29
     * Attach to legacy concrete5
30
     * @throws \Buttress\Concrete\Exception\VersionMismatchException
31
     */
32
    public function attach()
0 ignored issues
show
Coding Style introduced by
attach uses the super-global variable $GLOBALS 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...
33
    {
34
        // If the version number is more than 5.6.999, we have the wrong version.
35
        if (version_compare(PHP_VERSION, '5.6.999') > 0) {
36
            throw new VersionMismatchException('Legacy versions of concrete5 do not support PHP 7!', PHP_VERSION);
37
        }
38
39
        // Get the site path
40
        $path = $this->site->getPath();
41
42
        // Change the cwd to the site path
43
        chdir($path);
44
45
        // Define a couple things concrete5 expects
46
        define('DIR_BASE', $path);
47
        define('C5_ENVIRONMENT_ONLY', true);
48
49
        // Set the error reporting low
50
        error_reporting(E_ALL | ~E_NOTICE | ~E_WARNING | ~E_STRICT);
51
52
        // Include Adodb first, not sure why this was needed
53
        require_once $path . '/concrete/libraries/3rdparty/adodb/adodb.inc.php';
54
55
        // Load in legacy dispatcher
56
        require_once $path . '/concrete/dispatcher.php';
57
58
        $this->console->registerErrorHandler();
59
60
        // Adodb Stuff
61
        $GLOBALS['ADODB_ASSOC_CASE'] = 2;
62
        $GLOBALS['ADODB_ACTIVE_CACHESECS'] = 300;
63
        $GLOBALS['ADODB_CACHE_DIR'] = DIR_FILES_CACHE_DB;
64
65
        return new LegacyConnection();
66
    }
67
}
68