@@ -15,11 +15,25 @@ class UnlinkCommand extends Command
15
15
16
16
public function handle (): int
17
17
{
18
+ app (KibbleGitIgnore::class)();
19
+
20
+ if (! file_exists ('kibble.json ' )) {
21
+ $ this ->error ('kibble.json file not found ' );
22
+
23
+ return Command::FAILURE ;
24
+ }
25
+
18
26
$ repository = $ this ->argument ('repository ' );
27
+ $ kibble = json_decode (file_get_contents ('kibble.json ' ), true );
28
+
29
+ if (! isset ($ kibble [$ repository ])) {
30
+ $ this ->error ("{$ repository } repository not found in kibble.json " );
31
+
32
+ return Command::FAILURE ;
33
+ }
19
34
20
35
$ composer_json = file_get_contents ('composer.json ' );
21
36
$ trailing_newline = str_ends_with ($ composer_json , "\n" );
22
-
23
37
$ composer = json_decode ($ composer_json , true );
24
38
25
39
if (! isset ($ composer ['repositories ' ][$ repository ])) {
@@ -28,15 +42,11 @@ public function handle(): int
28
42
return Command::FAILURE ;
29
43
}
30
44
31
- app (KibbleGitIgnore::class)();
45
+ if ($ composer ['repositories ' ][$ repository ] !== $ kibble [$ repository ]) {
46
+ $ this ->error ("{$ repository } repository in composer.json does not match {$ repository } repository in kibble.json " );
32
47
33
- file_put_contents (
34
- filename: 'kibble.json ' ,
35
- data: json_encode (
36
- value: [$ repository => $ composer ['repositories ' ][$ repository ]],
37
- flags: JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
38
- ).($ trailing_newline ? "\n" : '' )
39
- );
48
+ return Command::FAILURE ;
49
+ }
40
50
41
51
unset($ composer ['repositories ' ][$ repository ]);
42
52
0 commit comments