Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type hinting #43

Merged
merged 13 commits into from
Nov 24, 2023
2 changes: 1 addition & 1 deletion lib/country_codes.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
class event_country_codes
{
public static function get()
public static function get(): array
{
return array(
"AF" => "Afghanistan",
Expand Down
6 changes: 3 additions & 3 deletions lib/cronjob_events_ics_import.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class rex_cronjob_events_ics_import extends rex_cronjob
{
public function execute()
public function execute(): void
{
$debug_dump = []; // Debug-Array, das bei enstprechender Option ausgegeben wird

Expand Down Expand Up @@ -220,12 +220,12 @@ public function execute()
}
}

public function getTypeName()
public function getTypeName(): string
{
return rex_i18n::msg('events_ics_import_cronjob_name');
}

public function getParamFields()
public function getParamFields(): array
{
// ICS-Datei als Demo vorschlagen
$default_url = 'https://www.schulferien.org/deutschland/ical/download/?lid=81&j='.date("Y").'&t=2';
Expand Down
20 changes: 10 additions & 10 deletions lib/event_category.php
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
<?php
class event_category extends \rex_yform_manager_dataset
{
public function getName() :string
public function getName(): string
{
return $this->name;
}
public function getImage() :string
public function getImage(): string
{
return $this->image;
}
public function getMedia()
public function getMedia(): rex_media
{
return rex_media::get($this->image);
}
Comment on lines -12 to 15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kannst du hier noch als Weiche einbauen - wenn media_manager_responsive installiert ist, dann rex_media_plus-Objekt zurückgeben.


public function getIcon()
public function getIcon(): string
{
return $this->getValue('icon');
}
public function getPrice()
public function getPrice(): string
{
return $this->getValue('msg_price');
}
public function getUrl()
public function getUrl(): string
{
return rex_getUrl('', '', ['event-category-id' => $this->getId()]);
}

public function getDateWhere($whereRaw = '')
public function getDateWhere($whereRaw = ''): object
{
return event_date::query()->joinRelation('event_category_id', 'c')->where('c.id', $this->getId())->whereRaw($whereRaw)->orderBy('startDate`, `startTime', 'DESC')->find();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function getDateWhere($whereRaw = ''): object
{
return event_date::query()->joinRelation('event_category_id', 'c')->where('c.id', $this->getId())->whereRaw($whereRaw)->orderBy('startDate`, `startTime', 'DESC')->find();
}
public function getDateWhere($whereRaw = ''): ?rex_yform_manager_collection
{
return event_date::query()->joinRelation('event_category_id', 'c')->where('c.id', $this->getId())->whereRaw($whereRaw)->orderBy('startDate`, `startTime', 'DESC')->find();
}


public function getRelatedDates($whereRaw = '')
public function getRelatedDates($whereRaw = ''): array
{
return $this->getDateWhere($whereRaw);
}
Comment on lines +35 to 38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function getRelatedDates($whereRaw = ''): array
{
return $this->getDateWhere($whereRaw);
}
public function getRelatedDates($whereRaw = ''): ?rex_yform_manager_collection
{
return $this->getDateWhere($whereRaw);
}


public function getAttributes()
public function getAttributes(): array
{
return explode(",", $this->getValue('msg_form_presets'));
}
public function hasAttribute($needle)
public function hasAttribute($needle): bool
{
return in_array($needle, $this->getAttributes());
}
Comment on lines +44 to 47
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function hasAttribute($needle): bool
{
return in_array($needle, $this->getAttributes());
}
public function hasAttribute($needle): bool
{
return in_array($needle, $this->getAttributes(), true);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool kommt nur raus, wenn in_array den 3. Parameter $strict = true hat

Expand Down
50 changes: 25 additions & 25 deletions lib/event_date.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ public static function generateuuid($id = null) :string
return uuid::uuid3(uuid::NAMESPACE_URL, $id);
}

public function getCategory()
public function getCategory(): object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function getCategory(): object
public function getCategory(): ?event_category

{
$this->category = event_category::get((int)$this->getValue('event_category_id'));
return $this->category;
}
public function getCategories()

public function getCategories(): array
{
$this->categories = $this->getRelatedCollection('event_category_id');
return $this->categories;
}
Comment on lines +22 to 26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function getCategories(): array
{
$this->categories = $this->getRelatedCollection('event_category_id');
return $this->categories;
}
public function getCategories(): ?rex_yform_manager_collection
{
$this->categories = $this->getRelatedCollection('event_category_id');
return $this->categories;
}


public function getIcs()
public function getIcs(): string
{
$UID = $this->getUid();

Expand Down Expand Up @@ -64,35 +65,35 @@ public function getIcs()
// exit($vEvent);
}

public function getLocation()
public function getLocation(): string
{
if ($this->location === null) {
$this->location = $this->getRelatedDataset('location');
}
return $this->location;
}
Comment on lines +68 to 74
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function getLocation(): string
{
if ($this->location === null) {
$this->location = $this->getRelatedDataset('location');
}
return $this->location;
}
public function getLocation(): ?event_location
{
if ($this->location === null) {
$this->location = $this->getRelatedDataset('location');
}
return $this->location;
}

public function getLocationId()
public function getLocationId(): int
{
return $this->getValue('location');
}

public function getTimezone($lat, $lng)
public function getTimezone(float $lat, float $lng): string
{
$event_timezone = "https://maps.googleapis.com/maps/api/timezone/json?location=" . $lat . "," . $lng . "&timestamp=" . time() . "&sensor=false";
$event_location_time_json = file_get_contents($event_timezone);
return $event_location_time_json;
}

public function getOfferAll()
public function getOfferAll(): array
{
return $this->getRelatedCollection('offer');
}

Comment on lines +87 to 91
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function getOfferAll(): array
{
return $this->getRelatedCollection('offer');
}
public function getOfferAll(): ?rex_yform_manager_collection
{
return $this->getRelatedCollection('offer');
}

public function getImage() : ?string
public function getImage(): ?string
{
return $this->image;
}
public function getMedia()
public function getMedia(): rex_media
{
return rex_media::get($this->image);
}
Comment on lines +96 to 99
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hier auch noch eine Weiche einbauen wenn media_manager_responsive installiert.

Expand All @@ -101,11 +102,11 @@ public function getDescriptionAsPlaintext() : ?string
{
return strip_tags(html_entity_decode($this->description));
}
public function getIcsStatus()
public function getIcsStatus(): int
{
return strip_tags($this->eventStatus);
}
Comment on lines +105 to 108
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function getIcsStatus(): int
{
return strip_tags($this->eventStatus);
}
public function getIcsStatus(): string
{
return strip_tags($this->eventStatus);
}

Da weiß ich, dass ein String rauskommt, weil ICS / Structured Data einen Text-Status haben

public function getUid()
public function getUid(): string
{
if ($this->uid === "" && $this->getValue("uid") === "") {
$this->uid = self::generateUuid($this->id);
Expand All @@ -115,19 +116,19 @@ public function getUid()
return $this->uid;
}

public function getJsonLd()
public function getJsonLd(): string
{
$fragment = new rex_fragment();
$fragment->setVar("event_date", $this);
return $fragment->parse('event-date-single.json-ld.php');
}

public static function formatDate($format_date = IntlDateFormatter::FULL, $format_time = IntlDateFormatter::SHORT, $lang = "de")
public static function formatDate(int $format_date = IntlDateFormatter::FULL, int $format_time = IntlDateFormatter::SHORT, string $lang = "de"): IntlDateFormatter
{
return datefmt_create($lang, $format_date, $format_time, null, IntlDateFormatter::GREGORIAN);
}

private function getDateTime($date, $time = "00:00")
private function getDateTime(string $date, string $time = "00:00"): DateTime
{
$time = explode(":", $time);
$dateTime = new DateTime($date);
Expand All @@ -136,22 +137,21 @@ private function getDateTime($date, $time = "00:00")
return $dateTime;
}

public function getFormattedStartDate($format_date = IntlDateFormatter::FULL, $format_time = IntlDateFormatter::NONE)
public function getFormattedStartDate(int $format_date = IntlDateFormatter::FULL, int $format_time = IntlDateFormatter::NONE): string
{
return self::formatDate($format_date, $format_time)->format($this->getDateTime($this->getValue("startDate"), $this->getStartTime()));
}


public function getFormattedEndDate($format_date = IntlDateFormatter::FULL, $format_time = IntlDateFormatter::SHORT)
public function getFormattedEndDate(int $format_date = IntlDateFormatter::FULL, int $format_time = IntlDateFormatter::SHORT): string
{
return self::formatDate($format_date, $format_time)->format($this->getDateTime($this->getValue("endDate"), $this->getEndTime()));
}

public function getFormattedStartTime()
public function getFormattedStartTime(): string
{
return $this->getStartTime();
}
public function getFormattedEndTime()
public function getFormattedEndTime(): string
{
return $this->getEndTime();
}
Expand Down Expand Up @@ -179,7 +179,7 @@ public function geTeaser() : ?string
return $this->getValue("teaser");
}

public function getPrice()
public function getPrice(): string
{
$offer = rex_yform_manager_table::get('rex_event_date_offer')->query()->where("date_id", $this->getValue('id'))->find();

Comment on lines +182 to 185
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function getPrice(): string
{
$offer = rex_yform_manager_table::get('rex_event_date_offer')->query()->where("date_id", $this->getValue('id'))->find();
public function getPrice(): ?event_offer
{
$offer = rex_yform_manager_table::get('rex_event_date_offer')->query()->where("date_id", $this->getValue('id'))->find();

Bin mir hier nicht sicher, am besten nochmal nachsehen. Es kommt ja ein Dataset zurück, aber von welcher Klasse?

Expand All @@ -188,7 +188,7 @@ public function getPrice()
}
return $this->getCategories()[0]->getPrice();
}
public function getPriceFormatted()
public function getPriceFormatted(): string
{
return $this->getPrice() . " " . rex_config::get('events', 'currency');
}
Expand Down Expand Up @@ -229,7 +229,7 @@ public function isFull() :bool
}
/* Register-URL-Addon */

public static function combineCidDid($cid, $did)
public static function combineCidDid($cid, $did): string
{
return $cid . str_pad($did, 3, '0', STR_PAD_LEFT);
}
Comment on lines +232 to 235
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static function combineCidDid($cid, $did): string
{
return $cid . str_pad($did, 3, '0', STR_PAD_LEFT);
}
public static function combineCidDid(int $cid, int $did): string
{
return $cid . str_pad($did, 3, '0', STR_PAD_LEFT);
}

Expand Down Expand Up @@ -272,18 +272,18 @@ public function getRegisterBar() :string
'.$this->countRegistrationPerson()."/".$this->getTotalCount().'
</div>';
}
public function getIcon()
public function getIcon(): string
{
if ($category = $this->getCategory()) {
return $category->getIcon();
}
}

public function getRegistrationPerson($status = 0, $operator = ">=")
public function getRegistrationPerson($status = 0, $operator = ">="): object
{
return event_registration_person::query()->where('status', $status, $operator)->where('event_date_id', self::getId())->find();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function getRegistrationPerson($status = 0, $operator = ">="): object
{
return event_registration_person::query()->where('status', $status, $operator)->where('event_date_id', self::getId())->find();
}
public function getRegistrationPerson($status = 0, $operator = ">="): ?rex_yform_manager_collection
{
return event_registration_person::query()->where('status', $status, $operator)->where('event_date_id', self::getId())->find();
}

public function countRegistrationPerson($status = 0, $operator = ">=")
public function countRegistrationPerson($status = 0, $operator = ">="): int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function countRegistrationPerson($status = 0, $operator = ">="): int
public function countRegistrationPerson(int $status = 0, string $operator = ">="): int

{
return count($this->getRegistrationPerson($status, $operator));
}
Expand Down
Loading
Loading