Passed
Push — master ( a2e26c...517afa )
by Théo
03:09
created

JsonFileScoper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A scope() 0 18 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the humbug/php-scoper package.
7
 *
8
 * Copyright (c) 2017 Théo FIDRY <[email protected]>,
9
 *                    Pádraic Brady <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Humbug\PhpScoper\Scoper\Composer;
16
17
use Humbug\PhpScoper\Scoper;
18
19
final class JsonFileScoper implements Scoper
20
{
21
    private $decoratedScoper;
22
23 2
    public function __construct(Scoper $decoratedScoper)
24
    {
25 2
        $this->decoratedScoper = $decoratedScoper;
26 2
    }
27
28
    /**
29
     * Scopes PHP and JSON files related to Composer.
30
     *
31
     * {@inheritdoc}
32
     */
33 2
    public function scope(string $filePath, string $prefix): string
34
    {
35 2
        if (1 !== preg_match('/composer\.json$/', $filePath)) {
36 1
            return $this->decoratedScoper->scope($filePath, $prefix);
37
        }
38
39 1
        $decodedJson = json_decode(
40
            file_get_contents($filePath),
41 1
            true
42
        );
43
44 1
        $decodedJson = AutoloadPrefixer::prefixPackageAutoloads($decodedJson, $prefix);
45
46 1
        return json_encode(
47
            $decodedJson,
48 1
            JSON_PRETTY_PRINT
49
        );
50
    }
51
}
52