Skip to content

Commit fcb9c51

Browse files
committed
chore: change traits to static class helpers
1 parent b7940b6 commit fcb9c51

File tree

11 files changed

+29
-47
lines changed

11 files changed

+29
-47
lines changed

src/Entity/AirPollution/AirPollutionCollection.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
namespace ProgrammatorDev\OpenWeatherMap\Entity\AirPollution;
44

55
use ProgrammatorDev\OpenWeatherMap\Entity\Coordinate;
6-
use ProgrammatorDev\OpenWeatherMap\Util\EntityTrait;
6+
use ProgrammatorDev\OpenWeatherMap\Helper\EntityHelper;
77

88
class AirPollutionCollection
99
{
10-
use EntityTrait;
11-
1210
private int $numResults;
1311

1412
private Coordinate $coordinate;
@@ -20,7 +18,7 @@ public function __construct(array $data)
2018
{
2119
$this->numResults = count($data['list']);
2220
$this->coordinate = new Coordinate($data['coord']);
23-
$this->data = $this->createEntityList(AirPollutionData::class, $data['list']);
21+
$this->data = EntityHelper::createEntityList(AirPollutionData::class, $data['list']);
2422
}
2523

2624
public function getNumResults(): int

src/Entity/Assistant/Answer.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
namespace ProgrammatorDev\OpenWeatherMap\Entity\Assistant;
44

5-
use ProgrammatorDev\OpenWeatherMap\Util\EntityTrait;
5+
use ProgrammatorDev\OpenWeatherMap\Helper\EntityHelper;
66

77
class Answer
88
{
9-
use EntityTrait;
10-
119
private string $answer;
1210

1311
private string $sessionId;
@@ -21,7 +19,7 @@ public function __construct(array $data)
2119
$this->sessionId = $data['session_id'];
2220

2321
if (!empty($data['data'])) {
24-
$this->data = $this->createEntityKeyList(WeatherData::class, $data['data']);
22+
$this->data = EntityHelper::createEntityKeyList(WeatherData::class, $data['data']);
2523
}
2624
}
2725

src/Entity/BaseWeather.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
namespace ProgrammatorDev\OpenWeatherMap\Entity;
44

5-
use ProgrammatorDev\OpenWeatherMap\Util\EntityTrait;
5+
use ProgrammatorDev\OpenWeatherMap\Helper\EntityHelper;
66

77
class BaseWeather
88
{
9-
use EntityTrait;
10-
119
private \DateTimeImmutable $dateTime;
1210

1311
private int $atmosphericPressure;
@@ -44,7 +42,7 @@ public function __construct(array $data)
4442
'gust' => $data['wind_gust'] ?? null
4543
]);
4644

47-
$this->conditions = $this->createEntityList(Condition::class, $data['weather']);
45+
$this->conditions = EntityHelper::createEntityList(Condition::class, $data['weather']);
4846
$this->rainVolume = $data['rain']['1h'] ?? $data['rain']['3h'] ?? $data['rain'] ?? null;
4947
$this->snowVolume = $data['snow']['1h'] ?? $data['snow']['3h'] ?? $data['snow'] ?? null;
5048
}

src/Entity/OneCall/Weather.php

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

55
use ProgrammatorDev\OpenWeatherMap\Entity\Coordinate;
66
use ProgrammatorDev\OpenWeatherMap\Entity\Timezone;
7-
use ProgrammatorDev\OpenWeatherMap\Util\EntityTrait;
7+
use ProgrammatorDev\OpenWeatherMap\Helper\EntityHelper;
88

99
class Weather
1010
{
11-
use EntityTrait;
12-
1311
private Coordinate $coordinate;
1412

1513
private Timezone $timezone;
@@ -43,14 +41,14 @@ public function __construct(array $data)
4341
$this->current = new WeatherData($data['current']);
4442

4543
$this->minutelyForecast = isset($data['minutely'])
46-
? $this->createEntityList(MinuteData::class, $data['minutely'])
44+
? EntityHelper::createEntityList(MinuteData::class, $data['minutely'])
4745
: null;
4846

49-
$this->hourlyForecast = $this->createEntityList(HourData::class, $data['hourly']);
50-
$this->dailyForecast = $this->createEntityList(DayData::class, $data['daily']);
47+
$this->hourlyForecast = EntityHelper::createEntityList(HourData::class, $data['hourly']);
48+
$this->dailyForecast = EntityHelper::createEntityList(DayData::class, $data['daily']);
5149

5250
$this->alerts = isset($data['alerts'])
53-
? $this->createEntityList(Alert::class, $data['alerts'])
51+
? EntityHelper::createEntityList(Alert::class, $data['alerts'])
5452
: null;
5553
}
5654

src/Entity/Weather/WeatherCollection.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
namespace ProgrammatorDev\OpenWeatherMap\Entity\Weather;
44

55
use ProgrammatorDev\OpenWeatherMap\Entity\Location;
6-
use ProgrammatorDev\OpenWeatherMap\Util\EntityTrait;
6+
use ProgrammatorDev\OpenWeatherMap\Helper\EntityHelper;
77

