Skip to content

Commit

Permalink
Merge pull request #21 from nspalo/development
Browse files Browse the repository at this point in the history
BWA-Dev-7-Weather-App-Code-Quality
  • Loading branch information
nspalo authored Sep 10, 2023
2 parents 36e9f94 + 755b99b commit 2c17b0f
Show file tree
Hide file tree
Showing 58 changed files with 850 additions and 99 deletions.
17 changes: 16 additions & 1 deletion src/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP_NAME=Laravel
APP_NAME='Weather App'
APP_ENV=local
APP_KEY=
APP_DEBUG=true
Expand Down Expand Up @@ -56,3 +56,18 @@ VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

# OPEN WEATHER API
OPEN_WEATHER_API_URI=api.openweathermap.org/data/2.5
OPEN_WEATHER_API_KEY=
OPEN_WEATHER_UNIT=metric
OPEN_WEATHER_MAX_OUTPUT=5

# GEOAPIFY API
GEOAPIFY_API_URI=api.geoapify.com/v1/geocode/search
GEOAPIFY_API_KEY=
GEOAPIFY_FILTER=countrycode:jp
GEOAPIFY_FORMAT=json
GEOAPIFY_LANG=en
GEOAPIFY_MAX_OUTPUT=1
GEOAPIFY_TYPE=city
4 changes: 3 additions & 1 deletion src/app/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
Expand All @@ -25,7 +27,7 @@ protected function schedule(Schedule $schedule)
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
$this->load(__DIR__ . '/Commands');

require base_path('routes/console.php');
}
Expand Down
29 changes: 16 additions & 13 deletions src/app/Enums/Direction.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
<?php

declare(strict_types=1);

namespace App\Enums;

