Test Setup Failed
Push — master ( 4706b6...910f0d )
by Josh
04:46
created

BaseCommand::getRunStats()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: joshgulledge
5
 * Date: 2/15/18
6
 * Time: 2:21 PM
7
 */
8
9
namespace LCI\Blend\Console;
10
11
use modX;
0 ignored issues
show
Bug introduced by
The type modX was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use LCI\Blend\Blender;
13
use LCI\MODX\Console\Command\BaseCommand as Command;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
/**
18
 * Class BaseCommand
19
 *
20
 * @package LCI\Blend\Console\BaseCommand
21
 */
22
abstract class BaseCommand extends Command
23
{
24
    /** @var \modX $modx */
25
    protected $modx;
26
27
    /** @var \LCI\Blend\Blender */
28
    protected $blender;
29
30
    protected $loadMODX = true;
31
32
    /**
33
     * Initializes the command just after the input has been validated.
34
     *
35
     * This is mainly useful when a lot of commands extends one main command
36
     * where some things need to be initialized based on the input arguments and options.
37
     *
38
     * @param InputInterface  $input  An InputInterface instance
39
     * @param OutputInterface $output An OutputInterface instance
40
     */
41
    public function initialize(InputInterface $input, OutputInterface $output)
42
    {
43
        parent::initialize($input, $output);
44
45
        if ($this->loadMODX) {
46
            $this->modx = $this->console->loadMODX();
47
48
            $this->blender = new Blender(
49
                $this->modx,
50
                $this->consoleUserInteractionHandler,
51
                [
52
                    // @TODO rename:
53
                    'blend_modx_migration_dir' => BLEND_MY_MIGRATION_PATH,
0 ignored issues
show
Bug introduced by
The constant LCI\Blend\Console\BLEND_MY_MIGRATION_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
54
                ]
55
            );
56
        }
57
58
59
    }
60
61
    // @TODO remove
62
    public function loadModxInstall()
63
    {
64
        /* to validate installation, instantiate the modX class and run a few tests */
65
        if (include_once (M_CORE_PATH . 'model/modx/modx.class.php')) {
0 ignored issues
show
Bug introduced by
The constant LCI\Blend\Console\M_CORE_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
66
            $modx = new modX(M_CORE_PATH . 'config/', [
67
                \xPDO::OPT_SETUP => true,
0 ignored issues
show
Bug introduced by
The type xPDO was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
68
            ]);
69
70
            if (!is_object($modx) || !($modx instanceof modX)) {
71
                $errors[] = '<p>'.$this->lexicon('modx_err_instantiate').'</p>';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$errors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $errors = array(); before regardless.
Loading history...
Bug introduced by
The method lexicon() does not exist on LCI\Blend\Console\BaseCommand. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
                $errors[] = '<p>'.$this->/** @scrutinizer ignore-call */ lexicon('modx_err_instantiate').'</p>';

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
            } else {
73
                $modx->setLogTarget(array(
74
                    'target' => 'FILE',
75
                    'options' => array(
76
                        'filename' => 'install.' . MODX_CONFIG_KEY . '.' . strftime('%Y%m%dT%H%M%S') . '.log'
0 ignored issues
show
Bug introduced by
The constant LCI\Blend\Console\MODX_CONFIG_KEY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
77
                    )
78
                ));
79
80
                /* try to initialize the mgr context */
81
                $modx->initialize('mgr');
82
                if (!$modx->isInitialized()) {
83
                    $errors[] = '<p>'.$this->lexicon('modx_err_instantiate_mgr').'</p>';
84
                }
85
            }
86
        } else {
87
            $errors[] = '<p>'.$this->lexicon('modx_class_err_nf').'</p>';
88
        }
89
    }
90
}
91