Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
82.14% |
23 / 28 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| DatePeriodStrategy | |
82.14% |
23 / 28 |
|
80.00% |
4 / 5 |
5.14 | |
0.00% |
0 / 1 |
| supports | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getCreationMetadata | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| getModificationMetadata | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getResultMetadata | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\Metadata\Strategy; |
| 3 | |
| 4 | use Apie\Core\Context\ApieContext; |
| 5 | use Apie\Core\Context\MetadataFieldHashmap; |
| 6 | use Apie\Core\Metadata\CompositeMetadata; |
| 7 | use Apie\Core\Metadata\Fields\DatePeriodOptions; |
| 8 | use Apie\Core\Metadata\Fields\GetterMethod; |
| 9 | use Apie\Core\Metadata\Fields\PublicProperty; |
| 10 | use Apie\Core\Metadata\MetadataInterface; |
| 11 | use Apie\Core\Metadata\StrategyInterface; |
| 12 | use DatePeriod; |
| 13 | use DateTimeInterface; |
| 14 | use ReflectionClass; |
| 15 | |
| 16 | class DatePeriodStrategy implements StrategyInterface |
| 17 | { |
| 18 | public static function supports(ReflectionClass $class): bool |
| 19 | { |
| 20 | return $class->name === DatePeriod::class; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * @param ReflectionClass<covariant DatePeriod<DateTimeInterface, DateTimeInterface|null, int|null>> $class |
| 25 | */ |
| 26 | public function __construct(private ReflectionClass $class) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | public function getCreationMetadata(ApieContext $context): MetadataInterface |
| 31 | { |
| 32 | return new CompositeMetadata( |
| 33 | new MetadataFieldHashmap([ |
| 34 | 'startDate' => new PublicProperty($this->class->getProperty('start')), |
| 35 | 'dateInterval' => new PublicProperty($this->class->getProperty('interval')), |
| 36 | 'recurrences' => new PublicProperty($this->class->getProperty('recurrences'), optional :true), |
| 37 | 'endDate' => new PublicProperty($this->class->getProperty('end'), optional :true), |
| 38 | 'options' => new DatePeriodOptions(), |
| 39 | ]), |
| 40 | $this->class |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | public function getModificationMetadata(ApieContext $context): MetadataInterface |
| 45 | { |
| 46 | return new CompositeMetadata( |
| 47 | new MetadataFieldHashmap([ |
| 48 | ]), |
| 49 | $this->class |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | public function getResultMetadata(ApieContext $context): MetadataInterface |
| 54 | { |
| 55 | return new CompositeMetadata( |
| 56 | new MetadataFieldHashmap([ |
| 57 | 'dateInterval' => new GetterMethod($this->class->getMethod('getDateInterval')), |
| 58 | 'endDate' => new GetterMethod($this->class->getMethod('getEndDate')), |
| 59 | 'recurrences' => new GetterMethod($this->class->getMethod('getRecurrences')), |
| 60 | 'startDate' => new GetterMethod($this->class->getMethod('getStartDate')), |
| 61 | 'includeStartDate' => new PublicProperty($this->class->getProperty('include_start_date')), |
| 62 | 'includeEndDate' => new PublicProperty($this->class->getProperty('include_end_date')), |
| 63 | ]), |
| 64 | $this->class |
| 65 | ); |
| 66 | } |
| 67 | } |