Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

min / max for lat long values #570

Merged
merged 5 commits into from
Feb 23, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/Faker/Provider/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,24 @@ public static function country()
}

/**
* @example 77.147489
* @return float Uses signed degrees format (returns a float number between -90 and 90)
* @example '77.147489'
* @param int $min
Copy link
Owner

Choose a reason for hiding this comment

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

it's a float, not an int, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for missing that, Phpstorm decided it, not me :)

* @param int $max
* @return string
*/
public static function latitude()
public static function latitude($min = -90, $max = 90)
Copy link
Owner

Choose a reason for hiding this comment

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

You're changing the results of existing calls. Please use 0 and 180 as min and max values.

Copy link
Contributor

Choose a reason for hiding this comment

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

He isn't. Look again.

Copy link
Owner

Choose a reason for hiding this comment

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

My bad, you're right.

{
return static::randomFloat(6, 0, 180) - 90;
return number_format(mt_rand($min * 1000000, $max * 1000000)/1000000, 6);
Copy link
Owner

Choose a reason for hiding this comment

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

why don't you use random_float anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a coordinate, not a "just" float number. So I decided to update lat lng functions

Copy link
Owner

Choose a reason for hiding this comment

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

Still, static::randomFloat() seems to be a better option:

// not that clear
return mt_rand($min * 1000000, $max * 1000000)/1000000;
// better
return static::randomFloat(6, $min, $max);

}

/**
* @example 86.211205
* @return float Uses signed degrees format (returns a float number between -180 and 180)
* @example '86.211205'
* @param int $min
* @param int $max
* @return string
*/
public static function longitude()
public static function longitude($min = -180, $max = 180)
Copy link
Owner

Choose a reason for hiding this comment

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

You're changing the results of existing calls. Please use 0 and 360 as min and max values.

Copy link
Owner

Choose a reason for hiding this comment

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

Disregard.

{
return static::randomFloat(6, 0, 360) - 180;
return number_format(mt_rand($min * 1000000, $max * 1000000)/1000000, 6);
}
}