|
14 | 14 |
|
15 | 15 | namespace Humbug\PhpScoper\Scoper\Composer; |
16 | 16 |
|
17 | | -use function array_key_exists; |
| 17 | +use stdClass; |
18 | 18 |
|
19 | 19 | /** |
20 | 20 | * @private |
21 | 21 | */ |
22 | 22 | final class AutoloadPrefixer |
23 | 23 | { |
24 | 24 | /** |
25 | | - * @param array $contents Decoded JSON |
26 | | - * @param string $prefix |
| 25 | + * @param stdClass $contents Decoded JSON |
| 26 | + * @param string $prefix |
27 | 27 | * |
28 | 28 | * @return array Prefixed decoded JSON |
29 | 29 | */ |
30 | | - public static function prefixPackageAutoloads(array $contents, string $prefix): array |
| 30 | + public static function prefixPackageAutoloads(stdClass $contents, string $prefix): stdClass |
31 | 31 | { |
32 | | - if (isset($contents['autoload'])) { |
33 | | - $contents['autoload'] = self::prefixAutoloads($contents['autoload'], $prefix); |
| 32 | + if (isset($contents->autoload)) { |
| 33 | + $contents->autoload = self::prefixAutoloads($contents->autoload, $prefix); |
34 | 34 | } |
35 | 35 |
|
36 | | - if (isset($contents['autoload-dev'])) { |
37 | | - $contents['autoload-dev'] = self::prefixAutoloads($contents['autoload-dev'], $prefix); |
| 36 | + if (isset($contents->{'autoload-dev'})) { |
| 37 | + $contents->{'autoload-dev'} = self::prefixAutoloads($contents->{'autoload-dev'}, $prefix); |
38 | 38 | } |
39 | 39 |
|
40 | 40 | return $contents; |
41 | 41 | } |
42 | 42 |
|
43 | | - private static function prefixAutoloads(array $autoload, string $prefix): array |
| 43 | + private static function prefixAutoloads(stdClass $autoload, string $prefix): stdClass |
44 | 44 | { |
45 | | - if (false === array_key_exists('psr-4', $autoload) && false === array_key_exists('psr-0', $autoload)) { |
| 45 | + if (false === isset($autoload->{'psr-4'}) && false === isset($autoload->{'psr-0'})) { |
46 | 46 | return $autoload; |
47 | 47 | } |
48 | 48 |
|
49 | | - if (isset($autoload['psr-0'])) { |
50 | | - $autoload['psr-4'] = self::mergePSR0And4($autoload['psr-0'], $autoload['psr-4'] ?? []); |
| 49 | + if (isset($autoload->{'psr-0'})) { |
| 50 | + $autoload->{'psr-4'} = self::mergePSR0And4( |
| 51 | + (array) $autoload->{'psr-0'}, |
| 52 | + (array) ($autoload->{'psr-4'} ?? new stdClass()) |
| 53 | + ); |
51 | 54 | } |
52 | | - unset($autoload['psr-0']); |
| 55 | + unset($autoload->{'psr-0'}); |
53 | 56 |
|
54 | | - if (isset($autoload['psr-4'])) { |
55 | | - $autoload['psr-4'] = self::prefixAutoload($autoload['psr-4'], $prefix); |
| 57 | + if (isset($autoload->{'psr-4'})) { |
| 58 | + $autoload->{'psr-4'} = self::prefixAutoload((array) $autoload->{'psr-4'}, $prefix); |
56 | 59 | } |
57 | 60 |
|
58 | 61 | return $autoload; |
|
0 commit comments