Test Failed
Pull Request — develop (#20)
by Denis
13:48 queued 05:42
created

get_branch_name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
function patch_composer_json(string $branchname): 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' => 'vcs',
20
        'url' => '../',
21
    ]];
22
    $json['require']['artprima/prometheus-metrics-bundle'] = 'dev-'.$branchname;
23
    $json['require-dev'] = (object)$json['require-dev'];
24
    $data = json_encode($json, JSON_PRETTY_PRINT);
25
    if ($data === false) {
26
        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...
27
    }
28
29
    $result = file_put_contents('symfony/composer.json', $data);
30
    if ($result === false) {
31
        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...
32
    }
33
}
34
35
// https://stackoverflow.com/questions/7447472/how-could-i-display-the-current-git-branch-name-at-the-top-of-the-page-of-my-de
36
function get_branch_name(): string
37
{
38
    $stringfromfile = file('.git/HEAD', FILE_USE_INCLUDE_PATH);
39
    $firstLine = $stringfromfile[0]; //get the string from the array
40
    $explodedstring = explode("/", $firstLine, 3); //seperate out by the "/" in the string
41
    $branchname = $explodedstring[2]; //get the one that is always the branch name
42
43
    return $branchname;
44
}
45
46
patch_composer_json(get_branch_name());
47