Skip to content

Commit 903f7da

Browse files
committed
chore: changed measurementSystem to unitSystem to be in accordance to API naming
1 parent 1804655 commit 903f7da

16 files changed

+97
-97
lines changed

src/Config.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use ProgrammatorDev\OpenWeatherMap\Exception\ValidationException;
66
use ProgrammatorDev\OpenWeatherMap\HttpClient\HttpClientBuilder;
77
use ProgrammatorDev\OpenWeatherMap\Language\Language;
8-
use ProgrammatorDev\OpenWeatherMap\MeasurementSystem\MeasurementSystem;
8+
use ProgrammatorDev\OpenWeatherMap\UnitSystem\UnitSystem;
99
use ProgrammatorDev\OpenWeatherMap\Validator\BlankValidatorTrait;
1010
use ProgrammatorDev\OpenWeatherMap\Validator\ChoiceValidatorTrait;
1111
use Psr\Cache\CacheItemPoolInterface;
@@ -29,7 +29,7 @@ public function __construct(array $options = [])
2929
private function configureOptions(OptionsResolver $resolver): void
3030
{
3131
$resolver->setDefaults([
32-
'measurementSystem' => MeasurementSystem::METRIC,
32+
'unitSystem' => UnitSystem::METRIC,
3333
'language' => Language::ENGLISH,
3434
'httpClientBuilder' => new HttpClientBuilder(),
3535
'cache' => null,
@@ -39,7 +39,7 @@ private function configureOptions(OptionsResolver $resolver): void
3939
$resolver->setRequired('applicationKey');
4040

4141
$resolver->setAllowedTypes('applicationKey', 'string');
42-
$resolver->setAllowedTypes('measurementSystem', 'string');
42+
$resolver->setAllowedTypes('unitSystem', 'string');
4343
$resolver->setAllowedTypes('language', 'string');
4444
$resolver->setAllowedTypes('httpClientBuilder', HttpClientBuilder::class);
4545
$resolver->setAllowedTypes('cache', ['null', CacheItemPoolInterface::class]);
@@ -48,7 +48,7 @@ private function configureOptions(OptionsResolver $resolver): void
4848
$resolver->setAllowedValues('applicationKey', function($value) {
4949
return !empty($value);
5050
});
51-
$resolver->setAllowedValues('measurementSystem', MeasurementSystem::getList());
51+
$resolver->setAllowedValues('unitSystem', UnitSystem::getList());
5252
$resolver->setAllowedValues('language', Language::getList());
5353
}
5454

@@ -69,19 +69,19 @@ public function setApplicationKey(string $applicationKey): self
6969
return $this;
7070
}
7171

72-
public function getMeasurementSystem(): string
72+
public function getUnitSystem(): string
7373
{
74-
return $this->options['measurementSystem'];
74+
return $this->options['unitSystem'];
7575
}
7676

7777
/**
7878
* @throws ValidationException
7979
*/
80-
public function setMeasurementSystem(string $measurementSystem): self
80+
public function setUnitSystem(string $unitSystem): self
8181
{
82-
$this->validateChoice('measurementSystem', $measurementSystem, MeasurementSystem::getList());
82+
$this->validateChoice('unitSystem', $unitSystem, UnitSystem::getList());
8383

84-
$this->options['measurementSystem'] = $measurementSystem;
84+
$this->options['unitSystem'] = $unitSystem;
8585

8686
return $this;
8787
}

src/Endpoint/AbstractEndpoint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class AbstractEndpoint
3535

3636
private ?LoggerInterface $logger;
3737

38-
protected string $measurementSystem;
38+
protected string $unitSystem;
3939

4040
protected string $language;
4141

@@ -48,7 +48,7 @@ public function __construct(protected OpenWeatherMap $api)
4848
$this->httpClientBuilder = $this->config->getHttpClientBuilder();
4949
$this->cache = $this->config->getCache();
5050
$this->logger = $this->config->getLogger();
51-
$this->measurementSystem = $this->config->getMeasurementSystem();
51+
$this->unitSystem = $this->config->getUnitSystem();
5252
$this->language = $this->config->getLanguage();
5353
}
5454

src/Endpoint/OneCallEndpoint.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Http\Client\Exception;
66
use ProgrammatorDev\OpenWeatherMap\Endpoint\Util\WithLanguageTrait;
7-
use ProgrammatorDev\OpenWeatherMap\Endpoint\Util\WithMeasurementSystemTrait;
7+
use ProgrammatorDev\OpenWeatherMap\Endpoint\Util\WithUnitSystemTrait;
88
use ProgrammatorDev\OpenWeatherMap\Entity\OneCall\HistoryDaySummary;
99
use ProgrammatorDev\OpenWeatherMap\Entity\OneCall\HistoryMoment;
1010
use ProgrammatorDev\OpenWeatherMap\Entity\OneCall\OneCall;
@@ -19,7 +19,7 @@
1919

2020
class OneCallEndpoint extends AbstractEndpoint
2121
{
22-
use WithMeasurementSystemTrait;
22+
use WithUnitSystemTrait;
2323
use WithLanguageTrait;
2424
use CoordinateValidatorTrait;
2525
use LessThanValidatorTrait;
@@ -49,7 +49,7 @@ public function getWeather(float $latitude, float $longitude): OneCall
4949
query: [
5050
'lat' => $latitude,
5151
'lon' => $longitude,
52-
'units' => $this->getMeasurementSystem(),
52+
'units' => $this->getUnitSystem(),
5353
'lang' => $this->getLanguage()
5454
]
5555
);
@@ -78,7 +78,7 @@ public function getHistoryMoment(float $latitude, float $longitude, \DateTimeInt
7878
'lat' => $latitude,
7979
'lon' => $longitude,
8080
'dt' => $dateTime->setTimezone(new \DateTimeZone('UTC'))->getTimestamp(),
81-
'units' => $this->getMeasurementSystem(),
81+
'units' => $this->getUnitSystem(),
8282
'lang' => $this->getLanguage()
8383
]
8484
);
@@ -107,7 +107,7 @@ public function getHistoryDaySummary(float $latitude, float $longitude, \DateTim
107107
'lat' => $latitude,
108108
'lon' => $longitude,
109109
'date' => $dateTime->format('Y-m-d'),
110-
'units' => $this->getMeasurementSystem(),
110+
'units' => $this->getUnitSystem(),
111111
'lang' => $this->getLanguage()
112112
]
113113
);

src/Endpoint/Util/WithMeasurementSystemTrait.php

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace ProgrammatorDev\OpenWeatherMap\Endpoint\Util;
4+
5+
use ProgrammatorDev\OpenWeatherMap\UnitSystem\UnitSystem;
6+
use ProgrammatorDev\OpenWeatherMap\Validator\ChoiceValidatorTrait;
7+
8+
trait WithUnitSystemTrait
9+
{
10+
use ChoiceValidatorTrait;
11+
12+
public function withUnitSystem(string $unitSystem): static
13+
{
14+
$this->validateChoice('unitSystem', $unitSystem, UnitSystem::getList());
15+
16+
$clone = clone $this;
17+
$clone->unitSystem = $unitSystem;
18+
19+
return $clone;
20+
}
21+
22+
public function getUnitSystem(): string
23+
{
24+
return $this->unitSystem;
25+
}
26+
}

src/Endpoint/WeatherEndpoint.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Http\Client\Exception;
66
use ProgrammatorDev\OpenWeatherMap\Endpoint\Util\WithLanguageTrait;
7-
use ProgrammatorDev\OpenWeatherMap\Endpoint\Util\WithMeasurementSystemTrait;
7+
use ProgrammatorDev\OpenWeatherMap\Endpoint\Util\WithUnitSystemTrait;
88
use ProgrammatorDev\OpenWeatherMap\Entity\Weather\CurrentWeather;
99
use ProgrammatorDev\OpenWeatherMap\Entity\Weather\WeatherList;
1010
use ProgrammatorDev\OpenWeatherMap\Exception\BadRequestException;
@@ -18,7 +18,7 @@
1818

1919
class WeatherEndpoint extends AbstractEndpoint
2020
{
21-
use WithMeasurementSystemTrait;
21+
use WithUnitSystemTrait;
2222
use WithLanguageTrait;
2323
use CoordinateValidatorTrait;
2424
use GreaterThanValidatorTrait;
@@ -48,7 +48,7 @@ public function getCurrent(float $latitude, float $longitude): CurrentWeather
4848
query: [
4949
'lat' => $latitude,
5050
'lon' => $longitude,
51-
'units' => $this->getMeasurementSystem(),
51+
'units' => $this->getUnitSystem(),
5252
'lang' => $this->getLanguage()
5353
]
5454
);
@@ -77,7 +77,7 @@ public function getForecast(float $latitude, float $longitude, int $numResults =
7777
'lat' => $latitude,
7878
'lon' => $longitude,
7979
'cnt' => $numResults,
80-
'units' => $this->getMeasurementSystem(),
80+
'units' => $this->getUnitSystem(),
8181
'lang' => $this->getLanguage()
8282
]
8383
);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace ProgrammatorDev\OpenWeatherMap\MeasurementSystem;
3+
namespace ProgrammatorDev\OpenWeatherMap\UnitSystem;
44

55
class Fahrenheit
66
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace ProgrammatorDev\OpenWeatherMap\MeasurementSystem;
3+
namespace ProgrammatorDev\OpenWeatherMap\UnitSystem;
44

55
class Imperial
66
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace ProgrammatorDev\OpenWeatherMap\MeasurementSystem;
3+
namespace ProgrammatorDev\OpenWeatherMap\UnitSystem;
44

55
class Standard
66
{

src/MeasurementSystem/MeasurementSystem.php renamed to src/UnitSystem/UnitSystem.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
namespace ProgrammatorDev\OpenWeatherMap\MeasurementSystem;
3+
namespace ProgrammatorDev\OpenWeatherMap\UnitSystem;
44

5-
class MeasurementSystem
5+
class UnitSystem
66
{
77
public const METRIC = 'metric';
88
public const IMPERIAL = 'imperial';

0 commit comments

Comments
 (0)