@@ -106,38 +106,37 @@ function merge($ancestor, $ours, $theirs) {
106
106
}
107
107
108
108
// Sort composer packages
109
- // Method was taken from https://github.com/composer/composer/blob/master/src/Composer/Json/JsonManipulator.php#L117-L146
110
- function sortPackages (&$ packages )
111
- {
112
- $ prefix = function ($ requirement ) {
113
- // value was taken from https://github.com/composer/composer/blob/master/src/Composer/Repository/PlatformRepository.php#L27
114
- $ platformPackageRegexp = '{^(?:php(?:-64bit|-ipv6|-zts|-debug)?|hhvm|(?:ext|lib)-[^/ ]+)$}i ' ;
115
-
116
- if (preg_match ($ platformPackageRegexp , $ requirement )) {
117
- return preg_replace (
118
- array (
119
- '/^php/ ' ,
120
- '/^hhvm/ ' ,
121
- '/^ext/ ' ,
122
- '/^lib/ ' ,
123
- '/^\D/ ' ,
124
- ),
125
- array (
126
- '0-$0 ' ,
127
- '1-$0 ' ,
128
- '2-$0 ' ,
129
- '3-$0 ' ,
130
- '4-$0 ' ,
131
- ),
132
- $ requirement
133
- );
134
- }
135
- return '5- ' .$ requirement ;
136
- };
137
-
138
- uksort ($ packages , function ($ a , $ b ) use ($ prefix ) {
139
- return strnatcmp ($ prefix ($ a ), $ prefix ($ b ));
140
- });
109
+ // adapted from https://github.com/composer/composer/blob/master/src/Composer/Json/JsonManipulator.php#L117-L146
110
+ function sortPackages (&$ packages ) {
111
+ $ prefix = function ($ requirement ) {
112
+ // value from https://github.com/composer/composer/blob/master/src/Composer/Repository/PlatformRepository.php#L27
113
+ $ platformPackageRegexp = '{^(?:php(?:-64bit|-ipv6|-zts|-debug)?|hhvm|(?:ext|lib)-[^/ ]+)$}i ' ;
114
+
115
+ if (preg_match ($ platformPackageRegexp , $ requirement )) {
116
+ return preg_replace (
117
+ [
118
+ '/^php/ ' ,
119
+ '/^hhvm/ ' ,
120
+ '/^ext/ ' ,
121
+ '/^lib/ ' ,
122
+ '/^\D/ ' ,
123
+ ],
124
+ [
125
+ '0-$0 ' ,
126
+ '1-$0 ' ,
127
+ '2-$0 ' ,
128
+ '3-$0 ' ,
129
+ '4-$0 ' ,
130
+ ],
131
+ $ requirement
132
+ );
133
+ }
134
+ return '5- ' . $ requirement ;
135
+ };
136
+
137
+ uksort ($ packages , function ($ a , $ b ) use ($ prefix ) {
138
+ return strnatcmp ($ prefix ($ a ), $ prefix ($ b ));
139
+ });
141
140
}
142
141
143
142
// special handling for lock files
@@ -190,19 +189,19 @@ if ($isLock) {
190
189
191
190
$ merged = json_encode ($ merged , JSON_ENCODE_OPTIONS );
192
191
} else {
193
- $ merged = merge ($ ancestor , $ ours , $ theirs );
194
-
195
- if (isset ($ merged ['config ' ]['sort-packages ' ]) && $ merged ['config ' ]['sort-packages ' ] === true ) {
196
- foreach (['require ' , 'require-dev ' ] as $ section ) {
197
- $ packageArray = $ merged [$ section ];
198
-
199
- sortPackages ($ packageArray );
192
+ $ merged = merge ($ ancestor , $ ours , $ theirs );
200
193
201
- $ merged [$ section ] = $ packageArray ;
202
- }
203
- }
194
+ if (isset ($ merged ['config ' ]['sort-packages ' ]) && $ merged ['config ' ]['sort-packages ' ] === true ) {
195
+ foreach (['require ' , 'require-dev ' ] as $ section ) {
196
+ // skip if the section type doesn't exist
197
+ if (!isset ($ merged [$ section ])) {
198
+ continue ;
199
+ }
200
+ sortPackages ($ merged [$ section ]);
201
+ }
202
+ }
204
203
205
- $ merged = json_encode ($ merged , JSON_ENCODE_OPTIONS );
204
+ $ merged = json_encode ($ merged , JSON_ENCODE_OPTIONS );
206
205
}
207
206
208
207
// if we have conflicts, replace the conflict markers with the actual conflicting values
0 commit comments