88
class WeatherCollection
99
{
10-
use EntityTrait;
11-
1210
private int $numResults;
1311

1412
private Location $location;
@@ -32,7 +30,7 @@ public function __construct(array $data)
3230
'timezone_offset' => $data['city']['timezone']
3331
]);
3432

35-
$this->data = $this->createEntityList(WeatherData::class, $data['list']);
33+
$this->data = EntityHelper::createEntityList(WeatherData::class, $data['list']);
3634
}
3735

3836
public function getNumResults(): int

src/Entity/Weather/WeatherData.php

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

55
use ProgrammatorDev\OpenWeatherMap\Entity\Condition;
66
use ProgrammatorDev\OpenWeatherMap\Entity\Wind;
7-
use ProgrammatorDev\OpenWeatherMap\Util\EntityTrait;
7+
use ProgrammatorDev\OpenWeatherMap\Helper\EntityHelper;
88

99
class WeatherData
1010
{
11-
use EntityTrait;
12-
1311
private \DateTimeImmutable $dateTime;
1412

1513
private float $temperature;
@@ -50,7 +48,7 @@ public function __construct(array $data)
5048
$this->cloudiness = $data['clouds']['all'];
5149
$this->visibility = $data['visibility'];
5250
$this->atmosphericPressure = $data['main']['pressure'];
53-
$this->conditions = $this->createEntityList(Condition::class, $data['weather']);
51+
$this->conditions = EntityHelper::createEntityList(Condition::class, $data['weather']);
5452
$this->wind = new Wind($data['wind']);
5553

5654
$this->precipitationProbability = isset($data['pop'])

src/Util/EntityTrait.php renamed to src/Helper/EntityHelper.php

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

3-
namespace ProgrammatorDev\OpenWeatherMap\Util;
3+
namespace ProgrammatorDev\OpenWeatherMap\Helper;
44

5-
trait EntityTrait
5+
class EntityHelper
66
{
7-
private function createEntityList(string $entityClass, array $list): array
7+
public static function createEntityList(string $entityClass, array $list): array
88
{
99
return array_map(function(array $data) use ($entityClass) {
1010
return new $entityClass($data);
1111
}, $list);
1212
}
1313

14-
private function createEntityKeyList(string $entityClass, array $list): array
14+
public static function createEntityKeyList(string $entityClass, array $list): array
1515
{
1616
return array_map(function(array $data, int|string $key) use ($entityClass) {
1717
return new $entityClass($key, $data);

src/Util/ReflectionTrait.php renamed to src/Helper/ReflectionHelper.php

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

3-
namespace ProgrammatorDev\OpenWeatherMap\Util;
3+
namespace ProgrammatorDev\OpenWeatherMap\Helper;
44

5-
trait ReflectionTrait
5+
class ReflectionHelper
66
{
7-
private function getClassConstants(string $className): array
7+
public static function getClassConstants(string $className): array
88
{
99
$class = new \ReflectionClass($className);
1010
$constants = $class->getConstants();

src/Language/Language.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
namespace ProgrammatorDev\OpenWeatherMap\Language;
44

5-
use ProgrammatorDev\OpenWeatherMap\Util\ReflectionTrait;
5+
use ProgrammatorDev\OpenWeatherMap\Helper\ReflectionHelper;
66

77
class Language
88
{
9-
use ReflectionTrait;
10-
119
public const AFRIKAANS = 'af';
1210
public const ALBANIAN = 'al';
1311
public const ARABIC = 'ar';
@@ -57,6 +55,6 @@ class Language
5755

5856
public static function getOptions(): array
5957
{
60-
return (new Language)->getClassConstants(self::class);
58+
return ReflectionHelper::getClassConstants(self::class);
6159
}
6260
}

src/Resource/GeocodingResource.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
use ProgrammatorDev\Api\Method;
66
use ProgrammatorDev\OpenWeatherMap\Entity\Geocoding\ZipLocation;
77
use ProgrammatorDev\OpenWeatherMap\Entity\Location;
8-
use ProgrammatorDev\OpenWeatherMap\Util\EntityTrait;
8+
use ProgrammatorDev\OpenWeatherMap\Helper\EntityHelper;
99
use Psr\Http\Client\ClientExceptionInterface;
1010

1111
class GeocodingResource extends Resource
1212
{
13-
use EntityTrait;
14-
1513
private const NUM_RESULTS = 5;
1614

1715
/**
@@ -31,7 +29,7 @@ public function getByLocationName(string $locationName, int $numResults = self::
3129
]
3230
);
3331

34-
return $this->createEntityList(Location::class, $data);
32+
return EntityHelper::createEntityList(Location::class, $data);
3533
}
3634

3735
/**
@@ -70,6 +68,6 @@ public function getByCoordinate(float $latitude, float $longitude, int $numResul
7068
]
7169
);
7270

73-
return $this->createEntityList(Location::class, $data);
71+
return EntityHelper::createEntityList(Location::class, $data);
7472
}
7573
}

0 commit comments

Comments
 (0)