Skip to content

Commit

Permalink
feat: add strict types to test files, and update return types for met…
Browse files Browse the repository at this point in the history
…hods in API resources, transformers, and repositories (v4)

Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Jan 5, 2025
1 parent ac799db commit a0055ef
Show file tree
Hide file tree
Showing 122 changed files with 688 additions and 563 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
},
"require-dev": {
"laravel/pint": "^1.2",
"larastan/larastan": "^2.4.0",
"larastan/larastan": "^3.0",
"rector/rector": "^2.0",
"sampoyigi/testbench": "dev-main as 1.0",
"pestphp/pest-plugin-laravel": "^3.0"
},
Expand Down
25 changes: 0 additions & 25 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,11 @@ parameters:
count: 1
path: src/ApiResources/Transformers/ReservationTransformer.php

-
message: "#^Access to an undefined property Igniter\\\\Reservation\\\\Models\\\\Reservation\\:\\:\\$location\\.$#"
count: 1
path: src/ApiResources/Transformers/ReservationTransformer.php

-
message: "#^Access to an undefined property Igniter\\\\Reservation\\\\Models\\\\Reservation\\:\\:\\$status\\.$#"
count: 1
path: src/ApiResources/Transformers/ReservationTransformer.php

-
message: "#^Access to an undefined property Igniter\\\\Reservation\\\\Models\\\\Reservation\\:\\:\\$status_history\\.$#"
count: 1
path: src/ApiResources/Transformers/ReservationTransformer.php

-
message: "#^Access to an undefined property Igniter\\\\Reservation\\\\Models\\\\Reservation\\:\\:\\$tables\\.$#"
count: 1
path: src/ApiResources/Transformers/ReservationTransformer.php

-
message: "#^Access to an undefined property Igniter\\\\Local\\\\Models\\\\Review\\:\\:\\$customer\\.$#"
count: 1
Expand All @@ -160,16 +145,6 @@ parameters:
count: 1
path: src/ApiResources/Transformers/ReviewTransformer.php

-
message: "#^Result of method Illuminate\\\\Console\\\\Command\\:\\:error\\(\\) \\(void\\) is used\\.$#"
count: 1
path: src/Console/IssueApiToken.php

-
message: "#^Default value of the parameter \\#2 \\$errors \\(string\\) of method Igniter\\\\Api\\\\Exceptions\\\\ResourceException\\:\\:__construct\\(\\) is incompatible with type array\\|Illuminate\\\\Support\\\\MessageBag\\.$#"
count: 1
path: src/Exceptions/ResourceException.php

-
message: "#^Access to an undefined property Illuminate\\\\Support\\\\Optional\\:\\:\\$id\\.$#"
count: 1
Expand Down
5 changes: 1 addition & 4 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ includes:
- phpstan-baseline.neon

parameters:
level: 2
level: 5
paths:
- src/
- config/
- database/
- resources/
# ignoreErrors:
# - '#PHPDoc tag @var#'
# excludePaths:
# - ./*/*/FileToBeExcluded.php
# checkMissingIterableValueType: false
15 changes: 15 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNewArrayRector;

return RectorConfig::configure()
->withPaths([__DIR__.'/src', __DIR__.'/tests'])
->withSkip([
ReturnTypeFromStrictNewArrayRector::class,
])
->withTypeCoverageLevel(100)
->withDeadCodeLevel(100)
->withCodeQualityLevel(0);
2 changes: 2 additions & 0 deletions src/ApiResources/Categories.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources;

use Igniter\Api\Classes\ApiController;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Currencies.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources;

use Igniter\Api\Classes\ApiController;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Customers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources;

use Igniter\Api\Classes\ApiController;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/DiningTables.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources;

use Igniter\Api\Classes\ApiController;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Locations.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources;

use Igniter\Api\Classes\ApiController;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/MenuItemOptions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources;

use Igniter\Api\Classes\ApiController;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/MenuOptions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources;

use Igniter\Api\Classes\ApiController;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Menus.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources;

use Igniter\Api\Classes\ApiController;
Expand Down
4 changes: 3 additions & 1 deletion src/ApiResources/Orders.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources;

use Igniter\Api\Classes\ApiController;
Expand Down Expand Up @@ -28,7 +30,7 @@ class Orders extends ApiController

protected string|array $requiredAbilities = ['orders:*'];

