Skip to content

[BUGFIX] Fix non-working short-options for "config" and "working-dir" #930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2024

Conversation

garvinhicking
Copy link
Contributor

This adresses:

  • OutputInterface namespace import is unused
  • realpath() may fail, needs gating to satisfy phpstan even though it's unlikely that is_file() returns true, but realpath() doesn't.
  • Currently only --config and not -c is parsed, same with --working-dir (-w)
  • Note: A phpstan error remains due to getcwd() maybe returning false and I didn't want to obfuscate this statement with if-condititions; if you have suggestions to improve the type juggling here, tell me.

Copy link
Contributor

@linawolf linawolf left a comment

Choose a reason for hiding this comment

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

Thanks for these changes, Looks good to me

@@ -47,11 +46,13 @@ if (is_file($projectConfig)) {
echo 'Loading guides.xml from ' . $projectConfig . PHP_EOL;
}
// vendor folder was placed directly into the project directory
$containerFactory->addConfigFile($projectConfig);
if ($projectConfig) {
Copy link
Member

Choose a reason for hiding this comment

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

Please make this a more explicit check. I think this check should be !== False?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did a lax check on that to also evalute an empty string to false.

But I can change that to:

if ($projectConfig !== false && $projectConfig !== '')

(but that has more cognitive load to me...)

Copy link
Member

Choose a reason for hiding this comment

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

That's why I choose to use early returns as much as possible. which is a bit hard in this context as we do not have real functions in this file. We could abuse empty($projectConfig) === false here. or a small namespaced function:

namespace phpDocumentor/guides {
  function emptyOption(string|bool $path) {
     if ($path === false) {
        return true;
    }
  }
} 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd be happy to implement it anyway you prefer, I don't have strong feelings about either approach. Personally I'd then rather use the if ($projectConfig !== false && $projectConfig !== '') approach, because I find the namespace variant and the empty(...) variant even harder to quickly read 😇

... sidequest ahead...

I did try to optimize this actual code block in the CLI binary because the current way of loading and overloading guides.xml created a problem for us in render-guides. And it's really not a beautiful piece of loading code ;)

I wanted to actually adjust that "guides.xml" could be fetched from the default render location (which is "docs" in guides and "Documentation" in render-guides).

But I couldn't get that to work because of the tough mixture of Decorator and actual Console command and loading order (see TYPO3-Documentation/render-guides#421 (comment)). I abandoned that for the time being, since we got bigger fish to fry at this point than putting hours into this optimization ;)

@jaapio
Copy link
Member

jaapio commented Mar 19, 2024

Thanks a lot @garvinhicking!

@jaapio jaapio force-pushed the support-short-code branch from ffe0a18 to e386a79 Compare March 19, 2024 20:52
@jaapio jaapio enabled auto-merge March 19, 2024 20:52
@phpdoc-bot
Copy link

💚 All backports created successfully

Status Branch Result
1.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

phpdoc-bot added a commit that referenced this pull request Mar 19, 2024
[1.x] Merge pull request #930 from garvinhicking/support-short-code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants