Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Use sprintf around formatted strings #7

Merged
merged 3 commits into from
Sep 12, 2015
Merged

Use sprintf around formatted strings #7

merged 3 commits into from
Sep 12, 2015

Conversation

Mezzle
Copy link
Contributor

@Mezzle Mezzle commented Aug 7, 2015

No description provided.

@samsonasik
Copy link
Contributor

👍

sprintf(
'Parameter of type %s is invalid; must be MongoClient or Mongo',
(is_object($mongo) ? get_class($mongo) : gettype($mongo))
)
Copy link
Contributor

Choose a reason for hiding this comment

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

ZF2 uses a slightly different indentation:

throw new InvalidArgumentException(sprintf(
    'Parameter of type %s is invalid; must be MongoClient or Mongo',
    (is_object($mongo) ? get_class($mongo) : gettype($mongo))
));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where is this documented?

Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this documented?

Good question for a framework where IMHO documentation is a problem 😄

Looking at other ZF2 code in almost every situation the indentation I mentioned is used: https://github.com/zendframework/zend-session/search?utf8=%E2%9C%93&q=Exception%28sprintf%28

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it may for consistency instead of standard

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Personally, I think the way you've suggested indenting it is what caused this error to occur. It's obvious to me that someone's written their code, and copy paste/modified the arguments within, and not noticed the sprintf tucked away :)

Copy link
Contributor

Choose a reason for hiding this comment

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

The error is caused by the fact the original PR was merged without proper tests: zendframework/zendframework#3221 If there was a unittest for this exception the problem would have been detected immediately, that is why it is important to add unittests. BTW a unittest is missing for this PR too 😉

@mwillbanks
Copy link
Contributor

Nice catch :) Yes; we certainly need some tests around this guy.

@Mezzle
Copy link
Contributor Author

Mezzle commented Aug 12, 2015

Added Tests, Coveralls doesn't get it because setUp skips tests if no Mongo extension.


$expectedExceptionMessage = sprintf(
'Parameter of type %s is invalid; must be MongoClient or Mongo',
get_class($notMongo)
Copy link
Member

Choose a reason for hiding this comment

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

Expectation should be static and not be built with the same logic as the implementation

@Maks3w
Copy link
Member

Maks3w commented Aug 12, 2015

👍 For add the test

'database' => 'zf2_tests',
'collection' => 'sessions',
]
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Previous indentation was the right one.

Copy link
Member

Choose a reason for hiding this comment

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

Indeed however I'll preffer don't add more noise in the PR for just cosmetic changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

No problem. I guess it will be corrected when it is merged?

Copy link
Member

Choose a reason for hiding this comment

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

no. The only wrong thing is to change unrelated lines in the PR. Both indentations are correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, sorry, I thought your comment was to me, but it was for @Mezzle

Copy link
Member

Choose a reason for hiding this comment

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

(both)

@mwillbanks mwillbanks added this to the 2.5.2 milestone Sep 4, 2015
@mwillbanks mwillbanks self-assigned this Sep 4, 2015
@mwillbanks mwillbanks merged commit 1ba219d into zendframework:master Sep 12, 2015
mwillbanks added a commit that referenced this pull request Sep 12, 2015
Use sprintf around formatted strings
mwillbanks added a commit that referenced this pull request Sep 12, 2015
mwillbanks added a commit that referenced this pull request Sep 12, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants