-
Couldn't load subscription status.
- Fork 148
[FEATURE] Add dedicated property accessors for OutputFormat
#871
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
Conversation
80236b4 to
65afd70
Compare
OutputFormatOutputFormat
65afd70 to
d7d4a44
Compare
d7d4a44 to
456e4d5
Compare
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.
Hot on the heels of #880. Looks good, but
- Some parameter names seem to be inaccurate;
- The test of the deprecated
array|stringfunctionality shouldn't be changed; - I'm wondering if any or all of the private properties should or shouldn't have accessors (but am unsure).
src/OutputFormat.php
Outdated
| public function setBeforeAtRuleBlock(string $whitespace): self | ||
| { | ||
| $this->sBeforeAtRuleBlock = $whitespace; |
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 property description says: "Content injected in and around at-rule blocks." Which suggests it's not necessarily whitespace, and thus the parameter should be differently named.
src/OutputFormat.php
Outdated
| public function setAfterAtRuleBlock(string $whitespace): self | ||
| { | ||
| $this->sAfterAtRuleBlock = $whitespace; |
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.
Ditto.
src/OutputFormat.php
Outdated
| public function setSpaceBeforeListArgumentSeparators(array $separators): self | ||
| { | ||
| $this->aSpaceBeforeListArgumentSeparators = $separators; |
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 separators are the array keys. The values are the space strings. So the parameter name is inaccurate.
In #880 I used $spaceForSeparator as a variable for the array, but am now wondering if one or both nouns should be plural. And I'm also wondering whether setSpaceBeforeListArgumentSeparators() was the best choice of name for the new method, though can't think of anything better.
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've changed it. Please have a look.
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.
WFM :)
src/OutputFormat.php
Outdated
| public function setSpaceAfterListArgumentSeparators(array $separators): self | ||
| { | ||
| $this->aSpaceAfterListArgumentSeparators = $separators; |
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.
Ditto.
src/OutputFormat.php
Outdated
| public function setBeforeDeclarationBlock(string $whitespace): self | ||
| { | ||
| $this->sBeforeDeclarationBlock = $whitespace; |
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 DocBlock for the property says: "Content injected in and around declaration blocks." Which implies it's not necessarily whitespace. (Also, it's not a setSpace... method.)
src/OutputFormat.php
Outdated
| public function setAfterDeclarationBlockSelectors(string $whitespace): self | ||
| { | ||
| $this->sAfterDeclarationBlockSelectors = $whitespace; |
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.
Ditto.
src/OutputFormat.php
Outdated
| public function setAfterDeclarationBlock(string $whitespace): self | ||
| { | ||
| $this->sAfterDeclarationBlock = $whitespace; |
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.
Ditto.
src/OutputFormat.php
Outdated
| public function setIndentation(string $sIndentation): self | ||
| { | ||
| $this->sIndentation = $sIndentation; |
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.
Perhaps avoid the Hungarian notation in the parameter name.
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.
Done.
src/OutputFormat.php
Outdated
| /** | ||
| * @return $this fluent interface | ||
| */ | ||
| public function setIndentationLevel(int $indentationLevel): self | ||
| { | ||
| $this->iIndentationLevel = $indentationLevel; | ||
|
|
||
| return $this; | ||
| } |
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 just noticed that the $oFormatter, $oNextLevelFormat and $iIndentationLevel properties are private (whereas the others are all public), so I'm wondering whether they are intended to be accessed externally. Though currently they all can be via the generic get and set methods.
The OutputFormatter class uses getIndentationLevel(), so that at least is required (but maybe the corresponding setter isn't).
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'd like to make all properties private anyway.
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'd like to make all properties
privateanyway.
Agree. We can mark them @deprecated to be made private in 9.0, with a message to use the relevant accessor methods. (And when they're made private, the Hungarian notation can be dropped.)
tests/OutputFormatTest.php
Outdated
| '.main, .test {font: italic normal bold 16px/1.2 "Helvetica", Verdana, sans-serif;background: white;}' | ||
| . "\n@media screen {.main {background-size: 100% 100%;font-size: 1.3em;background-color: #fff;}}", | ||
| $this->document->render(OutputFormat::create()->setSpaceAfterListArgumentSeparator([ | ||
| $this->document->render(OutputFormat::create()->setSpaceAfterListArgumentSeparators([ |
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.
This is intended to test the deprecated functionality, to confirm it still works, and should not be changed. When the deprecated functionality is removed, this test method can also be removed. (Incidentally, with the new functionality, the plural method does not support the first array item being the default - the default is instead set by the existing method with a string parameter. This doesn't make a difference here since the spacing for all separators used in the test has been specified explicitly.)
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.
Done.
The goal of this PR is to replace the magic getters/setters, which means keeping the same level of access to (or encapsulation of) the As far as our test coverage goes, we currently don't need any additional accessors to the |
456e4d5 to
c566b31
Compare
That was my thinking. Though the private |
c566b31 to
5d53656
Compare
So far, the setter only used in tests. So I think we could indeed drop it again. What do you think? |
|
Removed |
I could be wrong, but I don't think it's needed in the public API - it's for internal use rendering nested items. We'll need to adjust (or remove) the test which uses it though. |
No description provided.