Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
StarRating
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
5 / 5
7
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
3
 createRandom
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 fromNative
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 provideSchema
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 toNative
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Apie\CommonValueObjects;
4
5use Apie\Core\Attributes\FakeMethod;
6use Apie\Core\Attributes\SchemaMethod;
7use Apie\Core\Exceptions\InvalidTypeException;
8use Apie\Core\ValueObjects\Interfaces\ValueObjectInterface;
9use Apie\Core\ValueObjects\Utils;
10use Faker\Generator;
11
12#[FakeMethod('createRandom')]
13#[SchemaMethod('provideSchema')]
14final class StarRating implements ValueObjectInterface
15{
16    public function __construct(
17        private int $input
18    ) {
19        if ($input < 0 || $input > 5) {
20            throw new InvalidTypeException($input, '0-5');
21        }
22    }
23
24    public static function createRandom(Generator $faker): self
25    {
26        return new self($faker->numberBetween(0, 5));
27    }
28    public static function fromNative(mixed $input): self
29    {
30        return new StarRating(Utils::toInt($input));
31    }
32
33    /**
34     * @return array<string, string|int>
35     */
36    public static function provideSchema(): array
37    {
38        return [
39            'type' => 'number',
40            'format' => 'integer',
41            'minimum' => 0,
42            'maximum' => 5,
43        ];
44    }
45
46    public function toNative(): int
47    {
48        return $this->input;
49    }
50}