Test Failed
Pull Request — develop (#20)
by Denis
08:57 queued 01:13
created

patch_composer_json()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 5
eloc 19
c 3
b 0
f 0
nc 5
nop 0
dl 0
loc 28
rs 9.3222
1
<?php
2
3
declare(strict_types=1);
4
5
function patch_composer_json(): void
6
{
7
    if (!file_exists('symfony/composer.json')) {
8
        echo 'symfony/composer.json not found!'.PHP_EOL;
9
        exit(-1);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
10
    }
11
12
    $contents = file_get_contents('symfony/composer.json');
13
    if ($contents === false) {
14
        exit(-1);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
15
    }
16
17
    $json = json_decode($contents, true);
18
    $json['repositories'] = [[
19
        'type' => 'path',
20
        'url' => '../',
21
    ]];
22
    $json['require']['artprima/prometheus-metrics-bundle'] = '*';
23
    $json['require-dev'] = (object)$json['require-dev'];
24
    $json['minimum-stability'] = 'dev';
25
    $data = json_encode($json, JSON_PRETTY_PRINT);
26
    if ($data === false) {
27
        exit(-1);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
28
    }
29
30
    $result = file_put_contents('symfony/composer.json', $data);
31
    if ($result === false) {
32
        exit(-1);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
33
    }
34
}
35
36
patch_composer_json();
37