diff --git a/src/Generators/BaseOutlook.php b/src/Generators/BaseOutlook.php index 3ac7dca..3fd19e5 100644 --- a/src/Generators/BaseOutlook.php +++ b/src/Generators/BaseOutlook.php @@ -8,7 +8,7 @@ /** * @see https://github.com/InteractionDesignFoundation/add-event-to-calendar-docs/blob/master/services/outlook-web.md - * @psalm-type OutlookOptions = array + * @psalm-type OutlookUrlParameters = array */ abstract class BaseOutlook implements Generator { @@ -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. */ @@ -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)); } diff --git a/src/Generators/Google.php b/src/Generators/Google.php index c502632..728c6f9 100644 --- a/src/Generators/Google.php +++ b/src/Generators/Google.php @@ -8,7 +8,7 @@ /** * @see https://github.com/InteractionDesignFoundation/add-event-to-calendar-docs/blob/master/services/google.md - * @psalm-type GoogleOptions = array + * @psalm-type GoogleUrlParameters = array */ class Google implements Generator { @@ -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} */ @@ -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)); } diff --git a/src/Generators/Yahoo.php b/src/Generators/Yahoo.php index 06f4953..99e9900 100644 --- a/src/Generators/Yahoo.php +++ b/src/Generators/Yahoo.php @@ -8,22 +8,23 @@ /** * @see https://github.com/InteractionDesignFoundation/add-event-to-calendar-docs/blob/master/services/yahoo.md - * @psalm-type YahooOptions = array + * @psalm-type YahooUrlParameters = array */ 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} */ @@ -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)); } diff --git a/src/Link.php b/src/Link.php index e8b4116..54c9ab3 100644 --- a/src/Link.php +++ b/src/Link.php @@ -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 { @@ -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)); } /** @@ -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) diff --git a/tests/Generators/__snapshots__/WebOfficeGeneratorTest__it_can_generate_an_url_with_custom_parameters__1.txt b/tests/Generators/__snapshots__/WebOfficeGeneratorTest__it_can_generate_an_url_with_custom_parameters__1.txt index f2ee332..099f961 100644 --- a/tests/Generators/__snapshots__/WebOfficeGeneratorTest__it_can_generate_an_url_with_custom_parameters__1.txt +++ b/tests/Generators/__snapshots__/WebOfficeGeneratorTest__it_can_generate_an_url_with_custom_parameters__1.txt @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/tests/Generators/__snapshots__/WebOutlookGeneratorTest__it_can_generate_an_url_with_custom_parameters__1.txt b/tests/Generators/__snapshots__/WebOutlookGeneratorTest__it_can_generate_an_url_with_custom_parameters__1.txt index 079416d..fd60bac 100644 --- a/tests/Generators/__snapshots__/WebOutlookGeneratorTest__it_can_generate_an_url_with_custom_parameters__1.txt +++ b/tests/Generators/__snapshots__/WebOutlookGeneratorTest__it_can_generate_an_url_with_custom_parameters__1.txt @@ -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 \ No newline at end of file +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 \ No newline at end of file