-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Provide a DX where an array could be passed #25397
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] Provide a DX where an array could be passed #25397
Conversation
3.4? |
@@ -410,6 +411,9 @@ private function buildTableRows($rows) | ||
|
||
// Remove any new line breaks and replace it with a new line | ||
foreach ($rows[$rowKey] as $column => $cell) { | ||
if (is_array($cell)) { | ||
continue; |
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 would silence the error and consequently we would have an unexpected behavior. IMO we should throw an exception instead (probably in $this->fillNextRows()
) as the cell must be a string (always) at this moment.
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, i'm throwing now
ded8402
to
a07e8e1
Compare
a07e8e1
to
e6bdca2
Compare
Dude! could you please stop posting pictures! This is GitHub not Instagram 😂 |
This is now Instagit cc @iltar |
I like the idea of giving issues something more than just lines of code as it's people doing things behind :) |
*/ | ||
private function fillNextRows(array $rows, $line) | ||
{ | ||
$unmergedRows = array(); | ||
foreach ($rows[$line] as $column => $cell) { | ||
if (is_array($cell)) { | ||
throw new \UnexpectedValueException('The cell should always be a string, array given.'); |
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.
be a string or a TableCell
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.
if (!is_string($cell) && !$cell instanceof TableCell)
?
e6bdca2
to
f4066a6
Compare
* @expectedException \UnexpectedValueException | ||
* @expectedExceptionMessage The cell should always be a string, array given. | ||
*/ | ||
public function testThrows() |
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.
could be best named :)
*/ | ||
private function fillNextRows(array $rows, $line) | ||
{ | ||
$unmergedRows = array(); | ||
foreach ($rows[$line] as $column => $cell) { | ||
if (!is_string($cell) && !$cell instanceof TableCell) { | ||
throw new \UnexpectedValueException('The cell should always be a string, array given.'); |
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.
can we use the console InvalidArgumentException
to ease catching it?
f4066a6
to
85ee007
Compare
fabbot error is about #25397 (comment) so I'm not fixing it. |
85ee007
to
b3519a9
Compare
fabbot is right, |
d1f9a63
to
7996158
Compare
PR rebased with current 3.4 |
Status: Needs Review |
*/ | ||
private function fillNextRows(array $rows, $line) | ||
{ | ||
$unmergedRows = array(); | ||
foreach ($rows[$line] as $column => $cell) { | ||
if (null !== $cell && !is_string($cell) && !$cell instanceof TableCell && !is_scalar($cell)) { |
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.
What about dropping the is_string()
check? It's already covered by the is_scalar()
test.
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.
ping @Simperfit
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
5551d0e
to
2f2d254
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.
Tests are broken
It feels strange that are broken this way, I don't see how I can fix them without adding the |
|
So I need to cast it to string.
|
No, you need to check for |
2f2d254
to
79663df
Compare
This is what I've done instead of doing a cast that could lead to errors. |
79663df
to
23ee4ef
Compare
*/ | ||
private function fillNextRows(array $rows, $line) | ||
{ | ||
$unmergedRows = array(); | ||
foreach ($rows[$line] as $column => $cell) { | ||
if (null !== $cell && !$cell instanceof TableCell && !is_scalar($cell) && !(is_object($cell) && method_exists($cell, '__toString'))) { | ||
throw new InvalidArgumentException(sprintf('The cell should always be a string, a TableCell or a scalar, %s given.', gettype($cell))); |
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 say A cell must be a TableCell, a scalar or an object implementing __toString, %s given.
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.
ping @Simperfit
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
23ee4ef
to
de502f7
Compare
Thank you @Simperfit. |
…perfit) This PR was merged into the 3.4 branch. Discussion ---------- [Console] Provide a DX where an array could be passed | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | #25394 | License | MIT | Doc PR | none  I think that this is not fixing the root causes that does not appears in 4.1, so maybe there is something better to do. I did not find the root cause So I think it can bo good to fix the problem too. Commits ------- de502f7 [Console] Provide a bugfix where an array could be passed
I think that this is not fixing the root causes that does not appears in 4.1, so maybe there is something better to do. I did not find the root cause So I think it can bo good to fix the problem too.