Skip to content

Commit

Permalink
run pint to reformat laravel
Browse files Browse the repository at this point in the history
  • Loading branch information
crysg committed Jan 9, 2025
1 parent 8d6cf1f commit d512810
Show file tree
Hide file tree
Showing 25 changed files with 80 additions and 103 deletions.
2 changes: 1 addition & 1 deletion app/Actions/Jetstream/AddTeamMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AddTeamMember implements AddsTeamMembers
/**
* Add a new team member to the given team.
*/
public function add(User $user, Team $team, string $email, string $role = null): void
public function add(User $user, Team $team, string $email, ?string $role = null): void
{
Gate::forUser($user)->authorize('addTeamMember', $team);

Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Jetstream/InviteTeamMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class InviteTeamMember implements InvitesTeamMembers
/**
* Invite a new team member to the given team.
*/
public function invite(User $user, Team $team, string $email, string $role = null): void
public function invite(User $user, Team $team, string $email, ?string $role = null): void
{
Gate::forUser($user)->authorize('addTeamMember', $team);

Expand Down
21 changes: 13 additions & 8 deletions app/Http/Controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace App\Http\Controllers;

use Laravel\Socialite\Facades\Socialite;
use Illuminate\Support\Facades\Auth;
use Exception;
use App\Models\User;
use App\Models\Team;
use App\Models\User;
use Exception;
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;

class LoginController extends Controller
{
Expand All @@ -19,6 +19,7 @@ public function redirectToGoogle()
{
return Socialite::driver('google')->redirect();
}

/**
* Obtain the user information from Google.
*
Expand All @@ -35,13 +36,14 @@ public function handleGoogleCallback()

if ($existingUser) {
// If the user exists but doesn't have a Google ID, update it
if (!$existingUser->google_id) {
if (! $existingUser->google_id) {
$existingUser->google_id = $user->id;
$existingUser->save();
}

// Log the existing user in
Auth::login($existingUser);

return redirect('/');
} else {
// If no user is found, create a new one
Expand All @@ -55,7 +57,7 @@ public function handleGoogleCallback()
// Create a personal team for the user (required by Jetstream)
$newTeam = Team::forceCreate([
'user_id' => $newUser->id,
'name' => explode(' ', $user->name, 2)[0] . "'s Team",
'name' => explode(' ', $user->name, 2)[0]."'s Team",
'personal_team' => true,
]);

Expand All @@ -66,6 +68,7 @@ public function handleGoogleCallback()

// Log the new user in
Auth::login($newUser);

return redirect('/');
}
} catch (Exception $e) {
Expand Down Expand Up @@ -99,13 +102,14 @@ public function handleAzureCallback()

if ($existingUser) {
// If the user exists but doesn't have an Azure ID, update it
if (!$existingUser->azure_id) {
if (! $existingUser->azure_id) {
$existingUser->azure_id = $user->id;
$existingUser->save();
}

// Log the existing user in
Auth::login($existingUser);

return redirect('/');
} else {
// If no user is found, create a new one
Expand All @@ -119,7 +123,7 @@ public function handleAzureCallback()
// Create a personal team for the user (required by Jetstream)
$newTeam = Team::forceCreate([
'user_id' => $newUser->id,
'name' => explode(' ', $user->name, 2)[0] . "'s Team",
'name' => explode(' ', $user->name, 2)[0]."'s Team",
'personal_team' => true,
]);

Expand All @@ -130,6 +134,7 @@ public function handleAzureCallback()

// Log the new user in
Auth::login($newUser);

return redirect('/');
}
} catch (Exception $e) {
Expand Down
5 changes: 1 addition & 4 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class HandleInertiaRequests extends Middleware
* The root template that's loaded on the first page visit.
*
* @see https://inertiajs.com/server-side-setup#root-template
*
* @var string
*/
protected $rootView = 'app';
Expand All @@ -19,8 +20,6 @@ class HandleInertiaRequests extends Middleware
* Determines the current asset version.
*
* @see https://inertiajs.com/asset-versioning
* @param \Illuminate\Http\Request $request
* @return string|null
*/
public function version(Request $request): ?string
{
Expand All @@ -31,8 +30,6 @@ public function version(Request $request): ?string
* Defines the props that are shared by default.
*
* @see https://inertiajs.com/shared-data
* @param \Illuminate\Http\Request $request
* @return array
*/
public function share(Request $request): array
{
Expand Down
15 changes: 7 additions & 8 deletions app/Http/Traits/UsesApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
namespace App\Http\Traits;

use App\Models\DkApiToken;
use Illuminate\Support\Facades\Auth as Auth;
use Illuminate\Support\Facades\Http;

trait UsesApi
{
protected function authenticateDkApi(string $token_id = null)
protected function authenticateDkApi(?string $token_id = null)
{
$response = Http::withHeaders([
'Cache-Control' => 'no-cache',
'subscription-key' => env('DK_API_SUITE_SUBSCRIPTION_KEY'),
])->get(env('DK_API_SUITE_URL') . 'authenticate/get_jwt?api=' . env('DK_API_SUITE_PRODUCT'));
])->get(env('DK_API_SUITE_URL').'authenticate/get_jwt?api='.env('DK_API_SUITE_PRODUCT'));

$body = json_decode($response->body());
$token = !empty($token_id) ? DkApiToken::where('id', $token_id)->first() : new DkApiToken();
$token = ! empty($token_id) ? DkApiToken::where('id', $token_id)->first() : new DkApiToken;
$token->access = $body->access_token;
$token->type = 'access';
$token->save();
Expand All @@ -27,9 +26,9 @@ protected function authenticateDkApi(string $token_id = null)
protected function makesDkApiRequest(string $token, string $endpoint, string $type = 'get')
{
if ($type == 'post') {
$response = Http::withToken($token)->post(env('DK_API_SUITE_URL') . '/' . env('DK_API_SUITE_VERSION') . $endpoint);
$response = Http::withToken($token)->post(env('DK_API_SUITE_URL').'/'.env('DK_API_SUITE_VERSION').$endpoint);
} else {
$response = Http::withToken($token)->get(env('DK_API_SUITE_URL') . '/' . env('DK_API_SUITE_VERSION') . $endpoint);
$response = Http::withToken($token)->get(env('DK_API_SUITE_URL').'/'.env('DK_API_SUITE_VERSION').$endpoint);
}

return json_decode($response->body());
Expand All @@ -41,12 +40,12 @@ public static function getInsights()
$response = Http::withHeaders([
'Cache-Control' => 'no-cache',
'subscription-key' => env('DK_API_SUITE_SUBSCRIPTION_KEY'),
])->get(env('DK_API_SUITE_URL') . 'authenticate/get_jwt?api=' . env('DK_API_SUITE_PRODUCT'));
])->get(env('DK_API_SUITE_URL').'authenticate/get_jwt?api='.env('DK_API_SUITE_PRODUCT'));

$token = json_decode($response->body());
// Fetch insights using the fresh token
$raw = Http::withToken($token->access_token)
->get(env('DK_API_SUITE_URL') . '/sst/students_insight?support_level=all&institution_id=jjc_transfer&summary_insights=false');
->get(env('DK_API_SUITE_URL').'/sst/students_insight?support_level=all&institution_id=jjc_transfer&summary_insights=false');

dd($raw);
}
Expand Down
3 changes: 1 addition & 2 deletions app/Models/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Concerns\HasUuids;
use App\Traits\Uuid;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Laravel\Jetstream\Events\TeamCreated;
use Laravel\Jetstream\Events\TeamDeleted;
use Laravel\Jetstream\Events\TeamUpdated;
use App\Traits\Uuid;
use Laravel\Jetstream\Team as JetstreamTeam;

class Team extends JetstreamTeam
Expand Down
6 changes: 2 additions & 4 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Concerns\HasUuids;
use App\Traits\Uuid;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Jetstream\HasProfilePhoto;
use Laravel\Jetstream\HasTeams;
use App\Traits\Uuid;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
Expand All @@ -18,10 +17,9 @@ class User extends Authenticatable
use HasFactory;
use HasProfilePhoto;
use HasTeams;
use Uuid;
use Notifiable;

use TwoFactorAuthenticatable;
use Uuid;

/**
* The attributes that are mass assignable.
Expand Down
1 change: 0 additions & 1 deletion app/Policies/PointIndicatorPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Models\PointIndicator;
use App\Models\User;
use Illuminate\Auth\Access\Response;

class PointIndicatorPolicy
{
Expand Down
1 change: 0 additions & 1 deletion app/Policies/PublicIndicatorPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Models\PublicIndicator;
use App\Models\User;
use Illuminate\Auth\Access\Response;

class PublicIndicatorPolicy
{
Expand Down
29 changes: 6 additions & 23 deletions app/Traits/UsesApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,22 @@
namespace App\Traits;

use App\Models\DkApiToken;
use App\Models\File;
use App\Helpers\File\FileHelper;
use App\Models\Run;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use GuzzleHttp\Psr7;
use Inertia\Inertia;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;

use Illuminate\Support\Facades\Http;

trait UsesApi
{
/**
* Authenticates application to DK API Suite
*
* @param string $token_id
* @return mixed
*/
protected function authenticateDkApi(string $token_id = null): mixed
protected function authenticateDkApi(?string $token_id = null): mixed
{
$response = Http::withHeaders([
'Cache-Control' => 'no-cache',
'subscription-key' => env('DK_API_SUITE_SUBSCRIPTION_KEY'),
])->get(env('DK_API_SUITE_URL') . 'authenticate/get_jwt?api=' . env('DK_API_SUITE_PRODUCT'));
])->get(env('DK_API_SUITE_URL').'authenticate/get_jwt?api='.env('DK_API_SUITE_PRODUCT'));
$body = json_decode($response->body());
$token = !empty($token_id) ? DkApiToken::where('id', $token_id)->first() : new DkApiToken();
$token = ! empty($token_id) ? DkApiToken::where('id', $token_id)->first() : new DkApiToken;
$token->access = $body->access_token;
$token->type = 'access';
$token->save();
Expand All @@ -39,22 +28,16 @@ protected function authenticateDkApi(string $token_id = null): mixed

/**
* Formats DK API Suite request URL string and sends Request to API and decodes JSON response
*
* @param string $token
* @param string $endpoint
* @param string $type
* @return mixed
*/
protected function makesDkApiRequest(string $token, string $endpoint, string $type = 'get'): mixed
{

if ($type == 'post') {
$response = Http::withToken($token)->post(env('DK_API_SUITE_URL') . '/' . env('DK_API_SUITE_VERSION') . $endpoint);
$response = Http::withToken($token)->post(env('DK_API_SUITE_URL').'/'.env('DK_API_SUITE_VERSION').$endpoint);
} else {
$response = Http::withToken($token)->get(env('DK_API_SUITE_URL') . '/' . env('DK_API_SUITE_VERSION') . $endpoint);
$response = Http::withToken($token)->get(env('DK_API_SUITE_URL').'/'.env('DK_API_SUITE_VERSION').$endpoint);
}

return json_decode($response->body());
}

}
2 changes: 1 addition & 1 deletion bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
/* Load settings from a mounted volume, if available. */
$settings_dir = $_ENV['APP_SETTINGS_DIR'] ?? '/config';

if (file_exists($settings_dir . '/.env')) {
if (file_exists($settings_dir.'/.env')) {
$dotenv = Dotenv\Dotenv::createImmutable($settings_dir);
$dotenv->load();
}
Expand Down
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
App\Providers\FortifyServiceProvider::class,
App\Providers\JetstreamServiceProvider::class,
Laravel\Socialite\SocialiteServiceProvider::class,
\SocialiteProviders\Manager\ServiceProvider::class,
\SocialiteProviders\Manager\ServiceProvider::class,
])->toArray(),

