Skip to content

Commit

Permalink
heavy chore
Browse files Browse the repository at this point in the history
  • Loading branch information
fokosun committed Jun 26, 2024
1 parent 078a193 commit 63ff1b3
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 70 deletions.
2 changes: 0 additions & 2 deletions app/Http/Controllers/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class CommentController extends Controller
{
public function addComment(Request $request)
{
/** @phpstan-ignore-next-line */
if ($user = JWTAuth::parseToken()->user()) {

Check failure on line 19 in app/Http/Controllers/CommentController.php

View workflow job for this annotation

GitHub Actions / php-cs

Call to an undefined static method Tymon\JWTAuth\Facades\JWTAuth::parseToken().
$payload = $request->only([
'resource-type', 'resource-id', 'comment'
Expand Down Expand Up @@ -49,7 +48,6 @@ public function addComment(Request $request)

public function destroyComment(Request $request)
{
/** @phpstan-ignore-next-line */
if ($user = JWTAuth::parseToken()->user()) {

Check failure on line 51 in app/Http/Controllers/CommentController.php

View workflow job for this annotation

GitHub Actions / php-cs

Call to an undefined static method Tymon\JWTAuth\Facades\JWTAuth::parseToken().
$payload = $request->only(['comment-id']);
$comment = Comment::findOrFail($request->only(['comment-id']))->first();
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/RecipeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public function addClap(Request $request): JsonResponse
);

return ($recipe = $this->service->addClap($request->get('recipe_id'))) ?
/** @phpstan-ignore-next-line */
$this->successResponse(['updated' => true, 'claps' => $recipe->claps]) :
$this->errorResponse(['error' => 'There was an error processing this request. Please try again.']);
}
Expand Down
3 changes: 0 additions & 3 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public function update($username, UserUpdateRequest $request)

public function followUser(Request $request)
{
/** @phpstan-ignore-next-line */
if ($user = JWTAuth::parseToken()->user()) {

Check failure on line 83 in app/Http/Controllers/UserController.php

View workflow job for this annotation

GitHub Actions / php-cs

Call to an undefined static method Tymon\JWTAuth\Facades\JWTAuth::parseToken().
if ($toFollow = $request->get('toFollow')) {
$userToFollow = $this->service->findWhere($toFollow)->first();
Expand Down Expand Up @@ -146,7 +145,6 @@ private function getWhoToFollowData(User $user)

public function addFeedback(Request $request)
{
/** @phpstan-ignore-next-line */
if ($user = JWTAuth::parseToken()->user()) {

Check failure on line 148 in app/Http/Controllers/UserController.php

View workflow job for this annotation

GitHub Actions / php-cs

Call to an undefined static method Tymon\JWTAuth\Facades\JWTAuth::parseToken().
$hasRespondedAlready = UserFeedback::where(['user_id' => $user->getKey(), 'type' => 'feedback']);

Expand All @@ -172,7 +170,6 @@ public function addFeedback(Request $request)

public function listVideos(HttpRequestRunner $requestRunner)
{
/** @phpstan-ignore-next-line */
if ($user = JWTAuth::parseToken()->user()) {

Check failure on line 173 in app/Http/Controllers/UserController.php

View workflow job for this annotation

GitHub Actions / php-cs

Call to an undefined static method Tymon\JWTAuth\Facades\JWTAuth::parseToken().
$tikTokUser = $user->getTikTokUser();
$errors = [
Expand Down
2 changes: 0 additions & 2 deletions app/Http/Middleware/JWTAuthGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ class JWTAuthGuard
public function handle(Request $request, Closure $next)
{
try {
/** @phpstan-ignore-next-line */
if (JWTAuth::parseToken()->authenticate()) {

Check failure on line 20 in app/Http/Middleware/JWTAuthGuard.php

View workflow job for this annotation

GitHub Actions / php-cs

Call to an undefined static method Tymon\JWTAuth\Facades\JWTAuth::parseToken().

/** @phpstan-ignore-next-line */
$request->merge(["user_id" => JWTAuth::parseToken()->user()->getKey()]);

Check failure on line 22 in app/Http/Middleware/JWTAuthGuard.php

View workflow job for this annotation

GitHub Actions / php-cs

Call to an undefined static method Tymon\JWTAuth\Facades\JWTAuth::parseToken().

return $next($request);
Expand Down
24 changes: 22 additions & 2 deletions app/Interfaces/serviceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,33 @@

interface serviceInterface
{
/**
* @return mixed
*/
public function index();

public function show($option);
/**
* @param string|int $option
* @return mixed
*/
public function show(string|int $option);

/**
* @param Request $request
* @return mixed
*/
public function store(Request $request);

/**
* @param Request $request
* @param string $option
* @return mixed
*/
public function update(Request $request, string $option);

public function findWhere($q);
/**
* @param string|int $q
* @return mixed
*/
public function findWhere(string|int $q);
}
3 changes: 0 additions & 3 deletions app/Services/CookbookService.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,12 @@ public function store(Request $request): bool
}
}

/** @phpstan-ignore-next-line */
$cookbook->slug = DbHelper::generateUniqueSlug($request->name, 'cookbooks', 'slug');

if ($cookbook->save()) {
/** @phpstan-ignore-next-line */
$cookbook->users()->attach($cookbook->user_id);

foreach ($categories as $category) {
/** @phpstan-ignore-next-line */
$cookbook->categories()->attach($category);
}

Expand Down
5 changes: 0 additions & 5 deletions app/Services/SearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public function getAllCookbooksByTag(array $tags): Collection
}
}

/** @phpstan-ignore-next-line */
$result->metaData = [
'contains' => $contains,
'missing' => $missing
Expand Down Expand Up @@ -166,7 +165,6 @@ public function getAllCookbooksByCategoryName($category_names)
}
}

/** @phpstan-ignore-next-line */
$result->metaData = [
'contains' => $contains,
'missing' => $missing
Expand Down Expand Up @@ -244,7 +242,6 @@ public function getAllRecipesByIngredientName($ingredients)
*/
public function getAllCookbooksByMe($cookbookName = "")
{
/** @phpstan-ignore-next-line */
if ($user = JWTAuth::parseToken()->user()) {

Check failure on line 245 in app/Services/SearchService.php

View workflow job for this annotation

GitHub Actions / php-cs

Call to an undefined static method Tymon\JWTAuth\Facades\JWTAuth::parseToken().
$me = $user->getKey();

Expand All @@ -269,7 +266,6 @@ public function getAllCookbooksByMe($cookbookName = "")
*/
public function getAllRecipesByMe($recipeName = "")
{
/** @phpstan-ignore-next-line */
if ($user = JWTAuth::parseToken()->user()) {

Check failure on line 269 in app/Services/SearchService.php

View workflow job for this annotation

GitHub Actions / php-cs

Call to an undefined static method Tymon\JWTAuth\Facades\JWTAuth::parseToken().
$me = $user->getKey();

Expand All @@ -285,7 +281,6 @@ public function getAllRecipesByMe($recipeName = "")

public function getFollowing()
{
/** @phpstan-ignore-next-line */
if ($me = JWTAuth::parseToken()->user()) {

Check failure on line 284 in app/Services/SearchService.php

View workflow job for this annotation

GitHub Actions / php-cs

Call to an undefined static method Tymon\JWTAuth\Facades\JWTAuth::parseToken().
$recipes = [];
$following = Following::where(['follower_id' => $me->getKey()])->pluck('following')->toArray();
Expand Down
8 changes: 4 additions & 4 deletions app/Services/TikTok/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

class AccessToken extends Request
{
// private $endpoint = 'access-token';

public function handle()
public function handle(): void
{
$firstRequest = $this->httpClient->post('https://open.tiktokapis.com/v2/oauth/token/', [
'headers' => [
Expand All @@ -27,7 +25,9 @@ public function handle()
$decoded = json_decode($firstRequest->getBody()->getContents(), true);

if ($decoded["error"]) {
throw new InvalidArgumentException(json_encode($decoded));
if ($exception = json_encode($decoded)) {
throw new InvalidArgumentException($exception);
}
}

Config::set('tiktok', ['access_token' => $decoded['access_token']]);
Expand Down
25 changes: 19 additions & 6 deletions app/Services/TikTok/HttpRequestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

namespace App\Services\TikTok;

use Exception;
use Illuminate\Support\Facades\Config;

class HttpRequestRunner
{
public function __invoke(array $config, bool $async = false, Request...$requests)
/**
* @param array<string> $config
* @param bool $async
* @param Request ...$requests
* @return $this
* @throws Exception
*/
public function __invoke(array $config, bool $async = false, Request...$requests): self
{
$this->validateConfig($config);

Expand All @@ -22,23 +30,28 @@ public function __invoke(array $config, bool $async = false, Request...$requests
}

//todo
public function handleSync() {}
public function handleSync(): void {}

public function getContents()
public function getContents(): array
{
return Config::get('tiktok');
}

private function setCode(string $code)
private function setCode(string $code): void
{
Config::set('tiktok', ['code' => $code]);
}

private function validateConfig(array $options = [])
/**
* @param array<string> $options
* @return void
* @throws Exception
*/
private function validateConfig(array $options = []): void
{
foreach ($options as $i => $j) {
if (is_numeric($i)) {
throw new \Exception('Invalid type. Must be a key/value pair.');
throw new Exception('Invalid type. Must be a key/value pair.');
}
}

Expand Down
8 changes: 4 additions & 4 deletions app/Services/TikTok/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

abstract class Request
{
protected $httpClient;
private $endpoint = '';
protected Client $httpClient;
private string $endpoint = '';

public function __construct()
{
$this->httpClient = new Client();
}

public abstract function handle();
public abstract function handle(): void;

public function getEndpoint()
public function getEndpoint(): string
{
return $this->endpoint;
}
Expand Down
3 changes: 1 addition & 2 deletions app/Services/TikTok/UserInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

class UserInfo extends Request
{
// private $endpoint = 'user-info';
public function handle() {}
public function handle(): void {}
}
8 changes: 4 additions & 4 deletions app/Services/TikTok/Videos.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

class Videos extends Request
{
// private $endpoint = 'video-links';

public function handle()
public function handle(): void
{
$nextRequest = $this->httpClient->request('POST',
'https://open.tiktokapis.com/v2/video/list/',
Expand Down Expand Up @@ -40,7 +38,9 @@ public function handle()

if ($decoded["error"]) {
$stage = '/video/list/';
throw new InvalidArgumentException(json_encode($decoded));
if ($exception = json_encode($decoded)) {
throw new InvalidArgumentException($exception);
}
}
}
}
6 changes: 2 additions & 4 deletions app/Services/UserContactDetailsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace App\Services;

use App\Models\Cookbook;
use App\Models\User;
use App\Models\UserContactDetail;
use Illuminate\Http\Request;
Expand All @@ -18,14 +17,13 @@ public function __construct()
$this->serviceModel = new UserContactDetail();
}

protected $contact_detail;

/**
* Creates new user contact detail
*
* @param Request $request
* @return void
*/
public function store(Request $request)
public function store(Request $request): void
{
$detail = new UserContactDetail($request->only([
'user_id',
Expand Down
15 changes: 9 additions & 6 deletions app/Services/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
use App\Models\User;
use App\Models\UserContactDetail;
use App\Utils\DbHelper;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Hashing\BcryptHasher;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;

/**
* Class UserService
Expand All @@ -24,15 +27,15 @@ public function __construct()
/**
* Get all users from the database
*/
public function index()
public function index(): LengthAwarePaginator
{
return User::paginate(15);
}

/**
* Create a new user resource
*/
public function store(Request $request)
public function store(Request $request): bool
{
$user = new User([
'name' => $request->name,
Expand Down Expand Up @@ -61,7 +64,7 @@ public function store(Request $request)
return false;
}

public function show($q)
public function show(string|int $q): Collection
{
return $this->findWhere($q)->get()->append(['tiktok_videos']);
}
Expand Down Expand Up @@ -103,10 +106,10 @@ public function update(Request $request, string $option)
}

/**
* @param $q
* @return \Illuminate\Database\Eloquent\Builder
* @param string|int $q
* @return Builder
*/
public function findWhere($q)
public function findWhere(string|int $q): Builder
{
return User::with(['cookbooks', 'recipes'])
->where('id', '=', $q)
Expand Down
2 changes: 1 addition & 1 deletion app/Traits/EncryptsPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trait EncryptsPayload
/**
* Encrypts the given payload using Crypt
*
* @param array $payload
* @param array<string> $payload
* @return string
*/
public function encryptPayload(array $payload): string
Expand Down
3 changes: 3 additions & 0 deletions app/Utils/UriHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

class UriHelper
{
/**
* @param array<string> $parameters
*/
public static function buildHttpQuery(string $redirectToPage, array $parameters): string
{
$redirectToPage = $redirectToPage . '.beta-version-1-staging';
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"ext-json": "*",
"fakerphp/faker": "1.19.0",
"laravel/sail": "^1.15",
"nunomaduro/larastan": "^2.0"
"nunomaduro/larastan": "^2.6",
"phpstan/phpstan": "^1.10"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 63ff1b3

Please sign in to comment.