Completed
Push — master ( 3260ca...0c0ec5 )
by Christian
02:12
created

CheckCompatibility::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace N98\Magento\Application\Console\EventSubscriber;
4
5
use N98\Magento\Application;
6
use N98\Magento\Application\ApplicationAwareInterface;
7
use N98\Magento\Application\Console\Event;
8
use N98\Magento\Application\Console\Events;
9
use Symfony\Component\Console\Event\ConsoleEvent;
10
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11
12
/**
13
 * Class CheckCompatibility
14
 * @package N98\Magento\Application\Console\EventSubscriber
15
 */
16
class CheckCompatibility implements EventSubscriberInterface, ApplicationAwareInterface
17
{
18
    /**
19
     * @var Application
20
     */
21
    private $application;
22
23
    /**
24
     * Returns an array of event names this subscriber wants to listen to.
25
     *
26
     * @return array The event names to listen to
27
     *
28
     * @api
29
     */
30
    public static function getSubscribedEvents()
31
    {
32
        return [
33
            Events::RUN_BEFORE => 'checkCompatibility',
34
        ];
35
    }
36
37
    /**
38
     * Display a warning if a running n98-magerun as root user
39
     *
40
     * @param ConsoleEvent $event
41
     * @return void
42
     */
43
    public function checkCompatibility(ConsoleEvent $event)
44
    {
45
        try {
46
            $this->application->initMagento(true);
47
            $objectManager = $this->application->getObjectManager();
48
            if (!$objectManager) {
49
                return;
50
            }
51
52
            $productMetadata = $objectManager->get(\Magento\Framework\App\ProductMetadataInterface::class);
53
54
            $currentMagentoVersion = $productMetadata->getVersion();
55
            if (version_compare($currentMagentoVersion, '2.3.0', '<')) {
56
                $output = $event->getOutput();
57
                $output->writeln([
0 ignored issues
show
Documentation introduced by
array('', '<error>You ar...gerun2 v2.3.3', '', '') is of type array<integer,string,{"0...string","17":"string"}>, but the function expects a string|object<Symfony\Co...onsole\Output\iterable>.

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...
58
                    '',
59
                    '<error>You are running an incompatible version of n98-magerun2!</error>',
60
                    '<error>Your shop version has to be >2.3.0</error>',
61
                    '',
62
                    '',
63
                    '<comment>Current Magento Version     : ' . $currentMagentoVersion . '</comment>',
64
                    '<comment>Current n98-magerun2 Version: ' . $this->application->getVersion() . '</comment>',
65
                    '',
66
                    '',
67
                    '<info>Please download an older version of n98-magerun2.</info>',
68
                    '',
69
                    '<info>Visit: https://files.magerun.net/old_versions.php</info>',
70
                    '',
71
                    '    Magento 2.2.x => n98-magerun2 v3.2.0',
72
                    '    Magento 2.1.x => n98-magerun2 v3.2.0',
73
                    '    Magento 2.0.x => n98-magerun2 v2.3.3',
74
                    '',
75
                    '',
76
                ]);
77
78
                exit(1);
79
            }
80
        } catch (\Exception $e) {
81
            //
82
        }
83
    }
84
85
    public function setApplication($application)
86
    {
87
        $this->application = $application;
88
    }
89
}
90