Skip to content

Commit

Permalink
Rename parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
alies-dev committed Jan 28, 2024
1 parent 99b9f28 commit e3f779b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 38 deletions.
14 changes: 7 additions & 7 deletions src/Generators/BaseOutlook.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* @see https://github.com/InteractionDesignFoundation/add-event-to-calendar-docs/blob/master/services/outlook-web.md
* @psalm-type OutlookOptions = array<string, scalar|null>
* @psalm-type OutlookUrlParameters = array<string, scalar|null>
*/
abstract class BaseOutlook implements Generator
{
Expand All @@ -18,13 +18,13 @@ abstract class BaseOutlook implements Generator
/** @var string {@see https://www.php.net/manual/en/function.date.php} */
protected $dateTimeFormat = 'Y-m-d\TH:i:s\Z';

/** @psalm-var OutlookOptions */
protected array $options = [];
/** @psalm-var OutlookUrlParameters */
protected array $urlParameters = [];

/** @psalm-param OutlookOptions $options */
public function __construct(array $options = [])
/** @psalm-param OutlookUrlParameters $urlParameters */
public function __construct(array $urlParameters = [])
{
$this->options = $options;
$this->urlParameters = $urlParameters;
}

/** Get base URL for links. */
Expand Down Expand Up @@ -57,7 +57,7 @@ public function generate(Link $link): string
$url .= '&location='.$this->sanitizeString($link->address);
}