enum Direction: string
{
case North = "N";
case NorthEast = "NE";
case East = "E";
case SouthEast = "SE";
case South = "S";
case SouthWest = "SW";
case West = "W";
case NorthSouth = "NW";
case North = 'N';
case NorthEast = 'NE';
case East = 'E';
case SouthEast = 'SE';
case South = 'S';
case SouthWest = 'SW';
case West = 'W';
case NorthSouth = 'NW';

/**
* Convert Degrees to Direction using 8 Wind Compass Implementation
* Convert Degrees to Direction using 8 Point Compass Implementation
* - Cardinal Directions: N, E, S, W
* - Ordinal Directions: NE, SE, SW, NW
*/
public static function convertFromDegrees(int $degrees = 0): string
{
if($degrees < 0) {
$degrees *= -1; // Handle negative input value
if ($degrees < 0) {
// Handle negative input value
$degrees *= -1;
}

$direction = floor(($degrees/45)) % 8;
$index = \floor(($degrees / 45)) % 8;

return self::cases()[$direction]->value;
return self::cases()[$index]->value;
}
}
12 changes: 12 additions & 0 deletions src/app/Exceptions/BaseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,27 @@

class BaseException extends Exception
{
/**
* @var array|null
*/
private ?array $errors;

/**
* @param $message
* @param $code
* @param Throwable|null $previous
* @param array|null $errors
*/
public function __construct($message = '', $code = 0, ?Throwable $previous = null, ?array $errors = null)
{
parent::__construct($message, $code, $previous);

$this->errors = $errors;
}

/**
* @return array|null
*/
public function getErrors(): ?array
{
return $this->errors;
Expand Down
2 changes: 2 additions & 0 deletions src/app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class WeatherUpdateApiController extends Controller
{
protected GeoapifyApiServiceInterface $geoapifyGeocodingService;

protected OpenWeatherApiServiceFactoryInterface $weatherApiServiceFactory;

public function __construct(
Expand All @@ -30,10 +31,10 @@ public function __invoke(Request $request): JsonResource

$responseGeolocation = $this->geoapifyGeocodingService->getGeolocation($location);

$responseCurrentWeather = $this->weatherApiServiceFactory->make(WeatherTypeEnum::Current)
$responseCurrentWeather = $this->weatherApiServiceFactory->make(WeatherTypeEnum::Current)
->getWeatherData($responseGeolocation);

$responseForecastWeather = $this->weatherApiServiceFactory->make(WeatherTypeEnum::Forecast)
$responseForecastWeather = $this->weatherApiServiceFactory->make(WeatherTypeEnum::Forecast)
->getWeatherData($responseGeolocation);

$data = [
Expand Down
2 changes: 2 additions & 0 deletions src/app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
Expand Down
12 changes: 8 additions & 4 deletions src/app/Http/Controllers/WeatherApp/WeatherUpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
use App\Services\GeoapifyApi\Interfaces\GeoapifyApiServiceInterface;
use App\Services\OpenWeatherApi\Interfaces\OpenWeatherApiServiceFactoryInterface;
use Illuminate\Http\Request;
use Illuminate\View\View;

class WeatherUpdateController extends Controller
{
protected GeoapifyApiServiceInterface $geoapifyGeocodingService;

protected OpenWeatherApiServiceFactoryInterface $weatherApiServiceFactory;

public function __construct(
Expand All @@ -24,16 +24,20 @@ public function __construct(
$this->weatherApiServiceFactory = $weatherApiServiceFactory;
}

public function index(Request $request): View
/**
* @param Request $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
public function index(Request $request)
{
$location = $request->get('location') ?? \config('services.api.geoapify.default_search');

$responseGeolocation = $this->geoapifyGeocodingService->getGeolocation($location);

$responseCurrentWeather = $this->weatherApiServiceFactory->make(WeatherTypeEnum::Current)
$responseCurrentWeather = $this->weatherApiServiceFactory->make(WeatherTypeEnum::Current)
->getWeatherData($responseGeolocation);

$responseForecastWeather = $this->weatherApiServiceFactory->make(WeatherTypeEnum::Forecast)
$responseForecastWeather = $this->weatherApiServiceFactory->make(WeatherTypeEnum::Forecast)
->getWeatherData($responseGeolocation);

$data = [
Expand Down
2 changes: 2 additions & 0 deletions src/app/Http/Kernel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;
Expand Down
2 changes: 2 additions & 0 deletions src/app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;
Expand Down
2 changes: 2 additions & 0 deletions src/app/Http/Middleware/EncryptCookies.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Middleware;

use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
Expand Down
2 changes: 2 additions & 0 deletions src/app/Http/Middleware/PreventRequestsDuringMaintenance.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
Expand Down
2 changes: 2 additions & 0 deletions src/app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Middleware;

use App\Providers\RouteServiceProvider;
Expand Down
2 changes: 2 additions & 0 deletions src/app/Http/Middleware/TrimStrings.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
Expand Down
2 changes: 2 additions & 0 deletions src/app/Http/Middleware/TrustHosts.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Middleware;

use Illuminate\Http\Middleware\TrustHosts as Middleware;
Expand Down
2 changes: 2 additions & 0 deletions src/app/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Middleware;

use Illuminate\Http\Middleware\TrustProxies as Middleware;
Expand Down
2 changes: 2 additions & 0 deletions src/app/Http/Middleware/ValidateSignature.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Middleware;

use Illuminate\Routing\Middleware\ValidateSignature as Middleware;
Expand Down
2 changes: 2 additions & 0 deletions src/app/Http/Middleware/VerifyCsrfToken.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
Expand Down
2 changes: 2 additions & 0 deletions src/app/Models/User.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
Expand Down
2 changes: 2 additions & 0 deletions src/app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
Expand Down
2 changes: 2 additions & 0 deletions src/app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Providers;

// use Illuminate\Support\Facades\Gate;
Expand Down
2 changes: 2 additions & 0 deletions src/app/Providers/BroadcastServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Providers;

use Illuminate\Support\Facades\Broadcast;
Expand Down
2 changes: 2 additions & 0 deletions src/app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Providers;

use Illuminate\Auth\Events\Registered;
Expand Down
2 changes: 2 additions & 0 deletions src/app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Providers;

use Illuminate\Cache\RateLimiting\Limit;
Expand Down
2 changes: 2 additions & 0 deletions src/app/Providers/WeatherAppServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Providers;

use App\Services\ConfigurationMapper\Interfaces\ServiceConfigurationMapperInterface;
Expand Down
5 changes: 5 additions & 0 deletions src/app/Services/Collector/ServiceCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class ServiceCollector
{
/**
* @param iterable $objects
* @param string $class
* @return array
*/
public static function filterByClass(iterable $objects, string $class): array
{
$objects = $objects instanceof \Traversable ? \iterator_to_array($objects) : (array) $objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@

interface ServiceConfigurationMapperInterface
{
/**
* @param string|null $config
* @return void
*/
public function loadConfig(?string $config = null): void;

/**
* @param array $keyMapping
* @return array
*/
public function map(array $keyMapping): array;

/**
* @param string $key
* @return string|null
*/
public function getByKey(string $key): ?string;
}
Loading

0 comments on commit 2c17b0f

Please sign in to comment.