Skip to content

Commit

Permalink
Fix calculation of transfers (#169)
Browse files Browse the repository at this point in the history
* Fix calculation of transfers

#168

* StyleCI fixes

* Update Connection.php

* StyleCI fix

* fix transfers for direct connections

* Update Connection.php

* fix number of transfers in test data
  • Loading branch information
Kleisli authored and fabian committed Jul 20, 2017
1 parent 244b049 commit 2927977
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
9 changes: 8 additions & 1 deletion lib/Transport/Entity/Schedule/Connection.php
Expand Up @@ -155,7 +155,14 @@ public static function createFromJson($json, Connection $obj = null)
}

$obj->duration = gmdate('0z\dH:i:s', $json->duration);
$obj->transfers = count($json->legs) - 1;

$numberOfVehicles = 0;
foreach ($json->legs as $leg) {
if (isset($leg->type) && $leg->type != 'walk') {
$numberOfVehicles++;
}
}
$obj->transfers = $numberOfVehicles - 1;

if (isset($json->legs)) {
foreach ($json->legs as $leg) {
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/connections/response_2016-12-23.json
Expand Up @@ -78,7 +78,7 @@
}
},
"duration": "00d00:15:00",
"transfers": 1,
"transfers": 0,
"service": null,
"products": [
"IR"
Expand Down Expand Up @@ -334,7 +334,7 @@
}
},
"duration": "00d00:28:00",
"transfers": 1,
"transfers": 0,
"service": null,
"products": [
"S12"
Expand Down Expand Up @@ -894,7 +894,7 @@
}
},
"duration": "00d00:15:00",
"transfers": 1,
"transfers": 0,
"service": null,
"products": [
"IR"
Expand Down Expand Up @@ -1150,7 +1150,7 @@
}
},
"duration": "00d00:20:00",
"transfers": 1,
"transfers": 0,
"service": null,
"products": [
"IR"
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/connections/response_2017-06-20.json
Expand Up @@ -78,7 +78,7 @@
}
},
"duration": "00d00:30:00",
"transfers": 1,
"transfers": 0,
"service": null,
"products": [
"IC"
Expand Down Expand Up @@ -334,7 +334,7 @@
}
},
"duration": "00d00:30:00",
"transfers": 1,
"transfers": 0,
"service": null,
"products": [
"IC"
Expand Down Expand Up @@ -590,7 +590,7 @@
}
},
"duration": "00d00:30:00",
"transfers": 1,
"transfers": 0,
"service": null,
"products": [
"IC"
Expand Down Expand Up @@ -846,7 +846,7 @@
}
},
"duration": "00d00:30:00",
"transfers": 1,
"transfers": 0,
"service": null,
"products": [
"IC"
Expand Down

0 comments on commit 2927977

Please sign in to comment.