Skip to content
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

Common::getSniffCode(): add tests, more defensive coding and minor simplification #524

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jun 5, 2024

Description

Common::getSniffCode(): add tests

Add initial set of tests for the Common::getSniffCode() method.

Related to #146
Related to review comment in PR 446.

Common::getSniffCode(): throw exception on invalid input [1]

Previously, if an empty string was passed, the Common::getSniffCode() method would return .., which is just confusing.

This commit changes the behaviour to throw an InvalidArgumentException instead.

Includes making a potentially superfluous function call to the method conditionally (as it could hit the new exception).

Includes test.

Common::getSniffCode(): throw exception on invalid input [2a]

Previously, if an invalid (incomplete) class name was passed, the Common::getSniffCode() method would return a garbled name, like .Qualified.C, which is just confusing.

This commit changes the behaviour to throw an InvalidArgumentException instead.

Includes test.

Common::getSniffCode(): throw exception on invalid input [2b]

Previously, if an invalid class name was passed, which didn't end on Sniff or UnitTest, the Common::getSniffCode() method would return a garbled name, like Fully.Qualified.C, which is just confusing.

This commit changes the behaviour to throw an InvalidArgumentException instead.

Includes test.

Common::getSniffCode(): minor simplification

  • Remove the use of array_pop() in favour of directly referencing the required "parts" by their index in the array.
  • Remove the unused $sniffDir variable.
  • Remove the unnecessary $code variable.

Related to review comment in PR 446.

Suggested changelog entry

The Common::getSniffCode() method will now throw an InvalidArgumentException exception if an invalid $sniffClass is passed.

jrfnl added 5 commits June 5, 2024 19:37
Add initial set of tests for the `Common::getSniffCode()` method.

Related to 146
Related to [review comment in PR 446](#446 (comment)).
Previously, if an empty string was passed, the `Common::getSniffCode()` method would return `..`, which is just confusing (and incorrect).

This commit changes the behaviour to throw an `InvalidArgumentException` instead.

Includes making a potentially superfluous function call to the method conditionally (as it could hit the new exception).

Includes test.
Previously, if an invalid (incomplete) class name was passed, the `Common::getSniffCode()` method would return a garbled name, like `.Qualified.C`, which is just confusing.

This commit changes the behaviour to throw an `InvalidArgumentException` instead.

Includes test.
Previously, if an invalid class name was passed, which didn't end on `Sniff` or `UnitTest`, the `Common::getSniffCode()` method would return a garbled name, like `Fully.Qualified.C`, which is just confusing.

This commit changes the behaviour to throw an `InvalidArgumentException` instead.

Includes test.
* Remove the use of `array_pop()` in favour of directly referencing the required "parts" by their index in the array.
* Remove the unused `$sniffDir` variable.
* Remove the unnecessary `$code` variable.

Related to [review comment in PR 446](#446 (comment)).
Copy link
Contributor

@rodrigoprimo rodrigoprimo left a comment

Choose a reason for hiding this comment

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

LGTM

@jrfnl jrfnl modified the milestones: 3.10.x Next, 3.11.0 Jun 28, 2024
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.

None yet

3 participants