phpstan, phpcs, phpunit fixes

This commit is contained in:
Dennis Eichhorn 2023-01-27 22:12:09 +01:00
parent c493398c64
commit 8130bee71a
8 changed files with 94 additions and 187 deletions

View File

@ -55,22 +55,20 @@
"schedule_date": { "schedule_date": {
"name": "schedule_date", "name": "schedule_date",
"type": "DATETIME", "type": "DATETIME",
"null": false "null": true,
"default": null
}, },
"schedule_start": { "schedule_start": {
"name": "schedule_start", "name": "schedule_start",
"type": "DATETIME", "type": "DATETIME",
"null": false "null": true,
"default": null
}, },
"schedule_end": { "schedule_end": {
"name": "schedule_end", "name": "schedule_end",
"type": "DATETIME", "type": "DATETIME",
"null": false "null": true,
}, "default": null
"schedule_numberofoccurrences": {
"name": "schedule_numberofoccurrences",
"type": "TINYINT(1)",
"null": false
}, },
"schedule_pattern_numberofoccurrences": { "schedule_pattern_numberofoccurrences": {
"name": "schedule_pattern_numberofoccurrences", "name": "schedule_pattern_numberofoccurrences",
@ -233,6 +231,13 @@
"foreignTable": "calendar_event", "foreignTable": "calendar_event",
"foreignKey": "calendar_event_id" "foreignKey": "calendar_event_id"
}, },
"calendar_event_calendar": {
"name": "calendar_event_calendar",
"type": "INT",
"null": false,
"foreignTable": "calendar",
"foreignKey": "calendar_id"
},
"calendar_event_created_at": { "calendar_event_created_at": {
"name": "calendar_event_created_at", "name": "calendar_event_created_at",
"type": "DATETIME", "type": "DATETIME",

View File

@ -42,7 +42,7 @@ final class CalendarMapper extends DataMapperFactory
/** /**
* Has many relation. * Has many relation.
* *
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}> * @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0 * @since 1.0.0
*/ */
public const HAS_MANY = [ public const HAS_MANY = [

View File

@ -106,6 +106,25 @@ class Event
*/ */
public Location $location; public Location $location;
public \DateTime $start;
public \DateTime $end;
public int $showAs = 0;
public bool $hiddenAttendees = false;
public bool $isAllDay = true;
public bool $isCancelled = false;
public bool $isDraft = false;
public bool $isOnlineMeeting = false;
public string $webLink = '';
public string $externalId = '';
/** /**
* Calendar * Calendar
* *
@ -142,6 +161,8 @@ class Event
$this->location = new Location(); $this->location = new Location();
$this->schedule = new Schedule(); $this->schedule = new Schedule();
$this->calendar = 0; $this->calendar = 0;
$this->start = new \DateTime('now');
$this->end = new \DateTime('now');
} }
/** /**

View File

@ -41,8 +41,18 @@ final class EventMapper extends DataMapperFactory
'calendar_event_location' => ['name' => 'calendar_event_location', 'type' => 'Serializable', 'internal' => 'location'], 'calendar_event_location' => ['name' => 'calendar_event_location', 'type' => 'Serializable', 'internal' => 'location'],
'calendar_event_type' => ['name' => 'calendar_event_type', 'type' => 'int', 'internal' => 'type'], 'calendar_event_type' => ['name' => 'calendar_event_type', 'type' => 'int', 'internal' => 'type'],
'calendar_event_status' => ['name' => 'calendar_event_status', 'type' => 'int', 'internal' => 'status'], 'calendar_event_status' => ['name' => 'calendar_event_status', 'type' => 'int', 'internal' => 'status'],
'calendar_event_show_as' => ['name' => 'calendar_event_show_as', 'type' => 'int', 'internal' => 'showAs'],
'calendar_event_hidden_attendees' => ['name' => 'calendar_event_hidden_attendees', 'type' => 'bool', 'internal' => 'hiddenAttendees'],
'calendar_event_is_all_day' => ['name' => 'calendar_event_is_all_day', 'type' => 'bool', 'internal' => 'isAllDay'],
'calendar_event_is_cancelled' => ['name' => 'calendar_event_is_cancelled', 'type' => 'bool', 'internal' => 'isCancelled'],
'calendar_event_is_draft' => ['name' => 'calendar_event_is_draft', 'type' => 'bool', 'internal' => 'isDraft'],
'calendar_event_is_online_meeting' => ['name' => 'calendar_event_is_online_meeting', 'type' => 'bool', 'internal' => 'isOnlineMeeting'],
'calendar_event_web_link' => ['name' => 'calendar_event_web_link', 'type' => 'string', 'internal' => 'webLink'],
'calendar_event_external_id' => ['name' => 'calendar_event_external_id', 'type' => 'string', 'internal' => 'externalId'],
'calendar_event_schedule' => ['name' => 'calendar_event_schedule', 'type' => 'int', 'internal' => 'schedule'], 'calendar_event_schedule' => ['name' => 'calendar_event_schedule', 'type' => 'int', 'internal' => 'schedule'],
'calendar_event_calendar' => ['name' => 'calendar_event_calendar', 'type' => 'int', 'internal' => 'calendar'], 'calendar_event_calendar' => ['name' => 'calendar_event_calendar', 'type' => 'int', 'internal' => 'calendar'],
'calendar_event_start' => ['name' => 'calendar_event_start', 'type' => 'DateTime', 'internal' => 'start'],
'calendar_event_end' => ['name' => 'calendar_event_end', 'type' => 'DateTime', 'internal' => 'end'],
'calendar_event_created_by' => ['name' => 'calendar_event_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true], 'calendar_event_created_by' => ['name' => 'calendar_event_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
'calendar_event_created_at' => ['name' => 'calendar_event_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true], 'calendar_event_created_at' => ['name' => 'calendar_event_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
]; ];
@ -50,7 +60,7 @@ final class EventMapper extends DataMapperFactory
/** /**
* Has one relation. * Has one relation.
* *
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}> * @var array<string, array{mapper:class-string, external:string, by?:string, column?:string, conditional?:bool}>
* @since 1.0.0 * @since 1.0.0
*/ */
public const OWNS_ONE = [ public const OWNS_ONE = [
@ -63,7 +73,7 @@ final class EventMapper extends DataMapperFactory
/** /**
* Belongs to. * Belongs to.
* *
* @var array<string, array{mapper:string, external:string, column?:string, by?:string}> * @var array<string, array{mapper:class-string, external:string, column?:string, by?:string}>
* @since 1.0.0 * @since 1.0.0
*/ */
public const BELONGS_TO = [ public const BELONGS_TO = [
@ -76,7 +86,7 @@ final class EventMapper extends DataMapperFactory
/** /**
* Has many relation. * Has many relation.
* *
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}> * @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0 * @since 1.0.0
*/ */
public const HAS_MANY = [ public const HAS_MANY = [

View File

@ -60,21 +60,15 @@ class Schedule
*/ */
private int $freqType = FrequencyType::ONCE; private int $freqType = FrequencyType::ONCE;
/** public int $dayOfMonth = 0;
* Frequency interval.
*
* @var int
* @since 1.0.0
*/
private int $freqInterval = FrequencyInterval::DAY;
/** public int $daysOfWeek = 0;
* Frequency relative.
* public int $patternIndex = 0;
* @var int
* @since 1.0.0 public int $patternMonth = 0;
*/
private int $relativeInternal = FrequencyRelative::FIRST; public int $intervalType = 0;
/** /**
* Interval type. * Interval type.
@ -82,7 +76,7 @@ class Schedule
* @var int * @var int
* @since 1.0.0 * @since 1.0.0
*/ */
private int $intervalType = IntervalType::ABSOLUTE; private int $patternInterval = IntervalType::ABSOLUTE;
/** /**
* Recurrence factor. * Recurrence factor.
@ -90,31 +84,31 @@ class Schedule
* @var int * @var int
* @since 1.0.0 * @since 1.0.0
*/ */
public int $recurrenceFactor = 0; public int $numberOfOccurrences = 0;
/**
* Date.
*
* @var null|\DateTime
* @since 1.0.0
*/
public ?\DateTime $date = null;
/** /**
* Start. * Start.
* *
* @var \DateTime * @var null|\DateTime
* @since 1.0.0 * @since 1.0.0
*/ */
public \DateTime $start; public ?\DateTime $start = null;
/**
* Duration.
*
* @var int
* @since 1.0.0
*/
public int $duration = 3600;
/** /**
* End. * End.
* *
* @var \DateTime * @var null|\DateTime
* @since 1.0.0 * @since 1.0.0
*/ */
public \DateTime $end; public ?\DateTime $end = null;
/** /**
* Created at. * Created at.
@ -141,9 +135,6 @@ class Schedule
{ {
$this->createdBy = new NullAccount(); $this->createdBy = new NullAccount();
$this->createdAt = new \DateTimeImmutable('now'); $this->createdAt = new \DateTimeImmutable('now');
$this->start = new \DateTime('now');
$this->end = new \DateTime('now');
$this->end->setTimestamp($this->end->getTimestamp() + $this->duration);
} }
/** /**
@ -219,83 +210,27 @@ class Schedule
*/ */
public function getIntervalType() : int public function getIntervalType() : int
{ {
return $this->intervalType; return $this->patternInterval;
} }
/** /**
* @param int $intervalType Interval type * @param int $patternInterval Interval type
* *
* @return $this * @return $this
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setIntervalType(int $intervalType) : self public function setIntervalType(int $patternInterval) : self
{ {
if (!IntervalType::isValidValue($intervalType)) { if (!IntervalType::isValidValue($patternInterval)) {
throw new InvalidEnumValue($intervalType); throw new InvalidEnumValue($patternInterval);
} }
$this->intervalType = $intervalType; $this->patternInterval = $patternInterval;
return $this; return $this;
} }
/**
* @return int
*
* @since 1.0.0
*/
public function getFrequencyRelative() : int
{
return $this->relativeInternal;
}
/**
* @param int $relativeInterval Relative interval
*
* @return $this
*
* @since 1.0.0
*/
public function setFrequencyRelative(int $relativeInterval) : self
{
if (!FrequencyRelative::isValidValue($relativeInterval)) {
throw new InvalidEnumValue($relativeInterval);
}
$this->relativeInternal = $relativeInterval;
return $this;
}
/**
* @param int $freqInterval Frequency interval
*
* @return $this
*
* @since 1.0.0
*/
public function setFreqInterval(int $freqInterval) : self
{
if (!FrequencyInterval::isValidValue($freqInterval)) {
throw new InvalidEnumValue($freqInterval);
}
$this->freqInterval = $freqInterval;
return $this;
}
/**
* @return int
*
* @since 1.0.0
*/
public function getFreqInterval() : int
{
return $this->freqInterval;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -306,10 +241,7 @@ class Schedule
'uuid' => $this->uid, 'uuid' => $this->uid,
'status' => $this->status, 'status' => $this->status,
'freqType' => $this->freqType, 'freqType' => $this->freqType,
'freqInterval' => $this->freqInterval, 'patternInterval' => $this->patternInterval,
'relativeInternal' => $this->relativeInternal,
'intervalType' => $this->intervalType,
'recurrenceFactor' => $this->recurrenceFactor,
'start' => $this->start, 'start' => $this->start,
'createdAt' => $this->createdAt, 'createdAt' => $this->createdAt,
]; ];

View File

@ -34,25 +34,28 @@ final class ScheduleMapper extends DataMapperFactory
* @since 1.0.0 * @since 1.0.0
*/ */
public const COLUMNS = [ public const COLUMNS = [
'schedule_id' => ['name' => 'schedule_id', 'type' => 'int', 'internal' => 'id'], 'schedule_id' => ['name' => 'schedule_id', 'type' => 'int', 'internal' => 'id'],
'schedule_uid' => ['name' => 'schedule_uid', 'type' => 'string', 'internal' => 'uid'], 'schedule_uid' => ['name' => 'schedule_uid', 'type' => 'string', 'internal' => 'uid'],
'schedule_status' => ['name' => 'schedule_status', 'type' => 'int', 'internal' => 'status'], 'schedule_status' => ['name' => 'schedule_status', 'type' => 'int', 'internal' => 'status'],
'schedule_freq_type' => ['name' => 'schedule_freq_type', 'type' => 'int', 'internal' => 'freqType'], 'schedule_freq_type' => ['name' => 'schedule_freq_type', 'type' => 'int', 'internal' => 'freqType'],
'schedule_freq_interval' => ['name' => 'schedule_freq_interval', 'type' => 'int', 'internal' => 'freqInterval'], 'schedule_date' => ['name' => 'schedule_date', 'type' => 'DateTime', 'internal' => 'date'],
'schedule_freq_interval_type' => ['name' => 'schedule_freq_interval_type', 'type' => 'int', 'internal' => 'intervalType'], 'schedule_start' => ['name' => 'schedule_start', 'type' => 'DateTime', 'internal' => 'start'],
'schedule_freq_relative_interval' => ['name' => 'schedule_freq_relative_interval', 'type' => 'int', 'internal' => 'relativeInternal'], 'schedule_end' => ['name' => 'schedule_end', 'type' => 'DateTime', 'internal' => 'end'],
'schedule_freq_recurrence_factor' => ['name' => 'schedule_freq_recurrence_factor', 'type' => 'int', 'internal' => 'recurrenceFactor'], 'schedule_pattern_numberofoccurrences' => ['name' => 'schedule_pattern_numberofoccurrences', 'type' => 'int', 'internal' => 'numberOfOccurrences'],
'schedule_start' => ['name' => 'schedule_start', 'type' => 'DateTime', 'internal' => 'start'], 'schedule_pattern_type' => ['name' => 'schedule_pattern_type', 'type' => 'int', 'internal' => 'intervalType'],
'schedule_duration' => ['name' => 'schedule_duration', 'type' => 'int', 'internal' => 'duration'], 'schedule_pattern_pattern_interval' => ['name' => 'schedule_pattern_pattern_interval', 'type' => 'int', 'internal' => 'patternInterval'],
'schedule_end' => ['name' => 'schedule_end', 'type' => 'DateTime', 'internal' => 'end'], 'schedule_pattern_dayofmonth' => ['name' => 'schedule_pattern_dayofmonth', 'type' => 'int', 'internal' => 'dayOfMonth'],
'schedule_created_at' => ['name' => 'schedule_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true], 'schedule_pattern_daysofweek' => ['name' => 'schedule_pattern_daysofweek', 'type' => 'int', 'internal' => 'daysOfWeek'],
'schedule_created_by' => ['name' => 'schedule_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true], 'schedule_pattern_index' => ['name' => 'schedule_pattern_index', 'type' => 'int', 'internal' => 'patternIndex'],
'schedule_pattern_month' => ['name' => 'schedule_pattern_month', 'type' => 'int', 'internal' => 'patternMonth'],
'schedule_created_by' => ['name' => 'schedule_created_by', 'type' => 'int', 'internal' => 'createdBy'],
'schedule_created_at' => ['name' => 'schedule_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'],
]; ];
/** /**
* Belongs to. * Belongs to.
* *
* @var array<string, array{mapper:string, external:string, column?:string, by?:string}> * @var array<string, array{mapper:class-string, external:string, column?:string, by?:string}>
* @since 1.0.0 * @since 1.0.0
*/ */
public const BELONGS_TO = [ public const BELONGS_TO = [

View File

@ -1,16 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\Calendar
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
return ['Calendar' => [
]];

View File

@ -46,8 +46,6 @@ final class ScheduleTest extends \PHPUnit\Framework\TestCase
self::assertEquals(ScheduleStatus::ACTIVE, $this->schedule->getStatus()); self::assertEquals(ScheduleStatus::ACTIVE, $this->schedule->getStatus());
self::assertEquals(FrequencyType::ONCE, $this->schedule->getFreqType()); self::assertEquals(FrequencyType::ONCE, $this->schedule->getFreqType());
self::assertEquals(IntervalType::ABSOLUTE, $this->schedule->getIntervalType()); self::assertEquals(IntervalType::ABSOLUTE, $this->schedule->getIntervalType());
self::assertEquals(FrequencyRelative::FIRST, $this->schedule->getFrequencyRelative());
self::assertEquals(FrequencyInterval::DAY, $this->schedule->getFreqInterval());
self::assertInstanceOf('\Modules\Admin\Models\NullAccount', $this->schedule->createdBy); self::assertInstanceOf('\Modules\Admin\Models\NullAccount', $this->schedule->createdBy);
} }
@ -71,26 +69,6 @@ final class ScheduleTest extends \PHPUnit\Framework\TestCase
$this->schedule->setStatus(999); $this->schedule->setStatus(999);
} }
/**
* @covers Modules\Calendar\Models\Schedule
* @group module
*/
public function testFreqIntervalInputOutput() : void
{
$this->schedule->setFreqInterval(FrequencyInterval::DAY);
self::assertEquals(FrequencyInterval::DAY, $this->schedule->getFreqInterval());
}
/**
* @covers Modules\Calendar\Models\Schedule
* @group module
*/
public function testInvalidFreqInterval() : void
{
$this->expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class);
$this->schedule->setFreqInterval(999);
}
/** /**
* @covers Modules\Calendar\Models\Schedule * @covers Modules\Calendar\Models\Schedule
* @group module * @group module
@ -111,26 +89,6 @@ final class ScheduleTest extends \PHPUnit\Framework\TestCase
$this->schedule->setFreqType(999); $this->schedule->setFreqType(999);
} }
/**
* @covers Modules\Calendar\Models\Schedule
* @group module
*/
public function testFrequencyRelativeInputOutput() : void
{
$this->schedule->setFrequencyRelative(FrequencyRelative::LAST);
self::assertEquals(FrequencyRelative::LAST, $this->schedule->getFrequencyRelative());
}
/**
* @covers Modules\Calendar\Models\Schedule
* @group module
*/
public function testInvalidFrequencyRelative() : void
{
$this->expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class);
$this->schedule->setFrequencyRelative(999);
}
/** /**
* @covers Modules\Calendar\Models\Schedule * @covers Modules\Calendar\Models\Schedule
* @group module * @group module
@ -159,8 +117,6 @@ final class ScheduleTest extends \PHPUnit\Framework\TestCase
{ {
$this->schedule->setStatus(ScheduleStatus::INACTIVE); $this->schedule->setStatus(ScheduleStatus::INACTIVE);
$this->schedule->setFreqType(FrequencyType::YEARLY); $this->schedule->setFreqType(FrequencyType::YEARLY);
$this->schedule->setFreqInterval(FrequencyInterval::DAY);
$this->schedule->setFrequencyRelative(FrequencyRelative::LAST);
$this->schedule->setIntervalType(IntervalType::RELATIVE); $this->schedule->setIntervalType(IntervalType::RELATIVE);
$serialized = $this->schedule->jsonSerialize(); $serialized = $this->schedule->jsonSerialize();
@ -173,10 +129,6 @@ final class ScheduleTest extends \PHPUnit\Framework\TestCase
'uuid' => '', 'uuid' => '',
'status' => ScheduleStatus::INACTIVE, 'status' => ScheduleStatus::INACTIVE,
'freqType' => FrequencyType::YEARLY, 'freqType' => FrequencyType::YEARLY,
'freqInterval' => FrequencyInterval::DAY,
'relativeInternal' => FrequencyRelative::LAST,
'intervalType' => IntervalType::RELATIVE,
'recurrenceFactor' => 0,
], ],
$serialized $serialized
); );