Failed Conditions
Pull Request — develop (#20)
by Denis
14:06 queued 04:26
created

patch_composer_json()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 29
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 5
eloc 20
c 4
b 0
f 0
nc 5
nop 0
dl 0
loc 29
rs 9.2888
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
    $json['prefer-stable'] = true;
26
    $data = json_encode($json, JSON_PRETTY_PRINT);
27
    if ($data === false) {
28
        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...
29
    }
30
31
    $result = file_put_contents('symfony/composer.json', $data);
32
    if ($result === false) {
33
        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...
34
    }
35
}
36
37
patch_composer_json();
38