Skip to content

Add length and weight conversion classes with input validation issue fixed #187

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

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

Conversation

haj8110
Copy link

@haj8110 haj8110 commented Jul 11, 2025

No description provided.

@haj8110 haj8110 changed the title My feature branch Add length and weight conversion classes with input validation issue fixed Jul 11, 2025
Copy link
Contributor

@darwinz darwinz Aug 19, 2025

Choose a reason for hiding this comment

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

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.)

Copy link
Contributor

Choose a reason for hiding this comment

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

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);
Copy link
Contributor

@darwinz darwinz Aug 19, 2025

Choose a reason for hiding this comment

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

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...

Copy link
Contributor

@darwinz darwinz left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! A few requested changes to align with our standards:

  1. Rename files to Conversions/LengthConversions.php and Conversions/WeightConversions.php so filenames match StudlyCaps class names (PSR‑12).
  2. 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).
  3. Consider adding the namespace Conversions; to match folder structure (or align with existing style in other conversion files).
  4. 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!

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.

2 participants