1010use SonsOfPHP \Bard \Worker \File \Composer \Package \BranchAlias ;
1111use SonsOfPHP \Bard \Worker \File \Composer \Package \Funding ;
1212use SonsOfPHP \Bard \Worker \File \Composer \Package \Support ;
13+ use SonsOfPHP \Bard \Worker \File \Composer \Root \ClearSection ;
1314use SonsOfPHP \Bard \Worker \File \Composer \Root \UpdateAutoloadDevSection ;
1415use SonsOfPHP \Bard \Worker \File \Composer \Root \UpdateAutoloadSection ;
1516use SonsOfPHP \Bard \Worker \File \Composer \Root \UpdateProvideSection ;
1617use SonsOfPHP \Bard \Worker \File \Composer \Root \UpdateReplaceSection ;
1718use SonsOfPHP \Bard \Worker \File \Composer \Root \UpdateRequireDevSection ;
1819use SonsOfPHP \Bard \Worker \File \Composer \Root \UpdateRequireSection ;
19- use SonsOfPHP \Component \Json \Json ;
2020use Symfony \Component \Console \Helper \HelperInterface ;
2121use Symfony \Component \Console \Input \InputArgument ;
2222use Symfony \Component \Console \Input \InputInterface ;
3131 */
3232final class MergeCommand extends AbstractCommand
3333{
34- private readonly Json $ json ;
35-
36- private array $ bardConfig ;
34+ private JsonFile $ bardConfig ;
3735
3836 private string $ mainComposerFile ;
3937
4038 private ?HelperInterface $ formatter = null ;
4139
42- public function __construct ()
43- {
44- $ this ->json = new Json ();
45-
46- parent ::__construct ();
47- }
48-
4940 protected function configure (): void
5041 {
5142 $ this
@@ -63,9 +54,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
6354 throw new RuntimeException (sprintf ('"%s" file does not exist ' , $ bardConfigFile ));
6455 }
6556
66- $ this ->bardConfig = $ this ->json ->getDecoder ()
67- ->objectAsArray ()
68- ->decode (file_get_contents ($ bardConfigFile ));
57+ $ this ->bardConfig = new JsonFile ($ bardConfigFile );
6958
7059 $ this ->mainComposerFile = $ input ->getOption ('working-dir ' ) . '/composer.json ' ;
7160 if (!file_exists ($ this ->mainComposerFile )) {
@@ -83,10 +72,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8372 $ rootComposerJsonFile = new JsonFile ($ input ->getOption ('working-dir ' ) . '/composer.json ' );
8473
8574 // Clean out a few of the sections in root composer.json file
86- $ rootComposerJsonFile = $ rootComposerJsonFile ->setSection ('autoload ' , []);
87- $ rootComposerJsonFile = $ rootComposerJsonFile ->setSection ('autoload-dev ' , []);
88-
89- foreach ($ this ->bardConfig ['packages ' ] as $ pkg ) {
75+ $ rootComposerJsonFile = $ rootComposerJsonFile ->with (new ClearSection ('autoload ' ));
76+ $ rootComposerJsonFile = $ rootComposerJsonFile ->with (new ClearSection ('autoload-dev ' ));
77+ $ rootComposerJsonFile = $ rootComposerJsonFile ->with (new ClearSection ('require ' ));
78+ $ rootComposerJsonFile = $ rootComposerJsonFile ->with (new ClearSection ('require-dev ' ));
79+ $ rootComposerJsonFile = $ rootComposerJsonFile ->with (new ClearSection ('replace ' ));
80+ $ rootComposerJsonFile = $ rootComposerJsonFile ->with (new ClearSection ('provide ' ));
81+
82+ foreach ($ this ->bardConfig ->getSection ('packages ' ) as $ pkg ) {
9083 $ pkgComposerFile = realpath ($ input ->getOption ('working-dir ' ) . '/ ' . $ pkg ['path ' ] . '/composer.json ' );
9184 if (!file_exists ($ pkgComposerFile )) {
9285 $ output ->writeln (sprintf ('No "%s" found, skipping ' , $ packageComposerFile ));
0 commit comments