-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] [Helper] [Table] Columns styles #14044
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
[Console] [Helper] [Table] Columns styles #14044
Conversation
{ | ||
if (isset($this->columnStyles[$columnIndex])) { | ||
return $this->columnStyles[$columnIndex]; | ||
} else { |
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.
you can remove else here
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.
@aitboudad Nope, all columns should have current table style by default, if not assigned from outside. If I remove else, rendering will be broken.
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.
@MAXakaWIZARD else
is useless as you call return
in if
... Your code should look like:
if (isset($this->columnStyles[$columnIndex])) {
return $this->columnStyles[$columnIndex];
}
return $this->getStyle();
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.
@stloyd got it
e88006a
to
07be42a
Compare
*/ | ||
public function setColumnStyle($columnIndex, $name) | ||
{ | ||
if (!is_numeric($columnIndex)) { |
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 should be is_int
as 0.9 is not a valid column index but is valid for is_numeric
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.
is_int
will return false for string '23'
, for example
7c44129
to
efba0a7
Compare
@fabpot Any thoughts? |
efba0a7
to
ddd3620
Compare
* Sets table style. | ||
* | ||
* @param int $columnIndex Column index | ||
* @param TableStyle|string $name The style name or a TableStyle instance |
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.
you should apply cs fixer here to align doc block
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.
@aitboudad done
93d0483
to
9489871
Compare
@fabpot Any chances to have this in 2.7? |
@MAXakaWIZARD Why do we provide a style for columns and not rows? Would it make sense as well? |
@fabpot Well, I described it in first comment. It is useful for numeric data, for example. |
👍 ping @symfony/deciders |
👍 looks very nice. If we also wanted row styling, we could add that later. |
*/ | ||
public function setColumnStyle($columnIndex, $name) | ||
{ | ||
$isIndexValid = false; |
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.
we should assume that $columnIndex is an int, IMO we can remove checking the columnIndex type
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.
agreed
@fabpot Should this PR target version |
2.7 is fine. I will merge it automatically in the 2.8 branch anyway, no need to rebase on current 2.8. |
|
||
if (!$isIndexValid) { | ||
throw new \InvalidArgumentException(sprintf('Invalid column index: "%s".', $columnIndex)); | ||
} |
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.
All the lines above can be removed.
|
||
/** | ||
* Gets the current style for specified column, | ||
* if style was not set, returns global table style |
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 would prefer something along the lines of:
/**
* Gets the current style for a column.
*
* If style was not set, it returns the global table style.
*/
Apart from my small phpdoc comment, 👍 |
1a2a43d
to
06f9c51
Compare
@fabpot Done |
Can you keep the dots as in my original proposal? |
In fact, I still prefer my version than yours. |
50f0f20
to
ad15c25
Compare
@fabpot Sorry. Is it OK now? |
Looks good now. Can you rebase on current 2.7 to get rid of the merge commit? A simple |
ad15c25
to
0623598
Compare
@fabpot Done. It's only one commit finally. |
Thank you @MAXakaWIZARD. |
This PR introduces ability to set styles for individual columns in table. For example, we can apply STR_PAD_LEFT for the last column (useful for money, file size etc).
Code:
Output: