Skip to content

Commit

Permalink
Fixed bug where pollen forecast was not provided. Fixed incorrect par…
Browse files Browse the repository at this point in the history
…ameters in README.
  • Loading branch information
rugaard committed Sep 24, 2019
1 parent ba91529 commit e97a5fe
Show file tree
Hide file tree
Showing 3 changed files with 1,346 additions and 23 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ extendedForecast();
Search locations by name.

```php
search(string $query, int $locationId);
search(string $query, int $limit);
```

| Parameter | Type | Default | Description |
Expand Down Expand Up @@ -183,7 +183,7 @@ Get current weather condition and latest forecast for a location specified by co
_Note: `$includeRegional` is required to get `municipality` and `region` of location._

```php
locationByCoordinate(float $latitude, float $longitude, bool $includeWarnings);
locationByCoordinate(float $latitude, float $longitude, bool $includeRegional, bool $includeWarnings);
```

| Parameter | Type | Default | Description |
Expand Down Expand Up @@ -393,4 +393,4 @@ By implementing some form of internal caching, we could cache these kind of endp
## 🚓 License
This package is licensed under a [Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 (CC BY-NC-ND 4.0)](https://creativecommons.org/licenses/by-nc-nd/4.0/).

<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-nd/4.0/88x31.png" /></a>
<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-nd/4.0/88x31.png" /></a>
46 changes: 26 additions & 20 deletions src/DTO/Pollen.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,28 @@ class Pollen extends AbstractDTO
*/
public function parse(array $data) : void
{
$this->setName($data['name'])
->setForecast($data['forecast'])
->setReadings(Collection::make($data['readings']->xpath('reading'))->map(function ($data) {
// Convert to array.
$data = (array) $data;

if (in_array($data['name'], ['Alternaria', 'Cladosporium'])) {
$data['level'] = $this->determinePollenLevelByText($data['value']);
$data['value'] = null;
} else {
$data['value'] = is_numeric($data['value']) ? (int) $data['value'] : 0;
$data['level'] = $this->getPollenLevel($data['name'], $data['value']);
}

return Collection::make($data);
}));
$this->setName($data['name']);

if (isset($data['forecast']) && $data['forecast']->count() > 0) {
$this->setForecast($data['forecast']);
}

if (isset($data['readings']) && $data['readings']->count() > 0) {
$this->setReadings(Collection::make($data['readings']->xpath('reading'))->map(function ($data) {
// Convert to array.
$data = (array) $data;

if (in_array($data['name'], ['Alternaria', 'Cladosporium'])) {
$data['level'] = $this->determinePollenLevelByText($data['value']);
$data['value'] = null;
} else {
$data['value'] = is_numeric($data['value']) ? (int)$data['value'] : 0;
$data['level'] = $this->getPollenLevel($data['name'], $data['value']);
}

return Collection::make($data);
}));
}
}

/**
Expand Down Expand Up @@ -98,7 +104,7 @@ public function setForecast(string $forecast) : self
*
* @return string|null
*/
public function getForecast() : string
public function getForecast() :? string
{
return $this->forecast;
}
Expand All @@ -118,9 +124,9 @@ public function setReadings(Collection $readings) : self
/**
* Get pollen readings.
*
* @return \Tightenco\Collect\Support\Collection
* @return \Tightenco\Collect\Support\Collection|null
*/
public function getReadings() : Collection
public function getReadings() :? Collection
{
return $this->readings;
}
Expand Down Expand Up @@ -197,4 +203,4 @@ protected function determinePollenLevelByText(string $value) :? string
return null;
}
}
}
}
Loading

0 comments on commit e97a5fe

Please sign in to comment.