@@ -46,6 +46,18 @@ public function configure(): void
4646 \Symfony \Component \Console \Input \InputOption::VALUE_OPTIONAL ,
4747 'Automatically convert e.g. int[] into array. (false or true) ' ,
4848 'false '
49+ )->addOption (
50+ 'stubs-path ' ,
51+ null ,
52+ \Symfony \Component \Console \Input \InputOption::VALUE_OPTIONAL ,
53+ 'Overwrite the source of the stubs, by default we use PhpStorm Stubs via composer. ' ,
54+ ''
55+ )->addOption (
56+ 'stubs-file-extension ' ,
57+ null ,
58+ \Symfony \Component \Console \Input \InputOption::VALUE_OPTIONAL ,
59+ 'Overwrite the default file extension for stubs. ' ,
60+ '.php '
4961 );
5062 }
5163
@@ -58,6 +70,8 @@ public function execute(InputInterface $input, OutputInterface $output): int
5870
5971 $ autoFix = $ input ->getOption ('auto-fix ' ) !== 'false ' ;
6072 $ removeArrayValueInfo = $ input ->getOption ('remove-array-value-info ' ) !== 'false ' ;
73+ $ stubsPath = $ input ->getOption ('stubs-path ' );
74+ $ stubsFileExtension = $ input ->getOption ('stubs-file-extension ' );
6175
6276 if (!$ realPath || !\file_exists ($ realPath )) {
6377 $ output ->writeln ('------------------------------- ' );
@@ -70,38 +84,41 @@ public function execute(InputInterface $input, OutputInterface $output): int
7084 $ xmlReader = new \voku \PhpDocFixer \XmlDocs \XmlReader ($ realPath );
7185 $ xmlDocInfo = $ xmlReader ->parse ();
7286
73- $ phpStormStubsPath = __DIR__ . '/../../../../vendor/jetbrains/phpstorm-stubs/ ' ;
74- $ phpTypesFromPhpStormStubs = new \voku \PhpDocFixer \PhpStormStubs \PhpStormStubsReader (
75- $ phpStormStubsPath ,
76- $ removeArrayValueInfo
87+ if (!$ stubsPath ) {
88+ $ stubsPath = __DIR__ . '/../../../../vendor/jetbrains/phpstorm-stubs/ ' ;
89+ }
90+ $ phpTypesFromStubs = new \voku \PhpDocFixer \PhpStubs \PhpStubsReader (
91+ $ stubsPath ,
92+ $ removeArrayValueInfo ,
93+ $ stubsFileExtension
7794 );
78- $ phpStormStubsInfo = $ phpTypesFromPhpStormStubs ->parse ();
95+ $ stubsInfo = $ phpTypesFromStubs ->parse ();
7996
8097 $ errors = [];
8198 foreach ($ xmlDocInfo as $ functionName_or_classAndMethodName => $ types ) {
82- if (!isset ($ phpStormStubsInfo [$ functionName_or_classAndMethodName ])) {
83- // TODO: error in phpstorm- stubs ?
99+ if (!isset ($ stubsInfo [$ functionName_or_classAndMethodName ])) {
100+ // TODO: error in stubs?
84101 //\var_dump($functionName_or_classAndMethodName); exit;
85102 continue ;
86103 }
87104
88105 if (
89- ($ phpStormStubsInfo [$ functionName_or_classAndMethodName ]['return ' ] ?? []) !== ($ types ['return ' ] ?? [])
106+ ($ stubsInfo [$ functionName_or_classAndMethodName ]['return ' ] ?? []) !== ($ types ['return ' ] ?? [])
90107 ||
91- ($ phpStormStubsInfo [$ functionName_or_classAndMethodName ]['params ' ] ?? []) !== ($ types ['params ' ] ?? [])
108+ ($ stubsInfo [$ functionName_or_classAndMethodName ]['params ' ] ?? []) !== ($ types ['params ' ] ?? [])
92109 ) {
93110 $ pathTmp = $ types ['absoluteFilePath ' ];
94111 unset($ types ['absoluteFilePath ' ]);
95112
96113 $ errors [$ functionName_or_classAndMethodName ] = [
97- 'phpStubTypes ' => $ phpStormStubsInfo [$ functionName_or_classAndMethodName ],
114+ 'phpStubTypes ' => $ stubsInfo [$ functionName_or_classAndMethodName ],
98115 'phpDocTypes ' => $ types ,
99116 'path ' => $ pathTmp ,
100117 ];
101118
102119 if ($ autoFix ) {
103120 $ xmlFixer = new \voku \PhpDocFixer \XmlDocs \XmlWriter ($ pathTmp );
104- $ xmlFixer ->fix ($ phpStormStubsInfo [$ functionName_or_classAndMethodName ]);
121+ $ xmlFixer ->fix ($ stubsInfo [$ functionName_or_classAndMethodName ]);
105122 }
106123 }
107124 }
0 commit comments