Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

Merged

Conversation

Simperfit
Copy link
Contributor

@Simperfit Simperfit commented Dec 8, 2017

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #25394
License MIT
Doc PR none

img_2941

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.

@nicolas-grekas
Copy link
Member

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;
Copy link
Member

@yceruto yceruto Dec 8, 2017

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.

Copy link
Contributor Author

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

@chalasr chalasr added this to the 3.4 milestone Dec 8, 2017
@Simperfit Simperfit force-pushed the bugfix/fix-a-bug-where-an-array-could-be-passed branch from ded8402 to a07e8e1 Compare December 9, 2017 07:50
@Simperfit Simperfit changed the base branch from 4.0 to 3.4 December 9, 2017 07:51
@Simperfit Simperfit force-pushed the bugfix/fix-a-bug-where-an-array-could-be-passed branch from a07e8e1 to e6bdca2 Compare December 9, 2017 07:52
@Simperfit Simperfit changed the title [Console] Provide a bugfix where an array could be passed [Console] Provide a DX where an array could be passed Dec 9, 2017
@sstok
Copy link
Contributor

sstok commented Dec 9, 2017

Dude! could you please stop posting pictures! This is GitHub not Instagram 😂

@Simperfit
Copy link
Contributor Author

This is now Instagit cc @iltar

@sroze
Copy link
Contributor

sroze commented Dec 10, 2017

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.');
Copy link
Member

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

Copy link
Member

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

@Simperfit Simperfit force-pushed the bugfix/fix-a-bug-where-an-array-could-be-passed branch from e6bdca2 to f4066a6 Compare December 12, 2017 14:00
@xabbuh xabbuh added Console and removed Form labels Dec 14, 2017
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage The cell should always be a string, array given.
*/
public function testThrows()
Copy link
Member

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.');
Copy link
Member

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?

@Simperfit Simperfit force-pushed the bugfix/fix-a-bug-where-an-array-could-be-passed branch from f4066a6 to 85ee007 Compare December 16, 2017 04:38
@Simperfit
Copy link
Contributor Author

fabbot error is about #25397 (comment) so I'm not fixing it.

@Simperfit Simperfit force-pushed the bugfix/fix-a-bug-where-an-array-could-be-passed branch from 85ee007 to b3519a9 Compare December 17, 2017 07:12
@keradus
Copy link
Member

keradus commented Dec 19, 2017

fabbot is right, @expectedException is always from root namespace. use FQCN there as fabbot ask you

@Simperfit Simperfit force-pushed the bugfix/fix-a-bug-where-an-array-could-be-passed branch 3 times, most recently from d1f9a63 to 7996158 Compare December 20, 2017 15:49
@Simperfit
Copy link
Contributor Author

PR rebased with current 3.4

@Simperfit
Copy link
Contributor Author

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)) {
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @Simperfit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Simperfit Simperfit force-pushed the bugfix/fix-a-bug-where-an-array-could-be-passed branch from 5551d0e to 2f2d254 Compare January 17, 2018 08:27
Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are broken

@Simperfit
Copy link
Contributor Author

It feels strange that are broken this way, I don't see how I can fix them without adding the @expectedException because it really passes a Reference object to a factory.service

@chalasr
Copy link
Member

chalasr commented Jan 19, 2018

Reference can be casted to string, this probably needs to deal with objects implementing __toString() in addition to strings.

@Simperfit
Copy link
Contributor Author

Simperfit commented Jan 19, 2018 via email

@chalasr
Copy link
Member

chalasr commented Jan 19, 2018

No, you need to check for !is_scalar($cell) && !(is_object($cell) && method_exists($cell, '__toString')) (strings are strings, objects are not strings but can be casted too).

@Simperfit Simperfit force-pushed the bugfix/fix-a-bug-where-an-array-could-be-passed branch from 2f2d254 to 79663df Compare January 19, 2018 14:07
@Simperfit
Copy link
Contributor Author

This is what I've done instead of doing a cast that could lead to errors.

@Simperfit Simperfit force-pushed the bugfix/fix-a-bug-where-an-array-could-be-passed branch from 79663df to 23ee4ef Compare January 19, 2018 14:09
*/
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)));
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @Simperfit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Simperfit Simperfit force-pushed the bugfix/fix-a-bug-where-an-array-could-be-passed branch from 23ee4ef to de502f7 Compare January 24, 2018 15:57
@chalasr
Copy link
Member

chalasr commented Jan 25, 2018

Thank you @Simperfit.

@chalasr chalasr merged commit de502f7 into symfony:3.4 Jan 25, 2018
chalasr pushed a commit that referenced this pull request Jan 25, 2018
…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

![img_2941](https://user-images.githubusercontent.com/3451634/33766610-977f77ce-dc1e-11e7-93c1-38dd0038d7f5.jpeg)

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
@Simperfit Simperfit deleted the bugfix/fix-a-bug-where-an-array-could-be-passed branch January 25, 2018 10:21
This was referenced Jan 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.