Skip to content

Commit

Permalink
Prepare PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor committed Oct 21, 2023
1 parent 09f01c5 commit e7c2cbb
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 33 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/back-end.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,12 @@ jobs:
name: "Search for $this->$this typo 🐌"
run: |
! git grep --line-number -e '\$this\s*->\s*\$this' -- ':!:*/back-end\.yml'
-
name: "Install orchestra/testbench"
run: "composer require --dev orchestra/testbench"
-
name: "Perform static analysis"
run: "true TODO || composer exec -- phpstan analyze --level=5 src/"
run: "composer exec -- phpstan || true 'Annotate only'"

coding_standards:
name: "4️⃣ Coding Standards"
Expand Down
22 changes: 21 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,28 @@ parameters:
paths:
- src/
- config/
- database/
# TODO
# - database/
- routes/
level: 5
checkAlwaysTrueCheckTypeFunctionCall: true
checkAlwaysTrueInstanceof: true
checkAlwaysTrueStrictComparison: true
checkAlwaysTrueLooseComparison: true
checkClassCaseSensitivity: false
checkDynamicProperties: true
checkExplicitMixed: false
checkImplicitMixed: false
checkExplicitMixedMissingReturn: true
checkFunctionNameCase: true
checkInternalClassCaseSensitivity: true
ignoreErrors:
- '#^Unsafe usage of new static#'
# --- TODO-s ---
# Tricky readonlys
- '#Assign it in the constructor\.$#'
- '#is assigned outside of the constructor\.$#'
# X vs. X contract
- '#but returns Illuminate\\Contracts\\#'
# SoftDeletes
- '#(\$forceDeleting|::withTrashed|::onlyTrashed|::trashed|::restore)#'
5 changes: 5 additions & 0 deletions src/Fields/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
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
5 changes: 5 additions & 0 deletions src/Fields/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
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
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
5 changes: 5 additions & 0 deletions src/Fields/HasOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
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
5 changes: 5 additions & 0 deletions src/Fields/MorphOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
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
5 changes: 5 additions & 0 deletions src/Fields/MorphOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
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
2 changes: 2 additions & 0 deletions src/Models/Medium.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ public function user(): BelongsTo

/**
* Determine if the file is image.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute<bool, never>
*/
protected function isImage(): Attribute
{
Expand Down
6 changes: 6 additions & 0 deletions src/Navigation/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
use Cone\Root\Traits\Makeable;
use Illuminate\Support\Facades\URL;

/**
* @property string $url
* @property string $label
* @property string $icon
* @property string $group
*/
class Item
{
use HasAttributes;
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
30 changes: 0 additions & 30 deletions src/Traits/Sluggable.php

This file was deleted.

3 changes: 3 additions & 0 deletions src/Widgets/Widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Traits\ForwardsCalls;

/**
* @mixin \Illuminate\Support\Collection
*/
class Widgets
{
use ForwardsCalls;
Expand Down

0 comments on commit e7c2cbb

Please sign in to comment.