AnonymizeCommand::execute()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
nc 3
nop 2
1
<?php
2
/**
3
 * integer_net Magento Module
4
 *
5
 * @category   IntegerNet
6
 * @package    
7
 * @copyright  Copyright (c) 2015 integer_net GmbH (http://www.integer-net.de/)
8
 * @author     Fabian Schmengler <[email protected]>
9
 */
10
11
namespace IntegerNet\Anonymizer;
12
13
use N98\Magento\Command\AbstractMagentoCommand;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
use Symfony\Component\Console\Output\StreamOutput;
17
18
class AnonymizeCommand extends AbstractMagentoCommand
19
{
20
    protected function configure()
21
    {
22
        $this
23
            ->setName('db:anonymize')
24
            ->setDescription('Anonymize customer data');
25
    }
26
27
    /**
28
     * @param \Symfony\Component\Console\Input\InputInterface $input
29
     * @param \Symfony\Component\Console\Output\OutputInterface $output
30
     * @return int|void
31
     */
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        $this->detectMagento($output, true);
35
        if ($this->initMagento()) {
36
            $this->registerPsr0Autoloader();
37
            /** @var \IntegerNet_Anonymizer_Model_Anonymizer $anonymizer */
38
            $anonymizer = \Mage::getModel('integernet_anonymizer/anonymizer');
39
            if ($output instanceof StreamOutput) {
0 ignored issues
show
Bug introduced by
The class Symfony\Component\Console\Output\StreamOutput does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
40
                $anonymizer->setOutputStream($output->getStream());
41
            } else {
42
                //TODO allow OutputInterface in Anonymizer?
43
                //TODO pass ansi/no-ansi configuration to Anonymizer and use colors
44
                ob_start();
45
                $anonymizer->setOutputStream(STDOUT);
0 ignored issues
show
Documentation introduced by
STDOUT is of type string, but the function expects a resource.

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...
46
                $output->write(ob_get_clean());
47
            }
48
            $anonymizer->anonymizeAll();
49
        }
50
    }
51
    private function registerPsr0Autoloader()
52
    {
53
        \Mage::getConfig()->init()->loadEventObservers('global');
54
        \Mage::app()->addEventArea('global');
55
        \Mage::dispatchEvent('add_spl_autoloader');
56
    }
57
}