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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: simplify context class #315
Conversation
$this->verbosityLevel, | ||
$this->name, | ||
); | ||
return $this->with(currentDirectory: str_starts_with($path, '/') ? $path : PathHelper::realpath($this->currentDirectory . '/' . $path)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice something I don't like.
withPath
but the property is currentDirectory
.
What about deprecating withPath
to withCurrentDirectory
?
(if okay, I'll open a new PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok for renaming it, it bugged me a few times 馃憤
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current name of the run
method for defining the path is also path
. Shouldn't we also make sure they're identical?
Why not something like workingPath
or workingDirectory
to indicate the working directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
$this->verbosityLevel, | ||
$this->name, | ||
); | ||
return $this->with(currentDirectory: str_starts_with($path, '/') ? $path : PathHelper::realpath($this->currentDirectory . '/' . $path)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok for renaming it, it bugged me a few times 馃憤
@@ -276,6 +142,23 @@ public function offsetUnset(mixed $offset): void | |||
throw new \LogicException('Context is immutable.'); | |||
} | |||
|
|||
private function with(mixed ...$args): self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you consider putting all the parameters from the constructor here, with their type, but then nullable, with default null value?
It would still allow you to only use named parameters, but now you have type safety.
Instead of an array you reference the parameter directly and fallback to the original value using ??.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but did not succeed to do that. There is not way in PHP to check is null is passed or if it's the default value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it doesn't work when a property is nullable. Forgot about that.
Too bad!
No description provided.