Skip to content

Commit

Permalink
Fix many problems
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor committed Oct 16, 2023
1 parent 9897377 commit 27eaa63
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 10 deletions.
10 changes: 7 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ parameters:
paths:
- src/
- config/
- database/
# TODO
# - database/
- routes/
level: 5
checkAlwaysTrueCheckTypeFunctionCall: true
Expand All @@ -23,8 +24,11 @@ parameters:
checkInternalClassCaseSensitivity: true
ignoreErrors:
- '#^Unsafe usage of new static#'
# --- TODO-s ---
# Tricky readonlys
- '#Assign it in the constructor\.$#'
- '#is assigned outside of the constructor\.$#'
# View vs. View contract
- '#render\(\) should return Illuminate\\View\\View but#'
# X vs. X contract
- '#but returns Illuminate\\Contracts\\#'
# SoftDeletes
- '#(\$forceDeleting|::withTrashed|::onlyTrashed|::trashed|::restore)#'
4 changes: 4 additions & 0 deletions src/Fields/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo as EloquentRelation;
use Illuminate\Http\Request;

/**
* @template TRelation of \Illuminate\Database\Eloquent\Relations\BelongsTo
* @extends \Cone\Root\Fields\Relation<TRelation>
*/
class BelongsTo extends Relation
{
/**
Expand Down
4 changes: 4 additions & 0 deletions src/Fields/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
use Illuminate\Http\Request;
use Illuminate\Support\Arr;

/**
* @template TRelation of \Illuminate\Database\Eloquent\Relations\BelongsToMany
* @extends \Cone\Root\Fields\Relation<TRelation>
*/
class BelongsToMany extends Relation
{
use ResolvesFields;
Expand Down
2 changes: 1 addition & 1 deletion src/Fields/Boolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(string $label, string $modelAttribute = null)
*/
public function getValueForHydrate(Request $request): mixed
{
return $request->boolean([$this->getRequestKey()]);
return $request->boolean($this->getRequestKey());
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Fields/Fieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ protected function resolveField(Request $request, Field $field): void
*/
public function persist(Request $request, Model $model, mixed $value): void
{
$this->resolveFields($request)->each(static function (Field $field) use ($request): void {
$field->persist($request, $field->getValueForHydrate($request));
$this->resolveFields($request)->each(static function (Field $field) use ($request, $model): void {
$field->persist($request, $model, $field->getValueForHydrate($request));
});
}

Expand All @@ -41,8 +41,8 @@ public function persist(Request $request, Model $model, mixed $value): void
*/
public function resolveHydrate(Request $request, Model $model, mixed $value): void
{
$this->resolveFields($request)->each(static function (Field $field) use ($request): void {
$field->resolveHydrate($request, $field->getValueForHydrate($request));
$this->resolveFields($request)->each(static function (Field $field) use ($request, $model): void {
$field->resolveHydrate($request, $model, $field->getValueForHydrate($request));
});
}

Expand Down Expand Up @@ -77,7 +77,7 @@ public function toValidate(Request $request, Model $model): array
{
return array_merge(
parent::toValidate($request, $model),
$this->resolveFields($request)->mapToValidate($request)
$this->resolveFields($request)->mapToValidate($request, $model)
);
}
}
3 changes: 3 additions & 0 deletions src/Fields/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany as EloquentRelation;

/**
* @extends \Cone\Root\Fields\HasOneOrMany<\Illuminate\Database\Eloquent\Relations\HasMany>
*/
class HasMany extends HasOneOrMany
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Fields/HasOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne as EloquentRelation;

/**
* @extends \Cone\Root\Fields\HasOneOrMany<\Illuminate\Database\Eloquent\Relations\HasOne>
*/
class HasOne extends HasOneOrMany
{
/**
Expand Down
4 changes: 4 additions & 0 deletions src/Fields/HasOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
use Illuminate\Http\Request;
use Illuminate\Support\Arr;

/**
* @template TRelation of \Illuminate\Database\Eloquent\Relations\HasOneOrMany
* @extends \Cone\Root\Fields\Relation<TRelation>
*/
abstract class HasOneOrMany extends Relation
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Fields/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Illuminate\Database\Eloquent\Relations\MorphOne as EloquentRelation;
use Illuminate\Http\Request;

/**
* @extends \Cone\Root\Fields\MorphOne<\Illuminate\Database\Eloquent\Relations\MorphOne>
*/
class Meta extends MorphOne
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Fields/MorphMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphMany as EloquentRelation;

/**
* @extends \Cone\Root\Fields\MorphOneOrMany<\Illuminate\Database\Eloquent\Relations\MorphMany>
*/
class MorphMany extends MorphOneOrMany
{
/**
Expand Down
4 changes: 4 additions & 0 deletions src/Fields/MorphOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphOne as EloquentRelation;

/**
* @template TRelation of \Illuminate\Database\Eloquent\Relations\MorphOne
* @extends \Cone\Root\Fields\MorphOneOrMany<TRelation>
*/
class MorphOne extends MorphOneOrMany
{
/**
Expand Down
4 changes: 4 additions & 0 deletions src/Fields/MorphOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphOneOrMany as EloquentRelation;

/**
* @template TRelation of \Illuminate\Database\Eloquent\Relations\MorphOneOrMany
* @extends \Cone\Root\Fields\HasOneOrMany<TRelation>
*/
abstract class MorphOneOrMany extends HasOneOrMany
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Fields/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo as EloquentRelation;

/**
* @extends \Cone\Root\Fields\BelongsTo<\Illuminate\Database\Eloquent\Relations\MorphTo>
*/
class MorphTo extends BelongsTo
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Fields/MorphToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany as EloquentRelation;

/**
* @extends \Cone\Root\Fields\BelongsToMany<\Illuminate\Database\Eloquent\Relations\MorphToMany>
*/
class MorphToMany extends BelongsToMany
{
/**
Expand Down
5 changes: 5 additions & 0 deletions src/Fields/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Str;

/**
* @template TRelation of \Illuminate\Database\Eloquent\Relations\Relation
*/
abstract class Relation extends Field
{
/**
Expand Down Expand Up @@ -72,6 +75,8 @@ public static function scopeQuery(Closure $callback): void

/**
* Get the relation instance.
*
* @phpstan-return TRelation
*/
public function getRelation(Model $model): EloquentRelation
{
Expand Down
3 changes: 3 additions & 0 deletions src/Resources/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Illuminate\Support\Traits\ForwardsCalls;
use Throwable;

/**
* @mixin \Illuminate\Support\Collection
*/
class Resources
{
use ForwardsCalls;
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static function (Builder $query): Builder {
$value = is_null($match) ? $value : preg_replace_callback(
sprintf('/%s([\d]+)?$/', preg_quote($this->separator)),
static function (array $match): string {
return str_replace($match[1], ((int) $match[1]) + 1, $match[0]);
return str_replace($match[1], (string)(((int) $match[1]) + 1), $match[0]);
},
$match
);
Expand Down

0 comments on commit 27eaa63

Please sign in to comment.