foreach ($this->options as $key => $value) {
foreach ($this->urlParameters as $key => $value) {
$url .= '&'.urlencode($key).(in_array($value, [null, ''], true) ? '' : '='.$this->sanitizeString((string) $value));
}

Expand Down
14 changes: 7 additions & 7 deletions src/Generators/Google.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* @see https://github.com/InteractionDesignFoundation/add-event-to-calendar-docs/blob/master/services/google.md
* @psalm-type GoogleOptions = array<string, scalar|null>
* @psalm-type GoogleUrlParameters = array<string, scalar|null>
*/
class Google implements Generator
{
Expand All @@ -17,13 +17,13 @@ class Google implements Generator
/** @var string */
protected $dateTimeFormat = 'Ymd\THis\Z';

/** @psalm-var GoogleOptions */
protected array $options = [];
/** @psalm-var GoogleUrlParameters */
protected array $urlParameters = [];

/** @psalm-param GoogleOptions $options */
public function __construct(array $options = [])
/** @psalm-param GoogleUrlParameters $urlParameters */
public function __construct(array $urlParameters = [])
{
$this->options = $options;
$this->urlParameters = $urlParameters;
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -54,7 +54,7 @@ public function generate(Link $link): string
$url .= '&location='.urlencode($link->address);
}

foreach ($this->options as $key => $value) {
foreach ($this->urlParameters as $key => $value) {
$url .= '&'.urlencode($key).(in_array($value, [null, ''], true) ? '' : '='.urlencode((string) $value));
}

Expand Down
15 changes: 8 additions & 7 deletions src/Generators/Yahoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@

/**
* @see https://github.com/InteractionDesignFoundation/add-event-to-calendar-docs/blob/master/services/yahoo.md
* @psalm-type YahooOptions = array<string, scalar|null>
* @psalm-type YahooUrlParameters = array<string, scalar|null>
*/
class Yahoo implements Generator
{
/** @var string {@see https://www.php.net/manual/en/function.date.php} */
protected $dateFormat = 'Ymd';

/** @var string */
protected $dateTimeFormat = 'Ymd\THis\Z';

/** @psalm-var YahooOptions */
protected array $options = [];
/** @psalm-var YahooUrlParameters */
protected array $urlParameters = [];

/** @psalm-param YahooOptions $options */
public function __construct(array $options = [])
/** @psalm-param YahooUrlParameters $urlParameters */
public function __construct(array $urlParameters = [])
{
$this->options = $options;
$this->urlParameters = $urlParameters;
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -54,7 +55,7 @@ public function generate(Link $link): string
$url .= '&in_loc='.$this->sanitizeText($link->address);
}

foreach ($this->options as $key => $value) {
foreach ($this->urlParameters as $key => $value) {
$url .= '&'.urlencode($key).(in_array($value, [null, ''], true) ? '' : '='.$this->sanitizeText((string) $value));
}

Expand Down
30 changes: 15 additions & 15 deletions src/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* @property-read string $address
* @property-read bool $allDay
* @psalm-import-type IcsOptions from \Spatie\CalendarLinks\Generators\Ics
* @psalm-import-type GoogleOptions from \Spatie\CalendarLinks\Generators\Google
* @psalm-import-type YahooOptions from \Spatie\CalendarLinks\Generators\Yahoo
* @psalm-import-type OutlookOptions from \Spatie\CalendarLinks\Generators\BaseOutlook
* @psalm-import-type GoogleUrlParameters from \Spatie\CalendarLinks\Generators\Google
* @psalm-import-type YahooUrlParameters from \Spatie\CalendarLinks\Generators\Yahoo
* @psalm-import-type OutlookUrlParameters from \Spatie\CalendarLinks\Generators\BaseOutlook
*/
class Link
{
Expand Down Expand Up @@ -126,10 +126,10 @@ public function formatWith(Generator $generator): string
return $generator->generate($this);
}

/** @psalm-param GoogleOptions $options */
public function google(array $options = []): string
/** @psalm-param GoogleUrlParameters $urlParameters */
public function google(array $urlParameters = []): string
{
return $this->formatWith(new Google($options));
return $this->formatWith(new Google($urlParameters));
}

/**
Expand All @@ -143,22 +143,22 @@ public function ics(array $options = [], array $presentationOptions = []): strin
return $this->formatWith(new Ics($options, $presentationOptions));
}

/** @psalm-param YahooOptions $options */
public function yahoo(array $options = []): string
/** @psalm-param YahooUrlParameters $urlParameters */
public function yahoo(array $urlParameters = []): string
{
return $this->formatWith(new Yahoo($options));
return $this->formatWith(new Yahoo($urlParameters));
}

/** @psalm-param OutlookOptions $options */
public function webOutlook(array $options = []): string
/** @psalm-param OutlookUrlParameters $urlParameters */
public function webOutlook(array $urlParameters = []): string
{
return $this->formatWith(new WebOutlook($options));
return $this->formatWith(new WebOutlook($urlParameters));
}

/** @psalm-param OutlookOptions $options */
public function webOffice(array $options = []): string
/** @psalm-param OutlookUrlParameters $urlParameters */
public function webOffice(array $urlParameters = []): string
{
return $this->formatWith(new WebOffice($options));
return $this->formatWith(new WebOffice($urlParameters));
}

public function __get($property)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://outlook.office.com/calendar/deeplink/compose?path=/calendar/action/compose&rru=addevent&startdt=2018-02-01T09:00:00Z&enddt=2018-02-01T18:00:00Z&subject=Birthday&body=With%20balloons%2C%20clowns%20and%20stuff%0ABring%20a%20dog%2C%20bring%20a%20frog&location=Party%20Lane%201A%2C%201337%20Funtown
https://outlook.office.com/calendar/deeplink/compose?path=/calendar/action/compose&rru=addevent&startdt=2018-02-01T09:00:00Z&enddt=2018-02-01T18:00:00Z&subject=Birthday&body=With%20balloons%2C%20clowns%20and%20stuff%0ABring%20a%20dog%2C%20bring%20a%20frog&location=Party%20Lane%201A%2C%201337%20Funtown&online=1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://outlook.live.com/calendar/action/compose?path=/calendar/action/compose&rru=addevent&startdt=2018-02-01T09:00:00Z&enddt=2018-02-01T18:00:00Z&subject=Birthday&body=With%20balloons%2C%20clowns%20and%20stuff%0ABring%20a%20dog%2C%20bring%20a%20frog&location=Party%20Lane%201A%2C%201337%20Funtown
https://outlook.live.com/calendar/action/compose?path=/calendar/action/compose&rru=addevent&startdt=2018-02-01T09:00:00Z&enddt=2018-02-01T18:00:00Z&subject=Birthday&body=With%20balloons%2C%20clowns%20and%20stuff%0ABring%20a%20dog%2C%20bring%20a%20frog&location=Party%20Lane%201A%2C%201337%20Funtown&online=1

0 comments on commit e3f779b

Please sign in to comment.