Command::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
/**
3
 * Part of Cli for CodeIgniter
4
 *
5
 * @author     Kenji Suzuki <https://github.com/kenjis>
6
 * @license    MIT License
7
 * @copyright  2015 Kenji Suzuki
8
 * @link       https://github.com/kenjis/codeigniter-cli
9
 */
10
11
namespace Kenjis\CodeIgniter_Cli\Command;
12
13
use Aura\Cli\Stdio;
14
use Aura\Cli\Context;
15
use CI_Controller;
16
use RuntimeException;
17
18
abstract class Command
19
{
20
    protected $context;
21
    protected $stdio;
22
    protected $ci;
23
    protected $db;
24
    protected $dbforge;
25
26
    public function __construct(Context $context, Stdio $stdio, CI_Controller $ci)
27
    {
28
        $this->context = $context;
29
        $this->stdio = $stdio;
30
        $this->ci = $ci;
31
32
        $this->ci->load->database();
33
        $this->db = $this->ci->db;
34
        $this->ci->load->dbforge();
35
        $this->dbforge = $this->ci->dbforge;
36
    }
37
38
    public function __get($property)
39
    {
40
        if (! property_exists($this->ci, $property)) {
41
            ob_start();
42
            var_dump(debug_backtrace());
0 ignored issues
show
Security Debugging Code introduced by
var_dump(debug_backtrace()); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
43
            $backtrace = ob_get_clean();
44
            file_put_contents(ROOTPATH . '/tmp/backtrace.log', $backtrace, LOCK_EX);
45
            $this->stdio->errln(
46
                '<<red>>No such property: ' . $property . ' in CodeIgniter instance<<reset>>'
47
            );
48
            $this->stdio->errln('Backtrace was saved in tmp/backtrace.log');
49
            throw new RuntimeException('Property does not exist');
50
        }
51
52
        return $this->ci->$property;
53
    }
54
}
55