/*
Expand Down
12 changes: 6 additions & 6 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@
'strict' => true,
'engine' => null,
'sslmode' => 'require',
'options' => array(
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), #'/certs/ca.pem',
'options' => [
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), //'/certs/ca.pem',
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => env('MYSQL_ATTR_SSL_VERIFY_SERVER_CERT'),
PDO::MYSQL_ATTR_SSL_KEY => env('MYSQL_ATTR_SSL_KEY'), #'/certs/client-key.pem',
PDO::MYSQL_ATTR_SSL_CERT => env('MYSQL_ATTR_SSL_CERT'), #'/certs/client-cert.pem',
),
PDO::MYSQL_ATTR_SSL_KEY => env('MYSQL_ATTR_SSL_KEY'), //'/certs/client-key.pem',
PDO::MYSQL_ATTR_SSL_CERT => env('MYSQL_ATTR_SSL_CERT'), //'/certs/client-cert.pem',
],
],

'pgsql' => [
Expand Down Expand Up @@ -129,7 +129,7 @@

'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_') . '_database_'),
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
],

'default' => [
Expand Down
2 changes: 1 addition & 1 deletion config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL') . '/storage',
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => false,
],
Expand Down
1 change: 0 additions & 1 deletion database/factories/TeamFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Database\Factories;

use App\Models\Team;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

Expand Down
2 changes: 1 addition & 1 deletion database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function unverified(): static
/**
* Indicate that the user should have a personal team.
*/
public function withPersonalTeam(callable $callback = null): static
public function withPersonalTeam(?callable $callback = null): static
{
if (! Features::hasTeamFeatures()) {
return $this->state([]);
Expand Down
Loading

0 comments on commit d512810

Please sign in to comment.