Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve PHPStan config and typehint array-ish types #6

Merged
merged 5 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,9 @@ jobs:
run: |
composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist

- name: PHP Lint
- name: Code Validation
run: |
composer run lint-php

- name: Check code style
run: |
composer run cs

- name: Check PHP compatibility
run: |
composer run cscompat8
composer run code-validate

phpunit:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ when updating laravel version:
- MethodCallingRule comes back
- HasTraits booting/initialize of traits
- getForeignKey -> getForeignKeyName for BelongsTo
- WithJson can use Resources
- WithJson can use Resources


# Laravel Support Package
Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@
},
"scripts": {
"check-all": [
"@code-validate",
"@ut"
],
"code-validate": [
"@lint",
"@cs",
"@stan",
"@ut"
"@cscompat81"
],
"cs": "vendor/bin/phpcs --standard=devops/style --report-width=80 --colors .",
"lint": "vendor/bin/parallel-lint --exclude .git --exclude vendor --colors .",
"stan": "vendor/bin/phpstan analyse --configuration=devops/phpstan.neon",
"ut": "vendor/bin/phpunit",
"cscompat81": "vendor/bin/phpcs --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --colors --runtime-set testVersion 8.1- --ignore=blade.php src tests"
"cscompat81": "vendor/bin/phpcs --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --colors --runtime-set testVersion 8.1- --ignore=tests/views/ src tests"
}
}
1 change: 1 addition & 0 deletions devops/containers/compose.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APP_SERVICE=support
17 changes: 17 additions & 0 deletions devops/containers/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3'
name: support

x-var-check:
- SUPPORT_PATH: ${SUPPORT_PATH?missing}

services:
support:
image: vpf/support-php8.2-alpine3.19
build:
context: ${SUPPORT_PATH}
dockerfile: ./devops/containers/dev/Dockerfile
volumes:
- type: bind
source: ${SUPPORT_PATH}
target: /var/www/html

19 changes: 19 additions & 0 deletions devops/containers/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM php:8.2-fpm-alpine3.19

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions \
bz2 \
calendar \
exif \
gd \
gettext \
intl \
pcntl \
pdo_mysql \
shmop \
sockets \
zip


# install composer
COPY --from=composer:2.5 /usr/bin/composer /usr/bin/composer
1 change: 0 additions & 1 deletion devops/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ parameters:
paths:
- ../src

checkGenericClassInNonGenericObjectType: false
reportUnmatchedIgnoredErrors: false

ignoreErrors:
Expand Down
14 changes: 7 additions & 7 deletions src/Blade/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function checkBox(
}

/**
* @param array<mixed>|Collection|QueryBuilder|null $collection
* @param array<mixed>|Collection<array-key, mixed>|QueryBuilder|null $collection
* @param OptionHash $options
* @param OptionHash $htmlOptions
*/
Expand All @@ -139,7 +139,7 @@ public function collectionCheckBoxes(
}

/**
* @param array<mixed>|Collection|QueryBuilder|null $collection
* @param array<mixed>|Collection<array-key, mixed>|QueryBuilder|null $collection
* @param OptionHash $options
* @param OptionHash $htmlOptions
*/
Expand All @@ -165,7 +165,7 @@ public function collectionRadioButtons(
}

/**
* @param array<mixed>|Collection|QueryBuilder|null $collection
* @param array<mixed>|Collection<array-key, mixed>|QueryBuilder|null $collection
* @param OptionHash $options
* @param OptionHash $htmlOptions
*/
Expand Down Expand Up @@ -270,7 +270,7 @@ public function fileField(string $method, array $options = []): HtmlString {
}

/**
* @param array<mixed>|Collection|QueryBuilder|null $collection
* @param array<mixed>|Collection<array-key, mixed>|QueryBuilder|null $collection
* @param OptionHash $options
* @param OptionHash $htmlOptions
*/
Expand Down Expand Up @@ -532,7 +532,7 @@ public function yieldingButton(
}

