PHP code example of apie / apie-phpstan-rules

1. Go to this page and download the library: Download apie/apie-phpstan-rules library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

apie / apie-phpstan-rules example snippets



class ExampleEntity implements EntityInterface
{
    public function __construct(private readonly ExampleEntityIdentifier $id)
    {
    }

    public function getId(): IdentifierInterface
    {
        return $this->id;
    }
}


class ExampleEntity implements EntityInterface
{
    public function __construct(private readonly ExampleEntityIdentifier $id)
    {
    }

    public function getId(): ExampleEntityIdentifier
    {
        return $this->id;
    }
}


class ExampleValueObject implements ValueObjectInterface
{
    use CompositeValueObject;

    private string $property;
}


class ExampleValueObject implements ValueObjectInterface
{
    use CompositeValueObject;

    private string $property;

    private function __construct() {
    }
}


class ExampleValueObject implements ValueObjectInterface
{
    use CompositeValueObject;

    public function __construct(private string $property)
    {
    }
}


class ExampleValueObject implements ValueObjectInterface
{
    public function __construct(private string $property)
    {
    }

    public static function fromNative(mixed $input): self
    {
        $input = Utils::toArray($input);
        return new self($input['property'] ?? 'missing');
    }

    public function toNative(): array
    {
        return [
            'property' => $this->property
        ];
    }
}


#[SchemaMethod('provideSchema')]
class ExampleValueObject implements ValueObjectInterface
{
    public function __construct(private string $property)
    {
    }

    public static function fromNative(mixed $input): self
    {
        $input = Utils::toArray($input);
        return new self($input['property'] ?? 'missing');
    }

    public function toNative(): array
    {
        return [
            'property' => $this->property
        ];
    }

    public static function provideSchema(): array
    {
        return [
            'type' => 'object',
            'properties' => [
                'property' => ['type' => 'string', 'default' => 'missing']
            ],
            '