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
Show file tree
Hide file tree
Changes from 2 commits
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
30 changes: 15 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,21 @@ Each of the generator properties (like `name`, `address`, and `lorem`) are calle

### `Faker\Provider\en_US\Address`

cityPrefix // 'Lake'
secondaryAddress // 'Suite 961'
state // 'NewMexico'
stateAbbr // 'OH'
citySuffix // 'borough'
streetSuffix // 'Keys'
buildingNumber // '484'
city // 'West Judge'
streetName // 'Keegan Trail'
streetAddress // '439 Karley Loaf Suite 897'
postcode // '17916'
address // '8888 Cummings Vista Apt. 101, Susanbury, NY 95473'
country // 'Falkland Islands (Malvinas)'
latitude // 77.147489
longitude // 86.211205
cityPrefix // 'Lake'
secondaryAddress // 'Suite 961'
state // 'NewMexico'
stateAbbr // 'OH'
citySuffix // 'borough'
streetSuffix // 'Keys'
buildingNumber // '484'
city // 'West Judge'
streetName // 'Keegan Trail'
streetAddress // '439 Karley Loaf Suite 897'
postcode // '17916'
address // '8888 Cummings Vista Apt. 101, Susanbury, NY 95473'
country // 'Falkland Islands (Malvinas)'
latitude($min = -90, $max = 90) // 77.147489
longitude($min = -180, $max = 180) // 86.211205

### `Faker\Provider\en_US\PhoneNumber`

Expand Down
16 changes: 10 additions & 6 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
* @example '77.147489'
* @param float|int $min
* @param float|int $max
* @return float Uses signed degrees format (returns a float number between -90 and 90)
*/
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 floatval(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.

I don't understand the interest of converting a float to string (with number_format) and then back to float (with floatval)

}

/**
* @example 86.211205
* @example '86.211205'
* @param float|int $min
* @param float|int $max
* @return float Uses signed degrees format (returns a float number between -180 and 180)
*/
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 floatval(number_format(mt_rand($min * 1000000, $max * 1000000)/1000000, 6));
}
}