Skip to content

Commit

Permalink
Merge pull request #189 from spatie/privatize
Browse files Browse the repository at this point in the history
Privatize more methods and properties
  • Loading branch information
alies-dev committed Jan 28, 2024
2 parents 3edd495 + 1d7d300 commit d03792a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/Generators/BaseOutlook.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@
abstract class BaseOutlook implements Generator
{
/** @see https://www.php.net/manual/en/function.date.php */
protected string $dateFormat = 'Y-m-d';
private const DATE_FORMAT = 'Y-m-d';

/** @see https://www.php.net/manual/en/function.date.php */
protected string $dateTimeFormat = 'Y-m-d\TH:i:s\Z';
private const DATETIME_FORMAT = 'Y-m-d\TH:i:s\Z';

/**
* Get base URL for links.
* @return non-empty-string
*/
abstract public function baseUrl(): string;
abstract protected function baseUrl(): string;

/** @inheritDoc */
public function generate(Link $link): string
{
$url = $this->baseUrl();

$dateTimeFormat = $link->allDay ? $this->dateFormat : $this->dateTimeFormat;
$dateTimeFormat = $link->allDay ? self::DATE_FORMAT : self::DATETIME_FORMAT;

$utcStartDateTime = $link->from->setTimezone(new DateTimeZone('UTC'));
$utcEndDateTime = $link->to->setTimezone(new DateTimeZone('UTC'));
Expand Down
12 changes: 8 additions & 4 deletions src/Generators/Google.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@
class Google implements Generator
{
/** @see https://www.php.net/manual/en/function.date.php */
protected string $dateFormat = 'Ymd';
private const DATE_FORMAT = 'Ymd';

protected string $dateTimeFormat = 'Ymd\THis\Z';
/** @see https://www.php.net/manual/en/function.date.php */
private const DATETIME_FORMAT = 'Ymd\THis\Z';

/** @var non-empty-string */
protected const BASE_URL = 'https://calendar.google.com/calendar/render?action=TEMPLATE';

/** @inheritDoc */
public function generate(Link $link): string
{
$url = 'https://calendar.google.com/calendar/render?action=TEMPLATE';
$url = self::BASE_URL;

$utcStartDateTime = $link->from->setTimezone(new DateTimeZone('UTC'));
$utcEndDateTime = $link->to->setTimezone(new DateTimeZone('UTC'));
$dateTimeFormat = $link->allDay ? $this->dateFormat : $this->dateTimeFormat;
$dateTimeFormat = $link->allDay ? self::DATE_FORMAT : self::DATETIME_FORMAT;
$url .= '&dates='.$utcStartDateTime->format($dateTimeFormat).'/'.$utcEndDateTime->format($dateTimeFormat);

// Add timezone name if it is specified in both from and to dates and is the same for both
Expand Down
6 changes: 3 additions & 3 deletions src/Generators/WebOffice.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Spatie\CalendarLinks\Generators;

class WebOffice extends BaseOutlook
final class WebOffice extends BaseOutlook
{
/** @var non-empty-string */
protected const BASE_URL = 'https://outlook.office.com/calendar/deeplink/compose?path=/calendar/action/compose&rru=addevent';
private const BASE_URL = 'https://outlook.office.com/calendar/deeplink/compose?path=/calendar/action/compose&rru=addevent';

/** @inheritDoc */
public function baseUrl(): string
protected function baseUrl(): string
{
return static::BASE_URL;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Generators/WebOutlook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Spatie\CalendarLinks\Generators;

class WebOutlook extends BaseOutlook
final class WebOutlook extends BaseOutlook
{
/** @var non-empty-string */
protected const BASE_URL = 'https://outlook.live.com/calendar/action/compose?path=/calendar/action/compose&rru=addevent';
private const BASE_URL = 'https://outlook.live.com/calendar/action/compose?path=/calendar/action/compose&rru=addevent';

/** @inheritDoc */
public function baseUrl(): string
protected function baseUrl(): string
{
return static::BASE_URL;
}
Expand Down
12 changes: 8 additions & 4 deletions src/Generators/Yahoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@
class Yahoo implements Generator
{
/** @see https://www.php.net/manual/en/function.date.php */
protected string $dateFormat = 'Ymd';
private const DATE_FORMAT = 'Ymd';

protected string $dateTimeFormat = 'Ymd\THis\Z';
/** @see https://www.php.net/manual/en/function.date.php */
private const DATETIME_FORMAT = 'Ymd\THis\Z';

/** @var non-empty-string */
protected const BASE_URL = 'https://calendar.yahoo.com/?v=60&view=d&type=20';

/** @inheritDoc */
public function generate(Link $link): string
{
$url = 'https://calendar.yahoo.com/?v=60&view=d&type=20';
$url = self::BASE_URL;

$dateTimeFormat = $link->allDay ? $this->dateFormat : $this->dateTimeFormat;
$dateTimeFormat = $link->allDay ? self::DATE_FORMAT : self::DATETIME_FORMAT;

if ($link->allDay) {
$url .= '&ST='.$link->from->format($dateTimeFormat);
Expand Down

0 comments on commit d03792a

Please sign in to comment.