Skip to content

Don’t try to extract anything when there are no PHP files#24

Merged
schlessera merged 3 commits intomasterfrom
child-theme
Mar 6, 2018
Merged

Don’t try to extract anything when there are no PHP files#24
schlessera merged 3 commits intomasterfrom
child-theme

Conversation

@swissspidy
Copy link
Copy Markdown
Member

This is commonly the case when adding a child theme where only strings from style.css should get extracted but nothing else.

Without this change, \Gettext\Extractors\Extractor::getFiles() throws an InvalidArgumentException when 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().

This is commonly the case when adding a child theme where only strings from `style.css` should get extracted but nothing else.
@swissspidy swissspidy requested a review from a team March 6, 2018 12:33
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`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not checking STDOUT here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't hurt I guess. Added now.


try {
if ( ! empty( $files ) ) {
static::fromFile( $files, $translations, $options );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, let's keep it as is for now then.

@schlessera schlessera merged commit 90f3f8e into master Mar 6, 2018
@schlessera schlessera added the command:i18n Related to 'i18n' command label Mar 6, 2018
@schlessera schlessera added this to the 0.1.0 milestone Mar 6, 2018
@schlessera schlessera deleted the child-theme branch March 6, 2018 22:52
schlessera added a commit that referenced this pull request Jan 6, 2022
Don’t try to extract anything when there are no PHP files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:i18n Related to 'i18n' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants