Don’t try to extract anything when there are no PHP files#24
Don’t try to extract anything when there are no PHP files#24schlessera merged 3 commits intomasterfrom
Conversation
This is commonly the case when adding a child theme where only strings from `style.css` should get extracted but nothing else.
| Scenario: Does include file headers. | ||
| When I run `wp scaffold plugin hello-world --plugin_name="Hello World" --plugin_author="John Doe" --plugin_author_uri="https://example.com" --plugin_uri="https://foo.example.com"` | ||
|
|
||
| When I run `wp i18n make-pot wp-content/plugins/hello-world wp-content/plugins/hello-world/languages/hello-world.pot` |
There was a problem hiding this comment.
Can't hurt I guess. Added now.
|
|
||
| try { | ||
| if ( ! empty( $files ) ) { | ||
| static::fromFile( $files, $translations, $options ); |
There was a problem hiding this comment.
Unrelated to this PR, but makes me wonder whether public static function fromFile( $file, ... ) should not be named public static fromFiles( $files, ... ) instead (plural vor name and argument), as it loops over multiple files.
Alternatively, the loop could be extracted out of fromFile() and put into the surrounding code. Might make more sense, conceptually. In that case, the above would turn from an if into a simple foreach.
There was a problem hiding this comment.
I totally agree that it's not ideal.
Just note that this method implements ExtractorInterface::fromFile() where the doc block says @param array|string $file A path of a file or files. The abstract Extractor class it extends does the same, so I tried to keep the same behavior.
There was a problem hiding this comment.
Okay, let's keep it as is for now then.
Don’t try to extract anything when there are no PHP files
This is commonly the case when adding a child theme where only strings from
style.cssshould get extracted but nothing else.Without this change,
\Gettext\Extractors\Extractor::getFiles()throws anInvalidArgumentExceptionwhen being passed an empty array.Now, the function is not being called in that scenario. Plus, any exceptions will be caught an printed by
WP_CLI::error().