patternphpMinor
Retrieving information and images for rental properties using an API
Viewed 0 times
imagesrentalpropertiesforusingandretrievingapiinformation
Problem
I would like advice on making my code more elegant and straightforward. The code works great, but it lacks these things.
```
url = "https://app.kigo.net/api/ra/v1/listProperties";
$obj->user = "bla";
$obj->pass = "bla";
$obj->data = json_encode(null);
$list = $obj->curlkigo();
$directory = 'uploads';
$list = $list['API_REPLY'];
$c = count($list);
$kigopropid = array();
for($i=0;$i $prop_id) {
$obj = new kigo();
$obj->url = "https://app.kigo.net/api/ra/v1/readProperty";
$obj->user = "bla";
$obj->pass = "bla";
$obj->data = json_encode(array("PROP_ID" => $prop_id));
$obj->curlkigo();
$data = $obj->curlkigo();
//-----------Prop Name
$title = $propname[$tau].'
';
$tau++;
//-----------Adress informations
$strnr = unarr($data, 'PROP_STREETNO');
$addr1 = unarr($data, 'PROP_ADDR1');
$addr2 = unarr($data, 'PROP_ADDR2');
$addr3 = unarr($data, 'PROP_ADDR3');
$aptno = unarr($data, 'PROP_APTNO');
$prop_postcode = unarr($data, 'PROP_POSTCODE');
$prop_city = unarr($data, 'PROP_CITY');
$prop_region = unarr($data, 'PROP_REGION');
$prop_country = unarr($data, 'PROP_COUNTRY');
$prop_lat = unarr($data, 'PROP_LATITUDE');
$prop_long = unarr($data, 'PROP_LONGITUDE');
$prop_axcode = unarr($data, 'PROP_AXSCODE');
$adress = '
Adress
Primary Adress: '.$addr1.'
Secondary adress: '. $addr2.'
Tertiary adress: '.$addr3.'
Street number: '. $strnr.'
Apartment number: '. $aptno.'
Postcode: '. $prop_postcode.'
City: '. $prop_city.'
Country: '. $prop_country.'
Latitude: '. $prop_lat.'
Longitude: '. $prop_long.'
';
//-----------Property descriptions
$name = unarr($data, 'PROP_NAME');
$instant_book = unarr($data, 'PROP_INSTANT_BOOK');
$metadescription = unarr($data, 'PROP_SHORTDESCRIPTION');
```
url = "https://app.kigo.net/api/ra/v1/listProperties";
$obj->user = "bla";
$obj->pass = "bla";
$obj->data = json_encode(null);
$list = $obj->curlkigo();
$directory = 'uploads';
$list = $list['API_REPLY'];
$c = count($list);
$kigopropid = array();
for($i=0;$i $prop_id) {
$obj = new kigo();
$obj->url = "https://app.kigo.net/api/ra/v1/readProperty";
$obj->user = "bla";
$obj->pass = "bla";
$obj->data = json_encode(array("PROP_ID" => $prop_id));
$obj->curlkigo();
$data = $obj->curlkigo();
//-----------Prop Name
$title = $propname[$tau].'
';
$tau++;
//-----------Adress informations
$strnr = unarr($data, 'PROP_STREETNO');
$addr1 = unarr($data, 'PROP_ADDR1');
$addr2 = unarr($data, 'PROP_ADDR2');
$addr3 = unarr($data, 'PROP_ADDR3');
$aptno = unarr($data, 'PROP_APTNO');
$prop_postcode = unarr($data, 'PROP_POSTCODE');
$prop_city = unarr($data, 'PROP_CITY');
$prop_region = unarr($data, 'PROP_REGION');
$prop_country = unarr($data, 'PROP_COUNTRY');
$prop_lat = unarr($data, 'PROP_LATITUDE');
$prop_long = unarr($data, 'PROP_LONGITUDE');
$prop_axcode = unarr($data, 'PROP_AXSCODE');
$adress = '
Adress
Primary Adress: '.$addr1.'
Secondary adress: '. $addr2.'
Tertiary adress: '.$addr3.'
Street number: '. $strnr.'
Apartment number: '. $aptno.'
Postcode: '. $prop_postcode.'
City: '. $prop_city.'
Country: '. $prop_country.'
Latitude: '. $prop_lat.'
Longitude: '. $prop_long.'
';
//-----------Property descriptions
$name = unarr($data, 'PROP_NAME');
$instant_book = unarr($data, 'PROP_INSTANT_BOOK');
$metadescription = unarr($data, 'PROP_SHORTDESCRIPTION');
Solution
Yep not bad certainly seen worse
- Try to keep your spacing consistant for example you do
for()but
foreach () one or the other- Doing this
} else $image_ret = 0;is generally bad for readability / good code try to either use full if () { } else { } with the results of the if on separate lines or use ternary's where possible.
- Try to segment off your process code from your display code so put your process code in functions/methods etc and have those accept the inputs and spit back vars then have your display side of things prepare the html and put your output into it. Ignore people telling you to use frameworks as they're all generally horrible anyway. Better off learning to write better code yourself and if required use something like twig for layout.
Context
StackExchange Code Review Q#36163, answer score: 7
Revisions (0)
No revisions yet.