diff --git a/app/Http/Controllers/CommentController.php b/app/Http/Controllers/CommentController.php index 4f934ef9..09c7763d 100755 --- a/app/Http/Controllers/CommentController.php +++ b/app/Http/Controllers/CommentController.php @@ -16,7 +16,6 @@ class CommentController extends Controller { public function addComment(Request $request) { - /** @phpstan-ignore-next-line */ if ($user = JWTAuth::parseToken()->user()) { $payload = $request->only([ 'resource-type', 'resource-id', 'comment' @@ -49,7 +48,6 @@ public function addComment(Request $request) public function destroyComment(Request $request) { - /** @phpstan-ignore-next-line */ if ($user = JWTAuth::parseToken()->user()) { $payload = $request->only(['comment-id']); $comment = Comment::findOrFail($request->only(['comment-id']))->first(); diff --git a/app/Http/Controllers/RecipeController.php b/app/Http/Controllers/RecipeController.php index f5c6af6f..b306f249 100755 --- a/app/Http/Controllers/RecipeController.php +++ b/app/Http/Controllers/RecipeController.php @@ -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.']); } diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index f35df16d..6e82317f 100755 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -80,7 +80,6 @@ public function update($username, UserUpdateRequest $request) public function followUser(Request $request) { - /** @phpstan-ignore-next-line */ if ($user = JWTAuth::parseToken()->user()) { if ($toFollow = $request->get('toFollow')) { $userToFollow = $this->service->findWhere($toFollow)->first(); @@ -146,7 +145,6 @@ private function getWhoToFollowData(User $user) public function addFeedback(Request $request) { - /** @phpstan-ignore-next-line */ if ($user = JWTAuth::parseToken()->user()) { $hasRespondedAlready = UserFeedback::where(['user_id' => $user->getKey(), 'type' => 'feedback']); @@ -172,7 +170,6 @@ public function addFeedback(Request $request) public function listVideos(HttpRequestRunner $requestRunner) { - /** @phpstan-ignore-next-line */ if ($user = JWTAuth::parseToken()->user()) { $tikTokUser = $user->getTikTokUser(); $errors = [ diff --git a/app/Http/Middleware/JWTAuthGuard.php b/app/Http/Middleware/JWTAuthGuard.php index d65b8692..f2e02b60 100755 --- a/app/Http/Middleware/JWTAuthGuard.php +++ b/app/Http/Middleware/JWTAuthGuard.php @@ -17,10 +17,8 @@ class JWTAuthGuard public function handle(Request $request, Closure $next) { try { - /** @phpstan-ignore-next-line */ if (JWTAuth::parseToken()->authenticate()) { - /** @phpstan-ignore-next-line */ $request->merge(["user_id" => JWTAuth::parseToken()->user()->getKey()]); return $next($request); diff --git a/app/Interfaces/serviceInterface.php b/app/Interfaces/serviceInterface.php index 8ccefab6..b3301658 100755 --- a/app/Interfaces/serviceInterface.php +++ b/app/Interfaces/serviceInterface.php @@ -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); } diff --git a/app/Services/CookbookService.php b/app/Services/CookbookService.php index cfd62cb8..8799258e 100755 --- a/app/Services/CookbookService.php +++ b/app/Services/CookbookService.php @@ -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); } diff --git a/app/Services/SearchService.php b/app/Services/SearchService.php index 34f01928..8b0d0549 100755 --- a/app/Services/SearchService.php +++ b/app/Services/SearchService.php @@ -66,7 +66,6 @@ public function getAllCookbooksByTag(array $tags): Collection } } - /** @phpstan-ignore-next-line */ $result->metaData = [ 'contains' => $contains, 'missing' => $missing @@ -166,7 +165,6 @@ public function getAllCookbooksByCategoryName($category_names) } } - /** @phpstan-ignore-next-line */ $result->metaData = [ 'contains' => $contains, 'missing' => $missing @@ -244,7 +242,6 @@ public function getAllRecipesByIngredientName($ingredients) */ public function getAllCookbooksByMe($cookbookName = "") { - /** @phpstan-ignore-next-line */ if ($user = JWTAuth::parseToken()->user()) { $me = $user->getKey(); @@ -269,7 +266,6 @@ public function getAllCookbooksByMe($cookbookName = "") */ public function getAllRecipesByMe($recipeName = "") { - /** @phpstan-ignore-next-line */ if ($user = JWTAuth::parseToken()->user()) { $me = $user->getKey(); @@ -285,7 +281,6 @@ public function getAllRecipesByMe($recipeName = "") public function getFollowing() { - /** @phpstan-ignore-next-line */ if ($me = JWTAuth::parseToken()->user()) { $recipes = []; $following = Following::where(['follower_id' => $me->getKey()])->pluck('following')->toArray(); diff --git a/app/Services/TikTok/AccessToken.php b/app/Services/TikTok/AccessToken.php index 7f382d71..c2bbf745 100644 --- a/app/Services/TikTok/AccessToken.php +++ b/app/Services/TikTok/AccessToken.php @@ -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' => [ @@ -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']]); diff --git a/app/Services/TikTok/HttpRequestRunner.php b/app/Services/TikTok/HttpRequestRunner.php index 15b934b6..337d8cb4 100644 --- a/app/Services/TikTok/HttpRequestRunner.php +++ b/app/Services/TikTok/HttpRequestRunner.php @@ -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 $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); @@ -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 $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.'); } } diff --git a/app/Services/TikTok/Request.php b/app/Services/TikTok/Request.php index 2ad916b7..6d9013f9 100644 --- a/app/Services/TikTok/Request.php +++ b/app/Services/TikTok/Request.php @@ -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; } diff --git a/app/Services/TikTok/UserInfo.php b/app/Services/TikTok/UserInfo.php index ca60f702..5d1125d5 100644 --- a/app/Services/TikTok/UserInfo.php +++ b/app/Services/TikTok/UserInfo.php @@ -4,6 +4,5 @@ class UserInfo extends Request { -// private $endpoint = 'user-info'; - public function handle() {} + public function handle(): void {} } diff --git a/app/Services/TikTok/Videos.php b/app/Services/TikTok/Videos.php index 82980c66..b71d6480 100644 --- a/app/Services/TikTok/Videos.php +++ b/app/Services/TikTok/Videos.php @@ -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/', @@ -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); + } } } } diff --git a/app/Services/UserContactDetailsService.php b/app/Services/UserContactDetailsService.php index c823e776..67a59db1 100755 --- a/app/Services/UserContactDetailsService.php +++ b/app/Services/UserContactDetailsService.php @@ -4,7 +4,6 @@ namespace App\Services; -use App\Models\Cookbook; use App\Models\User; use App\Models\UserContactDetail; use Illuminate\Http\Request; @@ -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', diff --git a/app/Services/UserService.php b/app/Services/UserService.php index ce332e4d..09dbf6c3 100755 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -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 @@ -24,7 +27,7 @@ public function __construct() /** * Get all users from the database */ - public function index() + public function index(): LengthAwarePaginator { return User::paginate(15); } @@ -32,7 +35,7 @@ public function index() /** * Create a new user resource */ - public function store(Request $request) + public function store(Request $request): bool { $user = new User([ 'name' => $request->name, @@ -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']); } @@ -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) diff --git a/app/Traits/EncryptsPayload.php b/app/Traits/EncryptsPayload.php index 79c598bc..3cc53a49 100755 --- a/app/Traits/EncryptsPayload.php +++ b/app/Traits/EncryptsPayload.php @@ -11,7 +11,7 @@ trait EncryptsPayload /** * Encrypts the given payload using Crypt * - * @param array $payload + * @param array $payload * @return string */ public function encryptPayload(array $payload): string diff --git a/app/Utils/UriHelper.php b/app/Utils/UriHelper.php index 3f1344b7..55b5b181 100644 --- a/app/Utils/UriHelper.php +++ b/app/Utils/UriHelper.php @@ -6,6 +6,9 @@ class UriHelper { + /** + * @param array $parameters + */ public static function buildHttpQuery(string $redirectToPage, array $parameters): string { $redirectToPage = $redirectToPage . '.beta-version-1-staging'; diff --git a/composer.json b/composer.json index 9e166848..087b10b9 100755 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/composer.lock b/composer.lock index ee6ead95..16521bfa 100755 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a4e9787c1a523737182bf491d5ae6ee1", + "content-hash": "5ed8ec07dfccb4e0f2fc72c98dc2bfed", "packages": [ { "name": "aws/aws-crt-php", @@ -10278,12 +10278,12 @@ "version": "v2.6.4", "source": { "type": "git", - "url": "https://github.com/nunomaduro/larastan.git", + "url": "https://github.com/larastan/larastan.git", "reference": "6c5e8820f3db6397546f3ce48520af9d312aed27" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nunomaduro/larastan/zipball/6c5e8820f3db6397546f3ce48520af9d312aed27", + "url": "https://api.github.com/repos/larastan/larastan/zipball/6c5e8820f3db6397546f3ce48520af9d312aed27", "reference": "6c5e8820f3db6397546f3ce48520af9d312aed27", "shasum": "" }, @@ -10346,8 +10346,8 @@ "static analysis" ], "support": { - "issues": "https://github.com/nunomaduro/larastan/issues", - "source": "https://github.com/nunomaduro/larastan/tree/v2.6.4" + "issues": "https://github.com/larastan/larastan/issues", + "source": "https://github.com/larastan/larastan/tree/v2.6.4" }, "funding": [ { @@ -10367,6 +10367,7 @@ "type": "patreon" } ], + "abandoned": "larastan/larastan", "time": "2023-07-29T12:13:13+00:00" }, { @@ -10569,16 +10570,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.35", + "version": "1.10.67", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "e730e5facb75ffe09dfb229795e8c01a459f26c3" + "reference": "16ddbe776f10da6a95ebd25de7c1dbed397dc493" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e730e5facb75ffe09dfb229795e8c01a459f26c3", - "reference": "e730e5facb75ffe09dfb229795e8c01a459f26c3", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/16ddbe776f10da6a95ebd25de7c1dbed397dc493", + "reference": "16ddbe776f10da6a95ebd25de7c1dbed397dc493", "shasum": "" }, "require": { @@ -10621,13 +10622,9 @@ { "url": "https://github.com/phpstan", "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", - "type": "tidelift" } ], - "time": "2023-09-19T15:27:56+00:00" + "time": "2024-04-16T07:22:02+00:00" }, { "name": "phpunit/php-code-coverage", @@ -12104,5 +12101,5 @@ "platform-dev": { "ext-json": "*" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/config/tiktok.php b/config/tiktok.php new file mode 100644 index 00000000..0b67a5fe --- /dev/null +++ b/config/tiktok.php @@ -0,0 +1,3 @@ +