Skip to content

Conversation

@deluxetom
Copy link
Contributor

@deluxetom deluxetom commented Dec 17, 2024

  • Added new tests to make sure only valid parameters are used
  • New interface method for each manipulator to know the API parameters used
  • no BC break

$all_params = $this->server->getAllParams([
'w' => '100',
'p' => 'small',
'invalid' => '1',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ADmad I realize I added some fixes that are out of scope of the issue, but this is the test fixing the cache path issue

I believe it shouldn't accept invalid parameters

Copy link
Collaborator

@ADmad ADmad left a comment

Choose a reason for hiding this comment

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

no BC break

Adding a new interface method is very much a BC break 🙂

But I think it's worth it in this case, given the improvement it provides.

src/Api/Api.php Outdated
$params = [];

array_walk($this->manipulators, function (ManipulatorInterface $manipulator) use (&$params) {
foreach ($manipulator->getApiParams() as $param) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why loop through each instead of using array merge?

src/Api/Api.php Outdated
Comment on lines 145 to 147
foreach ($manipulator->getApiParams() as $param) {
$this->apiParams[] = $param;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
foreach ($manipulator->getApiParams() as $param) {
$this->apiParams[] = $param;
}
$this->apiParams = array_merge($this->apiParams, $manipulator->getApiParams());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was over-complicating this, thanks for pointing it out!

*
* @return list<string>
*/
abstract public function getApiParams(): array;
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need this abstract method because it is defined already in ManipulatorInterface

Copy link
Contributor Author

@deluxetom deluxetom Dec 17, 2024

Choose a reason for hiding this comment

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

I agree, I was following what was done for the run method, I removed both from BaseManipulator

@ADmad ADmad merged commit 3cb6c58 into thephpleague:3.x Dec 18, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants