File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 9
9
"phpstan/phpstan" : " ^0.11.5"
10
10
},
11
11
"require-dev" : {
12
+ "composer/composer" : " ^1.8.6" ,
12
13
"consistence/coding-standard" : " ^3.8" ,
13
14
"dealerdirect/phpcodesniffer-composer-installer" : " ^0.4.4" ,
14
15
"jakub-onderka/php-parallel-lint" : " ^1.0" ,
28
29
}
29
30
},
30
31
"minimum-stability" : " dev" ,
31
- "prefer-stable" : true
32
+ "prefer-stable" : true ,
33
+ "scripts" : {
34
+ "post-install-cmd" : " PHPStan\\ WordPress\\ Composer\\ FixWpStubs::php73Polyfill" ,
35
+ "post-update-cmd" : " PHPStan\\ WordPress\\ Composer\\ FixWpStubs::php73Polyfill"
36
+ }
32
37
}
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types = 1 );
2
+ /**
3
+ * Fix WordPress stubs.
4
+ */
5
+
6
+ namespace PHPStan \WordPress \Composer ;
7
+
8
+ use Composer \Script \Event ;
9
+
10
+ class FixWpStubs
11
+ {
12
+ const STUBSFILE = '/giacocorsiglia/wordpress-stubs/wordpress-stubs.php ' ;
13
+
14
+ public static function php73Polyfill (Event $ event )
15
+ {
16
+ if (! class_exists ('\Symfony\Polyfill\Php73\Php73 ' )) {
17
+ return ;
18
+ }
19
+
20
+ echo 'Removing duplicate is_countable() ... ' ;
21
+ $ vendorDir = $ event ->getComposer ()->getConfig ()->get ('vendor-dir ' );
22
+ $ stubsFile = $ vendorDir . self ::STUBSFILE ;
23
+
24
+ $ stubs = file_get_contents ($ stubsFile );
25
+ if ($ stubs === false ) {
26
+ echo 'WordPress stubs not found. ' ;
27
+ return ;
28
+ }
29
+ $ fixedStubs = preg_replace ('/(\n)(function is_countable)/ ' , '$1// $2 ' , $ stubs );
30
+
31
+ $ numberOfBytes = file_put_contents ($ stubsFile , $ fixedStubs );
32
+ $ message = 'OK. ' ;
33
+ if ($ numberOfBytes === false ) {
34
+ $ message = 'FAILED. ' ;
35
+ }
36
+
37
+ echo $ message . "\n" ;
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments