Completed
Pull Request — master (#333)
by Nikola
02:33
created

CacheWarmupCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
/*
3
 * Go! AOP framework
4
 *
5
 * @copyright Copyright 2013, Lisachenko Alexander <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Go\Console\Command;
12
13
use Go\Instrument\ClassLoading\CacheWarmer;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
/**
18
 * Console command for warming the cache
19
 *
20
 * @codeCoverageIgnore
21
 */
22
class CacheWarmupCommand extends BaseAspectCommand
23
{
24
25
    /**
26
     * {@inheritDoc}
27
     */
28
    protected function configure()
29
    {
30
        parent::configure();
31
        $this
32
            ->setName('cache:warmup:aop')
33
            ->setDescription("Warm up the cache with woven aspects")
34
            ->setHelp(<<<EOT
35
Initializes the kernel and, if successful, warm up the cache for PHP
36
files under the application directory.
37
38
By default, the cache directory is taken from configured AspectKernel class.
39
EOT
40
            );
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     */
46
    protected function execute(InputInterface $input, OutputInterface $output)
47
    {
48
        $this->loadAspectKernel($input, $output);
49
50
        $warmer = new CacheWarmer($this->aspectKernel, $output);
0 ignored issues
show
Bug introduced by
It seems like $this->aspectKernel can be null; however, __construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
51
        $warmer->warmUp();
52
    }
53
}
54