public function restAfterSave($model)
public function restAfterSave($model): void
{
if ($orderMenus = (array)request()->input('order_menus', [])) {
$model->addOrderMenus(json_decode(json_encode($orderMenus)));
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Repositories/CategoryRepository.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Repositories;

use Igniter\Api\Classes\AbstractRepository;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Repositories/CurrencyRepository.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Repositories;

use Igniter\Api\Classes\AbstractRepository;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Repositories/CustomerRepository.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Repositories;

use Igniter\Api\Classes\AbstractRepository;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Repositories/DiningTableRepository.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Repositories;

use Igniter\Api\Classes\AbstractRepository;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Repositories/LocationRepository.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Repositories;

use Igniter\Api\Classes\AbstractRepository;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Repositories/MenuItemOptionRepository.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Repositories;

use Igniter\Api\Classes\AbstractRepository;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Repositories/MenuOptionRepository.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Repositories;

use Igniter\Api\Classes\AbstractRepository;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Repositories/MenuRepository.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Repositories;

use Igniter\Api\Classes\AbstractRepository;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Repositories/OrderRepository.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Repositories;

use Igniter\Api\Classes\AbstractRepository;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Repositories/ReservationRepository.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Repositories;

use Igniter\Api\Classes\AbstractRepository;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Repositories/ReviewRepository.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Repositories;

use Igniter\Api\Classes\AbstractRepository;
Expand Down
4 changes: 3 additions & 1 deletion src/ApiResources/Requests/MenuItemOptionRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Requests;

use Igniter\System\Classes\FormRequest;
Expand All @@ -19,7 +21,7 @@ public function attributes()
];
}

public function rules()
public function rules(): array
{
return [
'menu_id' => ['nullable', 'integer'],
Expand Down
4 changes: 3 additions & 1 deletion src/ApiResources/Requests/MenuOptionRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Requests;

use Igniter\System\Classes\FormRequest;
Expand All @@ -22,7 +24,7 @@ public function attributes()
];
}

public function rules()
public function rules(): array
{
return [
'option_name' => ['required', 'min:2', 'max:32'],
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Requests/OrderRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Requests;

use Igniter\System\Classes\FormRequest;
Expand Down
4 changes: 3 additions & 1 deletion src/ApiResources/Requests/ReservationRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Requests;

use Igniter\System\Classes\FormRequest;
Expand All @@ -22,7 +24,7 @@ public function attributes()
];
}

public function rules()
public function rules(): array
{
return [
'table_id' => ['sometimes', 'required', 'integer'],
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Reservations.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources;

use Igniter\Api\Classes\ApiController;
Expand Down
2 changes: 2 additions & 0 deletions src/ApiResources/Reviews.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources;

use Igniter\Api\Classes\ApiController;
Expand Down
4 changes: 3 additions & 1 deletion src/ApiResources/Transformers/AddressTransformer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
Expand All @@ -10,7 +12,7 @@ class AddressTransformer extends TransformerAbstract
{
use MergesIdAttribute;

public function transform(Address $address)
public function transform(Address $address): array
{
return $this->mergesIdAttribute($address);
}
Expand Down
10 changes: 6 additions & 4 deletions src/ApiResources/Transformers/CategoryTransformer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
Expand All @@ -16,22 +18,22 @@ class CategoryTransformer extends TransformerAbstract
'locations',
];

public function transform(Category $category)
public function transform(Category $category): array
{
return $this->mergesIdAttribute($category);
}

public function includeMedia(Category $category)
public function includeMedia(Category $category): ?\League\Fractal\Resource\Item
{
return ($thumb = $category->getFirstMedia()) ? $this->item($thumb, new MediaTransformer, 'media') : null;
}

public function includeMenus(Category $category)
public function includeMenus(Category $category): ?\League\Fractal\Resource\Collection
{
return $this->collection($category->menus, new MenuTransformer, 'menus');
}

public function includeLocations(Category $category)
public function includeLocations(Category $category): ?\League\Fractal\Resource\Collection
{
return $this->collection($category->locations, new LocationTransformer, 'locations');
}
Expand Down
4 changes: 3 additions & 1 deletion src/ApiResources/Transformers/CurrencyTransformer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources\Transformers;

use Igniter\Api\Traits\MergesIdAttribute;
Expand All @@ -10,7 +12,7 @@ class CurrencyTransformer extends TransformerAbstract
{
use MergesIdAttribute;

public function transform(Currency $currency)
public function transform(Currency $currency): array
{
return $this->mergesIdAttribute($currency);
}
Expand Down
Loading

0 comments on commit a0055ef

Please sign in to comment.