Skip to content

Commit

Permalink
chore: bring codebase up to phpstan level 9
Browse files Browse the repository at this point in the history
  • Loading branch information
dshafik committed Oct 1, 2024
1 parent 8ff35aa commit f2c47e7
Show file tree
Hide file tree
Showing 98 changed files with 648 additions and 193 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ includes:
parameters:
paths:
- src/
level: 5
level: 9
treatPhpDocTypesAsCertain: false
9 changes: 9 additions & 0 deletions src/Bag/Attributes/Attribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Bag\Attributes;

interface Attribute
{
}
3 changes: 2 additions & 1 deletion src/Bag/Attributes/Bag.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
namespace Bag\Attributes;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;

#[Attribute(Attribute::TARGET_CLASS)]
class Bag
class Bag implements AttributeInterface
{
public const PUBLIC = 1;
public const PROTECTED = 2;
Expand Down
12 changes: 11 additions & 1 deletion src/Bag/Attributes/Cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
namespace Bag\Attributes;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;
use Bag\Casts\CastsPropertyGet;
use Bag\Casts\CastsPropertySet;
use Illuminate\Support\Collection;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Cast
class Cast implements AttributeInterface
{
/**
* @var array<array-key,mixed>
*/
protected array $parameters = [];

/**
Expand All @@ -22,6 +26,9 @@ public function __construct(protected string $casterClassname, mixed ...$paramet
$this->parameters = $parameters;
}

/**
* @param Collection<array-key,mixed> $properties
*/
public function cast(string $propertyType, string $propertyName, Collection $properties): mixed
{
/** @var CastsPropertySet $cast */
Expand All @@ -30,6 +37,9 @@ public function cast(string $propertyType, string $propertyName, Collection $pro
return $cast->set($propertyType, $propertyName, $properties);
}

/**
* @param Collection<array-key,mixed> $properties
*/
public function transform(string $propertyName, Collection $properties): mixed
{
/** @var CastsPropertyGet $cast */
Expand Down
9 changes: 7 additions & 2 deletions src/Bag/Attributes/CastInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
namespace Bag\Attributes;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;
use Bag\Casts\CastsPropertySet;
use Illuminate\Support\Collection;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class CastInput
class CastInput implements AttributeInterface
{
/**
* @var array<array-key,mixed>
*/
protected array $parameters = [];

public function __construct(protected string $casterClassname, mixed ...$parameters)
Expand All @@ -19,7 +23,8 @@ public function __construct(protected string $casterClassname, mixed ...$paramet
}

/**
* @param class-string<CastsPropertySet> $propertyName
* @param class-string<CastsPropertySet> $propertyName
* @param Collection<array-key,mixed> $properties
*/
public function cast(string $propertyType, string $propertyName, Collection $properties): mixed
{
Expand Down
9 changes: 8 additions & 1 deletion src/Bag/Attributes/CastOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@
namespace Bag\Attributes;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;
use Bag\Casts\CastsPropertyGet;
use Illuminate\Support\Collection;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class CastOutput
class CastOutput implements AttributeInterface
{
/**
* @var array<array-key,mixed>
*/
protected array $parameters = [];

public function __construct(protected string $casterClassname, mixed ...$parameters)
{
$this->parameters = $parameters;
}

/**
* @param Collection<array-key,mixed> $properties
*/
public function transform(string $propertyName, Collection $properties): mixed
{
/** @var CastsPropertyGet $cast */
Expand Down
5 changes: 3 additions & 2 deletions src/Bag/Attributes/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
namespace Bag\Attributes;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;

#[Attribute(Attribute::TARGET_CLASS)]
class Collection
class Collection implements AttributeInterface
{
/**
* @param class-string<\Illuminate\Support\Collection> $collectionClass
* @param class-string<\Illuminate\Support\Collection<array-key,mixed>> $collectionClass
*/
public function __construct(
public string $collectionClass
Expand Down
3 changes: 2 additions & 1 deletion src/Bag/Attributes/Computed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace Bag\Attributes;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;

#[Attribute(Attribute::TARGET_PROPERTY)]
class Computed
class Computed implements AttributeInterface
{
}
3 changes: 2 additions & 1 deletion src/Bag/Attributes/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
namespace Bag\Attributes;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;

#[Attribute(Attribute::TARGET_CLASS)]
class Factory
class Factory implements AttributeInterface
{
/**
* @param class-string<Factory> $factoryClass
Expand Down
3 changes: 2 additions & 1 deletion src/Bag/Attributes/Hidden.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace Bag\Attributes;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Hidden
class Hidden implements AttributeInterface
{
}
3 changes: 2 additions & 1 deletion src/Bag/Attributes/HiddenFromJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace Bag\Attributes;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class HiddenFromJson
class HiddenFromJson implements AttributeInterface
{
}
7 changes: 5 additions & 2 deletions src/Bag/Attributes/Laravel/FromRouteParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

namespace Bag\Attributes\Laravel;

#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_PARAMETER)]
class FromRouteParameter
use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class FromRouteParameter implements AttributeInterface
{
public function __construct(
public ?string $parameterName = null,
Expand Down
7 changes: 5 additions & 2 deletions src/Bag/Attributes/Laravel/FromRouteParameterProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

namespace Bag\Attributes\Laravel;

#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_PARAMETER)]
class FromRouteParameterProperty
use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class FromRouteParameterProperty implements AttributeInterface
{
public function __construct(
public string $parameterName,
Expand Down
3 changes: 2 additions & 1 deletion src/Bag/Attributes/MapInputName.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
namespace Bag\Attributes;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;
use Bag\Mappers\MapperInterface;

#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER | Attribute::IS_REPEATABLE)]
class MapInputName extends MapName
class MapInputName extends MapName implements AttributeInterface
{
/**
* @param class-string<MapperInterface> $mapper
Expand Down
9 changes: 6 additions & 3 deletions src/Bag/Attributes/MapName.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
namespace Bag\Attributes;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;
use Bag\Mappers\MapperInterface;

#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class MapName
class MapName implements AttributeInterface
{
/**
* @param class-string<MapperInterface>|null $input
* @param class-string<MapperInterface>|null $output
* @param class-string<MapperInterface>|null $input
* @param class-string<MapperInterface>|null $output
* @param array<array-key,mixed> $inputParams
* @param array<array-key,mixed> $outputParams
*/
public function __construct(public ?string $input = null, public ?string $output = null, public array $inputParams = [], public array $outputParams = [])
{
Expand Down
3 changes: 2 additions & 1 deletion src/Bag/Attributes/MapOutputName.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
namespace Bag\Attributes;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;
use Bag\Mappers\MapperInterface;

#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class MapOutputName extends MapName
class MapOutputName extends MapName implements AttributeInterface
{
/**
* @param class-string<MapperInterface> $mapper
Expand Down
6 changes: 5 additions & 1 deletion src/Bag/Attributes/Transforms.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
namespace Bag\Attributes;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;
use Illuminate\Support\Collection;

#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Transforms
class Transforms implements AttributeInterface
{
/**
* @var Collection<array-key, string>
*/
public Collection $types;

public function __construct(string ...$types)
Expand Down
3 changes: 2 additions & 1 deletion src/Bag/Attributes/Validation/Between.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
namespace Bag\Attributes\Validation;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Between extends Rule
class Between extends Rule implements AttributeInterface
{
public function __construct(int $min, int $max)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Bag/Attributes/Validation/Boolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
namespace Bag\Attributes\Validation;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Boolean extends Rule
class Boolean extends Rule implements AttributeInterface
{
public function __construct()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Bag/Attributes/Validation/Decimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
namespace Bag\Attributes\Validation;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Decimal extends Rule
class Decimal extends Rule implements AttributeInterface
{
public function __construct(int $minPlaces, ?int $maxPlaces = null)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Bag/Attributes/Validation/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
namespace Bag\Attributes\Validation;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Email extends Rule
class Email extends Rule implements AttributeInterface
{
public function __construct(
bool $rfc = true,
Expand Down
3 changes: 2 additions & 1 deletion src/Bag/Attributes/Validation/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

use Attribute;
use BackedEnum;
use Bag\Attributes\Attribute as AttributeInterface;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Enum extends Rule
class Enum extends Rule implements AttributeInterface
{
/**
* @type class-string<BackedEnum>
Expand Down
3 changes: 2 additions & 1 deletion src/Bag/Attributes/Validation/Exists.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
namespace Bag\Attributes\Validation;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;
use Illuminate\Database\Eloquent\Model;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Exists extends Rule
class Exists extends Rule implements AttributeInterface
{
/**
* @param string|class-string<Model> $table
Expand Down
3 changes: 2 additions & 1 deletion src/Bag/Attributes/Validation/In.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
namespace Bag\Attributes\Validation;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class In extends Rule
class In extends Rule implements AttributeInterface
{
public function __construct(mixed ... $values)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Bag/Attributes/Validation/Integer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
namespace Bag\Attributes\Validation;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Integer extends Rule
class Integer extends Rule implements AttributeInterface
{
public function __construct()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Bag/Attributes/Validation/Max.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
namespace Bag\Attributes\Validation;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Max extends Rule
class Max extends Rule implements AttributeInterface
{
public function __construct(int $maximum)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Bag/Attributes/Validation/Min.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
namespace Bag\Attributes\Validation;

use Attribute;
use Bag\Attributes\Attribute as AttributeInterface;

#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
class Min extends Rule
class Min extends Rule implements AttributeInterface
{
public function __construct(int $minimum)
{
Expand Down
Loading

0 comments on commit f2c47e7

Please sign in to comment.