Completed
Push — master ( 5da224...d5db9d )
by Greg
02:47
created

scripts/composer/ScriptHandler.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * @file
5
 * Contains \Robo\composer\ScriptHandler.
6
 */
7
8
namespace Robo\composer;
9
10
use Composer\Script\Event;
11
use Symfony\Component\Filesystem\Filesystem;
12
13
class ScriptHandler
14
{
15
16
    /**
17
     * Run prior to `composer installl` when a composer.lock is present.
18
     * @param Event $event
19
     */
20
    public static function checkDependencies(Event $event)
0 ignored issues
show
The parameter $event 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...
21
    {
22
        if (version_compare(PHP_VERSION, '5.6.0') < 0) {
23
            static::checkDependenciesFor55();
24
        }
25
    }
26
27
    /**
28
     * Check to see if the dependencies in composer.lock are compatible
29
     * with php 5.5.
30
     */
31
    protected static function checkDependenciesFor55()
32
    {
33
        $fs = new Filesystem();
34
        if (!$fs->exists('composer.lock')) {
35
            return;
36
        }
37
38
        $composerLockContents = file_get_contents('composer.lock');
39
        if (preg_match('#"php":.*(5\.6)#', $composerLockContents)) {
40
            static::fixDependenciesFor55();
41
        }
42
    }
43
44
    protected static function fixDependenciesFor55()
45
    {
46
        $fs = new Filesystem();
47
        $status = 0;
48
49
        $fs->remove('composer.lock');
50
51
        // Composer has already read our composer.json file, so we will
52
        // need to run in a new process to fix things up.
53
        passthru('composer install --ansi', $status);
54
55
        // Don't continue with the initial 'composer install' command
56
        exit($status);
0 ignored issues
show
Coding Style Compatibility introduced by
The method fixDependenciesFor55() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
57
    }
58
}
59