/**
* @param array<mixed>|Collection|QueryBuilder|null $collection
* @param array<mixed>|Collection<array-key, mixed>|QueryBuilder|null $collection
* @param OptionHash $options
* @param OptionHash $htmlOptions
* @return HtmlStringGenerator
Expand Down Expand Up @@ -562,7 +562,7 @@ public function yieldingCollectionCheckBoxes(
}

/**
* @param array<mixed>|Collection|QueryBuilder|null $collection
* @param array<mixed>|Collection<array-key, mixed>|QueryBuilder|null $collection
* @param OptionHash $options
* @param OptionHash $htmlOptions
* @return HtmlStringGenerator
Expand Down Expand Up @@ -710,7 +710,7 @@ protected function yieldingFieldsForNestedModel(string $name, ?object $object, a
}

/**
* @param array<mixed>|Model|Collection|null $association
* @param array<mixed>|Model|Collection<array-key, mixed>|null $association
* @param OptionHash $options
* @return HtmlStringGenerator
*/
Expand Down
26 changes: 13 additions & 13 deletions src/Blade/FormOptionsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait FormOptionsHelper {
use TagHelper;

/**
* @param array<mixed>|Collection|QueryBuilder|null $collection
* @param array<mixed>|Collection<array-key, mixed>|QueryBuilder|null $collection
* @param OptionHash $options
* @param OptionHash $htmlOptions
*/
Expand Down Expand Up @@ -58,7 +58,7 @@ public static function collectionCheckBoxes(
}

/**
* @param array<mixed>|Collection|QueryBuilder|null $collection
* @param array<mixed>|Collection<array-key, mixed>|QueryBuilder|null $collection
* @param OptionHash $options
* @param OptionHash $htmlOptions
*/
Expand Down Expand Up @@ -94,7 +94,7 @@ public static function collectionRadioButtons(
}

/**
* @param array<mixed>|Collection|QueryBuilder|null $collection
* @param array<mixed>|Collection<array-key, mixed>|QueryBuilder|null $collection
* @param OptionHash $options
* @param OptionHash $htmlOptions
*/
Expand All @@ -120,7 +120,7 @@ public static function collectionSelect(
}

/**
* @param array<mixed>|Collection|QueryBuilder|null $collection
* @param array<mixed>|Collection<array-key, mixed>|QueryBuilder|null $collection
* @param OptionHash $options
* @param OptionHash $htmlOptions
*/
Expand Down Expand Up @@ -152,7 +152,7 @@ public static function groupedCollectionSelect(
}

/**
* @param array<mixed>|Collection $groupedOptions
* @param array<mixed>|Collection<array-key, mixed> $groupedOptions
* @param OptionHash $options
*/
public static function groupedOptionsForSelect(
Expand Down Expand Up @@ -191,7 +191,7 @@ public static function groupedOptionsForSelect(
}

/**
* @param string|array<mixed>|Collection $container
* @param string|array<mixed>|Collection<array-key, mixed> $container
*/
public static function optionsForSelect(
string|array|Collection|null $container,
Expand Down Expand Up @@ -237,7 +237,7 @@ public static function optionsForSelect(
}

/**
* @param array<mixed>|Collection|QueryBuilder $collection
* @param array<mixed>|Collection<array-key, mixed>|QueryBuilder $collection
*/
public static function optionsFromCollectionForSelect(
array|Collection|QueryBuilder $collection,
Expand Down Expand Up @@ -267,7 +267,7 @@ public static function optionsFromCollectionForSelect(
}

/**
* @param array<mixed>|Collection|QueryBuilder $collection
* @param array<mixed>|Collection<array-key, mixed>|QueryBuilder $collection
*/
public static function optionGroupsFromCollectionForSelect(
array|Collection|QueryBuilder $collection,
Expand Down Expand Up @@ -307,7 +307,7 @@ public static function optionGroupsFromCollectionForSelect(
}

/**
* @param string|Stringable|array<mixed>|Collection|null $choices
* @param string|Stringable|array<mixed>|Collection<array-key, mixed>|null $choices
* @param OptionHash $options
* @param OptionHash $htmlOptions
*/
Expand Down Expand Up @@ -416,7 +416,7 @@ public static function weekdaySelect(
}

/**
* @param array<mixed>|Collection|QueryBuilder|null $collection
* @param array<mixed>|Collection<array-key, mixed>|QueryBuilder|null $collection
* @param OptionHash $options
* @param OptionHash $htmlOptions
* @return HtmlStringGenerator
Expand Down Expand Up @@ -453,7 +453,7 @@ public static function yieldingCollectionCheckBoxes(
}

/**
* @param array<mixed>|Collection|QueryBuilder|null $collection
* @param array<mixed>|Collection<array-key, mixed>|QueryBuilder|null $collection
* @param OptionHash $options
* @param OptionHash $htmlOptions
* @return HtmlStringGenerator
Expand Down Expand Up @@ -490,7 +490,7 @@ public static function yieldingCollectionRadioButtons(
}

/**
* @param string|Stringable|array<mixed>|Collection|null $choices
* @param string|Stringable|array<mixed>|Collection<array-key, mixed>|null $choices
* @param OptionHash $options
* @param OptionHash $htmlOptions
* @return HtmlStringGenerator
Expand Down Expand Up @@ -576,7 +576,7 @@ protected static function extractSelectedAndDisabled(mixed $selected): array {
}

/**
* @param array<mixed>|Collection $collection
* @param array<mixed>|Collection<array-key, mixed> $collection
*/
protected static function extractValuesFromCollection(
array|Collection $collection,
Expand Down
2 changes: 1 addition & 1 deletion src/Blade/Tags/CollectionHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
trait CollectionHelpers {

/**
* @param array<mixed>|Collection|QueryBuilder|null $collection
* @param array<mixed>|Collection<array-key, mixed>|QueryBuilder|null $collection
* @param array<string,mixed> $options
* @param array<string,mixed> $htmlOptions
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Blade/Tags/CollectionSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class CollectionSelect extends Base {

/**
* @param array<mixed>|Collection|QueryBuilder $collection
* @param array<mixed>|Collection<array-key, mixed>|QueryBuilder $collection
* @param array<string,mixed> $options
* @param array<string,mixed> $htmlOptions
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Blade/Tags/GroupedCollectionSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class GroupedCollectionSelect extends Base {

/**
* @param array<mixed>|Collection|QueryBuilder $collection
* @param array<mixed>|Collection<array-key, mixed>|QueryBuilder $collection
* @param array<string,mixed> $options
* @param array<string,mixed> $htmlOptions
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Eloquent/AutosavesRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ protected function pushAutosavedModels(?array $models, string $relationName, arr
}

/**
* @param Collection|Model|array<Model>|null $value
* @param Collection<array-key, Model>|Model|array<Model>|null $value
* @param array<string,mixed> $pushOptions
*/
protected function pushAutosavedRelation(
Expand Down
7 changes: 5 additions & 2 deletions src/Eloquent/FluentModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
use Illuminate\Support\Str;
use SilvertipSoftware\LaravelSupport\Libs\StrongParameters\Parameters;

/**
* @extends Fluent<string, mixed>
*/
class FluentModel extends Fluent implements ModelContract {
use HasEvents,
Naming,
Translation,
Validation;

/**
* @param array<string,mixed>|Arrayable $attributes
* @param array<string, mixed>|Arrayable<string, mixed> $attributes
*/
public function __construct(array|Arrayable $attributes = []) {
parent::__construct([]);
Expand All @@ -25,7 +28,7 @@ public function __construct(array|Arrayable $attributes = []) {
}

/**
* @param array<string,mixed>|Arrayable $attributes
* @param array<string, mixed>|Arrayable<string, mixed> $attributes
*/
public function fill(array|Arrayable $attributes): static {
$attributes = $attributes instanceof Arrayable
Expand Down
2 changes: 1 addition & 1 deletion src/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Model extends EloquentModel implements ModelContract {
protected $guarded = [];

/**
* @param array<string,mixed>|Arrayable $attributes
* @param array<string, mixed>|Arrayable<string, mixed> $attributes
*/
public function __construct(array|Arrayable $attributes = []) {
$attributes = $attributes instanceof Arrayable
Expand Down
3 changes: 3 additions & 0 deletions src/Eloquent/Naming/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Illuminate\Support\Fluent;
use Illuminate\Support\Str;

/**
* @extends Fluent<string, mixed>
*/
class Name extends Fluent {

public static string|Closure $rootModelNamespace = 'App\\Models';
Expand Down
6 changes: 3 additions & 3 deletions src/Eloquent/Transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
trait Transactions {

/**
* @param array<string, mixed>|Arrayable $attributes
* @param array<string, mixed>|Arrayable<string, mixed> $attributes
*/
public static function createOrFail(array|Arrayable $attributes = []): static {
$attrs = $attributes instanceof Arrayable
Expand Down Expand Up @@ -62,7 +62,7 @@ public function saveOrFail(array $options = []): bool {
}

/**
* @param array<string, mixed>|Arrayable $attributes
* @param array<string, mixed>|Arrayable<string, mixed> $attributes
* @param array<string, mixed> $options
*/
public function update(array|Arrayable $attributes = [], array $options = []) {
Expand All @@ -77,7 +77,7 @@ public function update(array|Arrayable $attributes = [], array $options = []) {
}

/**
* @param array<string, mixed>|Arrayable $attributes
* @param array<string, mixed>|Arrayable<string, mixed> $attributes
* @param array<string, mixed> $options
*/
public function updateOrFail(array|Arrayable $attributes = [], array $options = []) {
Expand Down
4 changes: 4 additions & 0 deletions src/Libs/StrongParameters/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
use RuntimeException;
use SilvertipSoftware\LaravelSupport\Libs\ArrUtils;

/**
* @implements ArrayAccess<string, mixed>
* @implements Arrayable<string, mixed>
*/
class Parameters implements Arrayable, ArrayAccess, Jsonable, JsonSerializable {

/** @var array<array<string,mixed>|Parameters> */
Expand Down
Loading
Loading