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

VarDirectoryChecker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 6 1
A checkForVarDirectoryProblem() 0 20 3
1
<?php
2
3
namespace N98\Magento\Application\Console\EventSubscriber;
4
5
use Symfony\Component\Console\ConsoleEvents;
6
use Symfony\Component\Console\Event\ConsoleCommandEvent;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
10
/**
11
 * Class VarDirectoryChecker
12
 * @package N98\Magento\Application\Console\EventSubscriber
13
 */
14
class VarDirectoryChecker implements EventSubscriberInterface
15
{
16
    /**
17
     * Returns an array of event names this subscriber wants to listen to.
18
     *
19
     * @return array The event names to listen to
20
     *
21
     * @api
22
     */
23
    public static function getSubscribedEvents()
24
    {
25
        return [
26
            ConsoleEvents::COMMAND => 'checkForVarDirectoryProblem',
27
        ];
28
    }
29
30
    /**
31
     * @param ConsoleCommandEvent $event
32
     * @return bool
33
     */
34
    public function checkForVarDirectoryProblem(ConsoleCommandEvent $event): bool
35
    {
36
        $tempVarDir = sys_get_temp_dir() . '/magento/var';
37
38
        if ((!OutputInterface::VERBOSITY_NORMAL) <= $event->getOutput()->getVerbosity() && !is_dir($tempVarDir)) {
39
            return true;
40
        }
41
42
        $event->getOutput()->writeln([
0 ignored issues
show
Documentation introduced by
array(sprintf('<warning>...more information.', '') is of type array<integer,string,{"0..."string","4":"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...
43
            sprintf('<warning>Cache fallback folder %s was found.</warning>', $tempVarDir),
44
            '',
45
            'n98-magerun2 is using the fallback folder. If there is another folder configured for Magento, this ' .
46
            'can cause serious problems.',
47
            'Please refer to https://github.com/netz98/n98-magerun/wiki/File-system-permissions ' .
48
            'for more information.',
49
            '',
50
        ]);
51
52
        return false;
53
    }
54
}
55