Composer::installBinaries()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 20
rs 8.8571
cc 5
eloc 14
nc 5
nop 1
1
<?php
2
3
namespace AppBundle;
4
5
use Composer\Script\CommandEvent;
6
7
class Composer
8
{
9
    public static function misc(CommandEvent $event)
10
    {
11
        self::spacingParametersYml($event);
12
        self::installBinaries($event);
13
    }
14
15
    private static function installBinaries(CommandEvent $event)
16
    {
17
        if (!is_dir('bin')) {
18
            $event->getIO()->write(sprintf('The "bin" directory was not found in %s.', getcwd()));
19
            return;
20
        }
21
        foreach (glob('app/Resources/bin/*') as $binary) {
22
            $src = '../app/Resources/bin/' . basename($binary);
23
            $dst = $dst = 'bin/' . basename($binary);
24
            @unlink($dst);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
25
            if (@symlink($src, $dst) === false) {
26
                if (!file_exists($dst)) {
27
                    $event->getIO()->write(sprintf('Failed to symlink %s from %s.', $src, $dst));
28
                    return;
29
                }
30
                continue;
31
            }
32
            $event->getIO()->write(sprintf('Installed binary %s.', $dst));
33
        }
34
    }
35
36
    private static function spacingParametersYml(CommandEvent $event)
37
    {
38
        if (!file_exists($file = 'vendor/incenteev/composer-parameter-handler/Processor.php')) {
39
            return;
40
        }
41
42
        $content = file_get_contents($file);
43
        $matches = 0;
44
        $content = str_replace('Yaml::dump($actualValues, 99)', 'Yaml::dump($actualValues, 99, 2)', $content, $matches);
45
        if ($matches) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $matches of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
46
            file_put_contents($file, $content, LOCK_EX);
47
            $event->getIO()->write('Updated spacing for incenteev parameters');
48
        }
49
    }
50
}
51