17
17
*
18
18
* For example: ">=7.2.5" becomes "7.2"
19
19
*/
20
- function extractPhpMinorVersion ($ versionConstraint ) {
21
- $ fullPhpVersion = preg_replace ('/[^0-9.]/ ' , '' , $ versionConstraint );
20
+ function extractPhpMinorVersion (array $ composerData ): ?string
21
+ {
22
+ if (!isset ($ composerData ['require ' ])) {
23
+ return null ;
24
+ }
25
+
26
+ if (!isset ($ composerData ['require ' ]['php ' ])) {
27
+ throw new \Exception (sprintf ('Missing "php" requirement for package "%s" ' , $ composerData ['name ' ]));
28
+ }
29
+
30
+ $ fullPhpVersion = preg_replace ('/[^0-9.]/ ' , '' , $ composerData ['require ' ]['php ' ]);
22
31
$ parts = explode ('. ' , $ fullPhpVersion );
23
32
24
33
return sprintf ('%s.%s ' , $ parts [0 ], $ parts [1 ]);
@@ -27,9 +36,12 @@ function extractPhpMinorVersion($versionConstraint) {
27
36
const MAX_PHP_VERSION = '8.0 ' ;
28
37
29
38
foreach ($ finder as $ file ) {
30
- // get the minimum PHP version supported
31
- $ phpRequirement = (json_decode ($ file ->getContents (), true ))['require ' ]['php ' ];
32
- $ phpVersion = extractPhpMinorVersion ($ phpRequirement );
39
+ $ phpVersion = extractPhpMinorVersion (json_decode ($ file ->getContents (), true ));
40
+
41
+ if (!$ phpVersion ) {
42
+ // some packages have no php code
43
+ continue ;
44
+ }
33
45
34
46
$ directory = $ file ->getPathInfo ()->getPathname ();
35
47
$ packagePath = substr ($ directory , strpos ($ directory , '../src/ ' ) + 7 );
0 commit comments