-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Make pivot key a required field #13
base: 1.x-dev
Are you sure you want to change the base?
Conversation
The `key` argument to the `ArrayHelper::pivot` is currently optional and defaults to `null`. If omitted when calling this method this will always return a blank array. So I don't understand why it was set as optional?
It's been that way since the original PR to add the method (joomla/joomla-platform#257) and there is a test case (https://github.com/joomla-framework/utilities/blob/1.3.3/Tests/ArrayHelperTest.php#L438) with |
The test case passes as the test case is built in favor of what it does. Also the test case lack in few important input conditions. The method simply keeps ignoring the values until end, and returns an empty array, which is not what one should expect. $input = array(
array('one' => 1, 'two' => 2, 'three' => 3),
array('one' => 11, 'two' => 22, 'three' => 33),
array('one' => 111, 'two' => 222, 'three' => 333),
);
$pivot = Joomla\Utilities\ArrayHelper::pivot($input); You'll get: $pivot = array(); Now try this: $input = array(
array('one' => 1, 'two' => 2, 'three' => 3),
array('one' => 11, 'two' => 22, 'three' => 33),
array('one' => 111, 'two' => 222, 'three' => 333),
'four',
);
$pivot = Joomla\Utilities\ArrayHelper::pivot($input); and this: $input = array(
array('one' => 1, 'two' => 2, 'three' => 3),
array('one' => 11, 'two' => 22, 'three' => 33),
array('one' => 111, 'two' => 222, 'three' => 333),
null,
'four',
);
$pivot = Joomla\Utilities\ArrayHelper::pivot($input); I can see it does (somewhat) the reverse of what See this example: $input = array(
'1000' => 'New',
'1500' => 'New',
'1750' => 'New',
'3000' => 'Used',
'4000' => 'Used',
'5000' => 'Used',
'6000' => 'Used',
'7000' => 'Refurbished',
);
$pivot = Joomla\Utilities\ArrayHelper::pivot($input); Outputs: $pivot = array(
'New' => array('1000', '1500', '1750'),
'Used' => array('3000', '4000', '5000', '6000'),
'Refurbished' => '7000'
); Now if we pass above to $invert = Joomla\Utilities\ArrayHelper::invert($pivot); We get: $invert = array(
'1000' => 'New',
'1500' => 'New',
'1750' => 'New',
'3000' => 'Used',
'4000' => 'Used',
'5000' => 'Used',
'6000' => 'Used',
// '7000' => 'Refurbished', <=== Missing value
); Points to notice here:
This is my understanding and perspective. Please advise! |
I know I'm late as all hell on this, so looking at the change alone it's definitely a B/C break changing the signature. For 1.x, I'd suggest checking |
I agree. About 2.0 branch, can I propose to make the pivot behaviour consistent for all cases. I mean to change current output $pivot = array(
'New' => array('1000', '1500', '1750'),
'Used' => array('3000', '4000', '5000', '6000'),
'Refurbished' => '7000'
); to $pivot = array(
'New' => array('1000', '1500', '1750'),
'Used' => array('3000', '4000', '5000', '6000'),
'Refurbished' => array('7000') // <-- this is changed.
); Currently it needs us to always check whether the pivoted value is a multi-value or single-value. |
Both ideas sound good to me. |
I was trying to add an exception message but I see there is usage of Please suggest what would be the best way to raise the error condition. |
The Framework is weaning away from using translated Exception messages to using hardcoded English so don't worry about that aspect of things. |
Switching from Travis to Drone for 2.0-dev
The
key
argument to theArrayHelper::pivot
is currently optional and defaults tonull
. If omitted when calling this method this will always return a blank array. So I don't understand why it was set as optional?I'd like to discuss on this case.