Skip to content
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

Merged
merged 1 commit into from Mar 9, 2024
Merged

chore: simplify context class #315

merged 1 commit into from Mar 9, 2024

Conversation

lyrixx
Copy link
Member

@lyrixx lyrixx commented Mar 8, 2024

No description provided.

$this->verbosityLevel,
$this->name,
);
return $this->with(currentDirectory: str_starts_with($path, '/') ? $path : PathHelper::realpath($this->currentDirectory . '/' . $path));
Copy link
Member Author

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)

Copy link
Member

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 馃憤

Copy link
Contributor

@TheoD02 TheoD02 Mar 8, 2024

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?

@lyrixx lyrixx requested a review from pyrech March 8, 2024 16:45
Copy link
Member

@pyrech pyrech left a 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));
Copy link
Member

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
Copy link
Contributor

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 ??.

Copy link
Member Author

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

Copy link
Contributor

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!

@lyrixx lyrixx merged commit 667611a into main Mar 9, 2024
8 checks passed
@lyrixx lyrixx deleted the context-simplify branch March 9, 2024 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants