CanRestartTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A restartScript() 0 9 2
1
<?php
2
/**
3
 * For the full copyright and license information, please view the LICENSE.md
4
 * file that was distributed with this source code.
5
 */
6
7
namespace Notamedia\ConsoleJedi\Application;
8
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * Trait used for restarting process.
14
 *
15
 * @author Marat Shamshutdinov <[email protected]>
16
 */
17
trait CanRestartTrait
18
{
19
    /**
20
     * Executes another copy of console process to continue updates
21
     *
22
     * We may encounter problems when module update scripts (update.php or update_post.php) requires module files,
23
     * they are included only once and stay in most early version.
24
     * Bitrix update system always run update scripts in separate requests to web-server.
25
     * This ensures the same behavior as in original update system, updates always run on latest module version.
26
     *
27
     * @param InputInterface $input
28
     * @param OutputInterface $output
29
     *
30
     * @return int
31
     */
32
    protected function restartScript(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Unused Code introduced by
The parameter $input is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
restartScript uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
33
    {
34
        $proc = popen('php -f ' . join(' ', $GLOBALS['argv']) . ' 2>&1', 'r');
35
        while (!feof($proc)) {
36
            $output->write(fread($proc, 4096));
37
        }
38
39
        return pclose($proc);
40
    }
41
}