refs #4626: Added readable_list() method to Text class.#328
Conversation
This method takes an array of strings and converts them into a human readable list. For example: array('eggs', 'milk', 'cheese') => "eggs, milk and cheese".
There was a problem hiding this comment.
This should be moved into a parameter of the readable_list() method.
|
The requested change has been made. |
|
This needs to either use Oxford commas or have a static flag for them. Look |
|
Good call, I apologise for the US-English ignorance... I'll add this in over the weekend. |
|
Why the loop at the top? Why not just throw the exception in a single loop if you really want to check for type? I don't even thing it matters enough to check the types in this method. |
There was a problem hiding this comment.
This brace should be on a new line.
- Improved exception message. - Added parameter for the use of serial commas.
|
I've just pushed some changes. I've got a number of thoughts remaining:
|
|
I believe we use the serial comma in other parts of our code and documentation so the default should probably be The reason I would remove the checking is simply because the method should be usable with an array of objects that properly implement |
- Optimisation to remove unrequired loop. - "Validation" exceptions changed to: InvalidArgumentException.
|
It's really just a logical style thing. There's no other reason than having a very clear separation between "validation" and processing. It's unlikely that you're going to want to output a readable list for a huge array, so performance wise I imagine the difference will be negligible. Regardless, it's not exactly unclear to be in the one loop, and it is more efficient, so I've merged the two. I've also changed the exceptions to be instances of |
|
Now Also you need a space between the |
|
For some reason my brain must have been passively thinking that casting an object that doesn't implement I've fixed it now, and I don't particularly think it's excessive... |
|
Why all this mess while you can just copy and unset last item, implode array with comma, add conjunction with last item. $last = $words[$sum - 1]; |
|
Or use |
|
I agree, using |
|
Agreed and updated. |
|
I promise those two are my last comments :D then I'll merge it in! |
|
I've removed the empty line... Otherwise, those checks still need to be present. As an example, one of the values could be a bool, and that'd break the logic (probably without error, but that's even worse in my opinion). You could of course check that it's not a bool, but I think it's safer to check what it can be (a string, int or object that supports |
|
Fair enough, I'll merge this in as soon as I get a chance. |
…t-method refs #4626: Added readable_list() method to Text class.
This pull request adds the following feature: http://dev.kohanaframework.org/issues/4626