Add length and weight conversion classes with input validation issue fixed#187
Add length and weight conversion classes with input validation issue fixed#187haj8110 wants to merge 2 commits intoTheAlgorithms:masterfrom
Conversation
There was a problem hiding this comment.
PSR‑12 expects StudlyCaps class names and generally one class per file with matching filename (StudlyCaps). Please rename file to:
- Conversions/LengthConversions.php
(Also update DIRECTORY.md entries to the exact casing.)
There was a problem hiding this comment.
PSR‑12 expects StudlyCaps class names and generally one class per file with matching filename (StudlyCaps). Please rename files to:
- Conversions/WeightConversions.php
(Also update DIRECTORY.md entries to the exact casing.)
| if (!is_numeric($m)) { | ||
| throw new \InvalidArgumentException("Invalid input for mToKm: expected numeric, got string ('{$m}')"); | ||
| } | ||
| return round($m / 1000, 6); |
There was a problem hiding this comment.
Rather than using magic numbers like this (example, 1000) - I'd prefer to use named class constants, e.g.
private const M_PER_KM = 1000.0;
private const KM_PER_MI = 1.609344; // exact standard
private const IN_PER_CM = 0.39370078740157477; // 1 / 2.54
Same for the other magic numbers used in this file...
There was a problem hiding this comment.
Thanks for the contribution! A few requested changes to align with our standards:
- Rename files to Conversions/LengthConversions.php and Conversions/WeightConversions.php so filenames match StudlyCaps class names (PSR‑12).
- Replace conversion factors with accurate constants (lb_to_kg = 0.45359237, mile_to_km = 1.609344, km_to_mile = 0.621371192, etc.) and make rounding precision consistent (or configurable).
- Consider adding the namespace
Conversions; to match folder structure (or align with existing style in other conversion files). - Update DIRECTORY.md entries to match the new filenames/casing and any ordering rules.
The small elseif cleanup and php_codesniffer bump look good. Once the above are addressed, this should be in great shape. Thanks again!
No description provided.