From 97d842e8b552e9b26446c82fd9e7324ae49ba4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavs=20G=C5=ABtmanis?= Date: Sat, 21 May 2022 13:32:47 +0300 Subject: [PATCH] chore: updating code styles --- .../FeedMe/CalendarIntegration.php | 2 +- .../src/Bundles/GraphQL/GqlPermissions.php | 2 +- .../GraphQL/Interfaces/AbstractInterface.php | 4 +- .../Types/Generators/EventGenerator.php | 1 - packages/plugin/src/Calendar.php | 50 ++++---- .../src/Controllers/CalendarsController.php | 14 +-- .../src/Controllers/CodePackController.php | 2 +- .../src/Controllers/EventsApiController.php | 6 +- .../src/Controllers/EventsController.php | 8 +- .../plugin/src/Controllers/ViewController.php | 2 +- .../plugin/src/Elements/Db/EventQuery.php | 23 ++-- packages/plugin/src/Elements/Event.php | 107 +++++++++--------- .../src/FieldTypes/CalendarFieldType.php | 10 +- .../plugin/src/FieldTypes/EventFieldType.php | 9 +- .../Library/Attributes/AbstractAttributes.php | 6 +- .../plugin/src/Library/CodePack/CodePack.php | 2 +- .../Components/AssetsFileComponent.php | 2 +- .../src/Library/ColorJizz/Formats/CIELab.php | 6 +- .../Library/DataObjects/EventListOptions.php | 4 +- .../plugin/src/Library/DatabaseHelper.php | 8 +- packages/plugin/src/Library/DateHelper.php | 4 +- .../Export/ExportCalendarInterface.php | 4 +- .../Library/Export/ExportCalendarToIcs.php | 2 +- .../plugin/src/Library/RecurrenceHelper.php | 10 +- packages/plugin/src/Models/CalendarModel.php | 4 +- packages/plugin/src/Models/SettingsModel.php | 30 +++-- .../plugin/src/Records/CalendarRecord.php | 4 +- .../Records/CalendarSiteSettingsRecord.php | 2 +- .../plugin/src/Records/ExceptionRecord.php | 2 +- .../plugin/src/Records/SelectDateRecord.php | 2 +- .../plugin/src/Services/CalendarsService.php | 8 +- .../plugin/src/Services/EventsService.php | 8 +- .../plugin/src/Services/FormatsService.php | 4 +- .../RequireEventEditPermissions_Node.php | 2 +- ...equireEventEditPermissions_TokenParser.php | 2 +- .../tests/Library/DatabaseHelperTest.php | 2 +- 36 files changed, 166 insertions(+), 192 deletions(-) diff --git a/packages/plugin/src/Bundles/ExternalPluginSupport/FeedMe/CalendarIntegration.php b/packages/plugin/src/Bundles/ExternalPluginSupport/FeedMe/CalendarIntegration.php index 488bd042..e7912f70 100644 --- a/packages/plugin/src/Bundles/ExternalPluginSupport/FeedMe/CalendarIntegration.php +++ b/packages/plugin/src/Bundles/ExternalPluginSupport/FeedMe/CalendarIntegration.php @@ -21,7 +21,7 @@ if (class_exists('craft\feedme\base\Element')) { class CalendarIntegration extends Element { - const RRULE_MAP = [ + public const RRULE_MAP = [ 'BYMONTH' => 'byMonth', 'BYYEARDAY' => 'byYearDay', 'BYMONTHDAY' => 'byMonthDay', diff --git a/packages/plugin/src/Bundles/GraphQL/GqlPermissions.php b/packages/plugin/src/Bundles/GraphQL/GqlPermissions.php index 2135a904..b4ca0478 100644 --- a/packages/plugin/src/Bundles/GraphQL/GqlPermissions.php +++ b/packages/plugin/src/Bundles/GraphQL/GqlPermissions.php @@ -6,7 +6,7 @@ class GqlPermissions extends Gql { - const CATEGORY_CALENDARS = 'Calendars'; + public const CATEGORY_CALENDARS = 'Calendars'; public static function canQueryCalendars(): bool { diff --git a/packages/plugin/src/Bundles/GraphQL/Interfaces/AbstractInterface.php b/packages/plugin/src/Bundles/GraphQL/Interfaces/AbstractInterface.php index 61c900fa..5c655fc5 100644 --- a/packages/plugin/src/Bundles/GraphQL/Interfaces/AbstractInterface.php +++ b/packages/plugin/src/Bundles/GraphQL/Interfaces/AbstractInterface.php @@ -48,9 +48,7 @@ public static function getType($fields = null): Type /** * Return conditional fields for this type. - * - * @return array - */ + */ protected static function getConditionalFields(): array { return []; diff --git a/packages/plugin/src/Bundles/GraphQL/Types/Generators/EventGenerator.php b/packages/plugin/src/Bundles/GraphQL/Types/Generators/EventGenerator.php index 4dd0c003..751038dd 100644 --- a/packages/plugin/src/Bundles/GraphQL/Types/Generators/EventGenerator.php +++ b/packages/plugin/src/Bundles/GraphQL/Types/Generators/EventGenerator.php @@ -3,7 +3,6 @@ namespace Solspace\Calendar\Bundles\GraphQL\Types\Generators; use craft\gql\GqlEntityRegistry; -use craft\gql\TypeManager; use craft\helpers\Gql; use Solspace\Calendar\Bundles\GraphQL\Arguments\EventArguments; use Solspace\Calendar\Bundles\GraphQL\Interfaces\EventInterface; diff --git a/packages/plugin/src/Calendar.php b/packages/plugin/src/Calendar.php index 9682dcb9..5ba162ad 100644 --- a/packages/plugin/src/Calendar.php +++ b/packages/plugin/src/Calendar.php @@ -62,37 +62,36 @@ */ class Calendar extends Plugin { - const TRANSLATION_CATEGORY = 'calendar'; + public const TRANSLATION_CATEGORY = 'calendar'; - const FIELD_LAYOUT_TYPE = 'Calendar_Event'; + public const FIELD_LAYOUT_TYPE = 'Calendar_Event'; - const VIEW_MONTH = 'month'; - const VIEW_WEEK = 'week'; - const VIEW_DAY = 'day'; - const VIEW_EVENTS = 'events'; - const VIEW_CALENDARS = 'calendars'; - const VIEW_RESOURCES = 'resources'; + public const VIEW_MONTH = 'month'; + public const VIEW_WEEK = 'week'; + public const VIEW_DAY = 'day'; + public const VIEW_EVENTS = 'events'; + public const VIEW_CALENDARS = 'calendars'; + public const VIEW_RESOURCES = 'resources'; - const PERMISSION_CALENDARS = 'calendar-manageCalendars'; - const PERMISSION_CREATE_CALENDARS = 'calendar-createCalendars'; - const PERMISSION_EDIT_CALENDARS = 'calendar-editCalendars'; - const PERMISSION_DELETE_CALENDARS = 'calendar-deleteCalendars'; - const PERMISSION_EVENTS = 'calendar-manageEvents'; - const PERMISSION_EVENTS_FOR = 'calendar-manageEventsFor'; - const PERMISSION_EVENTS_FOR_ALL = 'calendar-manageEventsFor:all'; - const PERMISSION_SETTINGS = 'calendar-settings'; - const PERMISSION_RESOURCES = 'calendar-resources'; + public const PERMISSION_CALENDARS = 'calendar-manageCalendars'; + public const PERMISSION_CREATE_CALENDARS = 'calendar-createCalendars'; + public const PERMISSION_EDIT_CALENDARS = 'calendar-editCalendars'; + public const PERMISSION_DELETE_CALENDARS = 'calendar-deleteCalendars'; + public const PERMISSION_EVENTS = 'calendar-manageEvents'; + public const PERMISSION_EVENTS_FOR = 'calendar-manageEventsFor'; + public const PERMISSION_EVENTS_FOR_ALL = 'calendar-manageEventsFor:all'; + public const PERMISSION_SETTINGS = 'calendar-settings'; + public const PERMISSION_RESOURCES = 'calendar-resources'; - const PERMISSIONS_HELP_LINK = 'https://docs.solspace.com/craft/calendar/v2/setup/demo-templates.html'; + public const PERMISSIONS_HELP_LINK = 'https://docs.solspace.com/craft/calendar/v2/setup/demo-templates.html'; - const EDITION_LITE = 'lite'; - const EDITION_PRO = 'pro'; + public const EDITION_LITE = 'lite'; + public const EDITION_PRO = 'pro'; - const CONFIG_PATH_ROOT = 'solspace.calendar'; - const CONFIG_CALENDAR_PATH = 'solspace.calendar.calendars'; - const CONFIG_CALENDAR_SITES_PATH = 'solspace.calendar.calendar-sites'; + public const CONFIG_PATH_ROOT = 'solspace.calendar'; + public const CONFIG_CALENDAR_PATH = 'solspace.calendar.calendars'; + public const CONFIG_CALENDAR_SITES_PATH = 'solspace.calendar.calendar-sites'; - /** @var bool */ public bool $hasCpSettings = true; /** @var array */ @@ -242,9 +241,6 @@ public static function getInstance(): self return parent::getInstance(); } - /** - * @return null|array - */ public function getCpNavItem(): ?array { $navItem = parent::getCpNavItem(); diff --git a/packages/plugin/src/Controllers/CalendarsController.php b/packages/plugin/src/Controllers/CalendarsController.php index ba9682a8..397ae2c1 100644 --- a/packages/plugin/src/Controllers/CalendarsController.php +++ b/packages/plugin/src/Controllers/CalendarsController.php @@ -10,7 +10,6 @@ use craft\records\Field; use Solspace\Calendar\Calendar; use Solspace\Calendar\Elements\Event; -use Solspace\Calendar\Library\ColorHelper; use Solspace\Calendar\Library\DateHelper; use Solspace\Calendar\Models\CalendarModel; use Solspace\Calendar\Models\CalendarSiteSettingsModel; @@ -113,13 +112,13 @@ public function actionDuplicate(): Response $oldLayoutTabs = $oldLayout->getTabs(); foreach ($oldLayoutTabs as $oldLayoutTab) { - $newLayoutTab = new FieldLayoutTab(); - $newLayoutTab->name = $oldLayoutTab->name; - $newLayoutTab->sortOrder = $oldLayoutTab->sortOrder; - $newLayoutTab->setLayout($newLayout); - $newLayoutTab->setElements($oldLayoutTab->getElements()); + $newLayoutTab = new FieldLayoutTab(); + $newLayoutTab->name = $oldLayoutTab->name; + $newLayoutTab->sortOrder = $oldLayoutTab->sortOrder; + $newLayoutTab->setLayout($newLayout); + $newLayoutTab->setElements($oldLayoutTab->getElements()); - $newLayoutTabs[] = $newLayoutTab; + $newLayoutTabs[] = $newLayoutTab; } $newLayout->setTabs($newLayoutTabs); @@ -210,6 +209,7 @@ public function actionSaveCalendar(): Response if ($fieldLayout) { $fieldHandles = []; + /** @var Field $field */ foreach ($fieldLayout->getCustomFields() as $field) { $fieldHandles[] = $field->handle; diff --git a/packages/plugin/src/Controllers/CodePackController.php b/packages/plugin/src/Controllers/CodePackController.php index eff3aedd..9729b1b8 100644 --- a/packages/plugin/src/Controllers/CodePackController.php +++ b/packages/plugin/src/Controllers/CodePackController.php @@ -11,7 +11,7 @@ class CodePackController extends BaseController { - const FLASH_VAR_KEY = 'codepack_prefix'; + public const FLASH_VAR_KEY = 'codepack_prefix'; /** * @throws \yii\web\ForbiddenHttpException diff --git a/packages/plugin/src/Controllers/EventsApiController.php b/packages/plugin/src/Controllers/EventsApiController.php index 74b6dff9..a319734e 100644 --- a/packages/plugin/src/Controllers/EventsApiController.php +++ b/packages/plugin/src/Controllers/EventsApiController.php @@ -14,7 +14,7 @@ class EventsApiController extends BaseController { - const EVENT_FIELD_NAME = 'calendarEvent'; + public const EVENT_FIELD_NAME = 'calendarEvent'; public array|bool|int $allowAnonymous = true; @@ -35,7 +35,7 @@ public function actionModifyDate(): Response * @var int $deltaSeconds * @var bool $isAllDay */ - list($event, $deltaSeconds, $isAllDay) = $this->validateAndReturnModificationData(); + [$event, $deltaSeconds, $isAllDay] = $this->validateAndReturnModificationData(); $eventsService = $this->getEventsService(); @@ -146,7 +146,7 @@ public function actionModifyDuration(): Response * @var Event $event * @var \DateInterval $interval */ - list($event, $deltaSeconds) = $this->validateAndReturnModificationData(); + [$event, $deltaSeconds] = $this->validateAndReturnModificationData(); $event->getEndDate()->addSeconds($deltaSeconds); diff --git a/packages/plugin/src/Controllers/EventsController.php b/packages/plugin/src/Controllers/EventsController.php index 754483cd..8c36ac03 100644 --- a/packages/plugin/src/Controllers/EventsController.php +++ b/packages/plugin/src/Controllers/EventsController.php @@ -27,8 +27,8 @@ class EventsController extends BaseController { - const EVENT_FIELD_NAME = 'calendarEvent'; - const EVENT_PREVIEW_EVENT = 'previewEvent'; + public const EVENT_FIELD_NAME = 'calendarEvent'; + public const EVENT_PREVIEW_EVENT = 'previewEvent'; protected array|bool|int $allowAnonymous = ['save-event', 'view-shared-event']; @@ -288,7 +288,7 @@ public function actionDeleteEvent() $event = $this->getEventsService()->getEventById($eventId, null, true); - if (! $event) { + if (!$event) { return false; } @@ -428,7 +428,7 @@ private function renderEditForm(Event $event, string $title): Response // Enable Live Preview? $showPreviewButton = false; - if (!\Craft::$app->getRequest()->isMobileBrowser(true) && $this->getCalendarService()->isEventTemplateValid($calendar, $event->siteId) && ! is_null($event->id)) { + if (!\Craft::$app->getRequest()->isMobileBrowser(true) && $this->getCalendarService()->isEventTemplateValid($calendar, $event->siteId) && null !== $event->id) { $previewUrl = $event->getUrl(); $this->getView()->registerJs('Craft.LivePreview.init('.Json::encode([ 'fields' => '#title-field, #event-builder-data, #event-builder, #fields .calendar-event-wrapper > .field, #fields > .field > .field, #fields > .flex-fields > .field', diff --git a/packages/plugin/src/Controllers/ViewController.php b/packages/plugin/src/Controllers/ViewController.php index ae063ecd..9e714da6 100644 --- a/packages/plugin/src/Controllers/ViewController.php +++ b/packages/plugin/src/Controllers/ViewController.php @@ -62,7 +62,7 @@ public function actionTargetTime( $month = null, $day = null ): Response { - $view = $view ?? Calendar::VIEW_MONTH; + $view ??= Calendar::VIEW_MONTH; $calendarView = $view; if (Calendar::VIEW_WEEK === $calendarView) { diff --git a/packages/plugin/src/Elements/Db/EventQuery.php b/packages/plugin/src/Elements/Db/EventQuery.php index f76da6dc..d6a6c831 100644 --- a/packages/plugin/src/Elements/Db/EventQuery.php +++ b/packages/plugin/src/Elements/Db/EventQuery.php @@ -26,11 +26,11 @@ class EventQuery extends ElementQuery implements \Countable { - const MAX_EVENT_LENGTH_DAYS = 365; + public const MAX_EVENT_LENGTH_DAYS = 365; - const TARGET_MONTH = 'Month'; - const TARGET_WEEK = 'Week'; - const TARGET_DAY = 'Day'; + public const TARGET_MONTH = 'Month'; + public const TARGET_WEEK = 'Week'; + public const TARGET_DAY = 'Day'; /** @var int */ public $typeId; @@ -539,12 +539,7 @@ public function all($db = null): array return $this->events; } - /** - * @param int $n - * @param Connection|null $db - * @return array|\yii\base\Model|null - */ - public function nth(int $n, ?\yii\db\Connection $db = null): array|null|\yii\base\Model + public function nth(int $n, ?Connection $db = null): array|null|\yii\base\Model { $this->all($db); @@ -556,7 +551,7 @@ public function nth(int $n, ?\yii\db\Connection $db = null): array|null|\yii\bas * * @return int[] */ - public function ids(?\yii\db\Connection $db = null): array + public function ids(?Connection $db = null): array { $events = $this->all($db); @@ -1002,7 +997,7 @@ private function cacheRecurringEvents(array $foundIds) * @var Carbon $occurrenceStartDate * @var Carbon $occurrenceEndDate */ - list($occurrenceStartDate, $occurrenceEndDate) = DateHelper::getRelativeEventDates( + [$occurrenceStartDate, $occurrenceEndDate] = DateHelper::getRelativeEventDates( $startDateCarbon, $endDateCarbon, $date @@ -1057,7 +1052,7 @@ private function cacheRecurringEvents(array $foundIds) * @var Carbon $occurrenceStartDate * @var Carbon $occurrenceEndDate */ - list($occurrenceStartDate, $occurrenceEndDate) = DateHelper::getRelativeEventDates( + [$occurrenceStartDate, $occurrenceEndDate] = DateHelper::getRelativeEventDates( $startDateCarbon, $endDateCarbon, $occurrence @@ -1229,7 +1224,7 @@ function ($data) { * @var Carbon $date * @var int $eventId */ - foreach ($this->eventCache as list($date, $eventId)) { + foreach ($this->eventCache as [$date, $eventId]) { if (!isset($eventsById[$eventId])) { continue; } diff --git a/packages/plugin/src/Elements/Event.php b/packages/plugin/src/Elements/Event.php index 0c2dc4e7..b9e872c7 100644 --- a/packages/plugin/src/Elements/Event.php +++ b/packages/plugin/src/Elements/Event.php @@ -36,16 +36,16 @@ class Event extends Element implements \JsonSerializable { - const TABLE = '{{%calendar_events}}'; - const TABLE_STD = 'calendar_events'; + public const TABLE = '{{%calendar_events}}'; + public const TABLE_STD = 'calendar_events'; - const UNTIL_TYPE_FOREVER = 'forever'; - const UNTIL_TYPE_UNTIL = 'until'; - const UNTIL_TYPE_AFTER = 'after'; + public const UNTIL_TYPE_FOREVER = 'forever'; + public const UNTIL_TYPE_UNTIL = 'until'; + public const UNTIL_TYPE_AFTER = 'after'; - const SPAN_LIMIT_DAYS = 365; + public const SPAN_LIMIT_DAYS = 365; - const EVENT_TRANSFORM_JSON_VALUE = 'transform-json-value'; + public const EVENT_TRANSFORM_JSON_VALUE = 'transform-json-value'; /** @var \DateTime */ public $postDate; @@ -230,7 +230,7 @@ public static function buildQuery(array $config = null): ElementQueryInterface } $query->setOverlapThreshold(Calendar::getInstance()->settings->getOverlapThreshold()); - $query->siteId = $query->siteId ?? \Craft::$app->sites->currentSite->id; + $query->siteId ??= \Craft::$app->sites->currentSite->id; return $query; } @@ -365,10 +365,8 @@ public function getCpEditUrl(): ?string /** * Returns the field layout used by this element. - * - * @return null|FieldLayout */ - public function getFieldLayout(): ?\craft\models\FieldLayout + public function getFieldLayout(): ?FieldLayout { if ($this->calendarId) { return $this->getCalendar()->getFieldLayout(); @@ -394,9 +392,6 @@ public function getAuthor() return null; } - /** - * @return null|string - */ public function getUriFormat(): ?string { return $this->getCalendar()->getUriFormat($this->siteId); @@ -427,7 +422,7 @@ public function setExceptions(array $exceptions): self $model->eventId = $this->id; $this->exceptions[] = $model; - } elseif (is_string($date)) { + } elseif (\is_string($date)) { $model = new ExceptionModel(); $model->date = Carbon::createFromDate($date); $model->eventId = $this->id; @@ -513,7 +508,7 @@ public function setSelectDates(array $selectDates = []): self $model->eventId = $this->id; $this->selectDates[] = $model; - } elseif (is_string($date)) { + } elseif (\is_string($date)) { $model = new SelectDateModel(); $model->date = Carbon::createFromTimestampUTC(strtotime($date)); $model->eventId = $this->id; @@ -532,7 +527,7 @@ public function getSelectDatesAsDates(bool $includeOriginalEventStartDate = fals { $models = $this->getSelectDates($rangeStart, $rangeEnd); - if (! $includeOriginalEventStartDate) { + if (!$includeOriginalEventStartDate) { $this->removeOriginalEventFromSelectDates($models); } @@ -1355,6 +1350,45 @@ public function metaFieldsHtml(bool $static): string ]); } + /** + * https://github.com/solspace/craft-calendar/issues/122. + * + * Adds original event date as an occurrence + * + * @return array + */ + public function addOriginalEventToSelectDates(array &$selectDates) + { + if (\array_key_exists(0, $selectDates) && !empty($selectDates[0]) && !empty($selectDates[0]->eventId)) { + $event = Calendar::getInstance()->events->getEventById($selectDates[0]->eventId); + if ($event) { + $originalEventDate = new SelectDateModel(); + $originalEventDate->id = (int) $event->getId(); + $originalEventDate->eventId = (int) $event->getId(); + $originalEventDate->date = new Carbon($event->getStartDate(), DateHelper::UTC); + + array_unshift($selectDates, $originalEventDate); + } + } + } + + /** + * Removes original event date as an occurrence. + * + * @return array + */ + public function removeOriginalEventFromSelectDates(array &$selectDates) + { + if (\array_key_exists(0, $selectDates) && !empty($selectDates[0]) && !empty($selectDates[0]->eventId)) { + $event = Calendar::getInstance()->events->getEventById($selectDates[0]->eventId); + + // Only remove if it matches the original event + if ($event && $event->getId() == $selectDates[0]->id && $event->getId() == $selectDates[0]->eventId && $event->getStartDate() == $selectDates[0]->date) { + array_shift($selectDates); + } + } + } + /** * {@inheritDoc} */ @@ -1577,43 +1611,4 @@ private function getRRuleObject() 'BYYEARDAY' => $this->byYearDay, ]); } - - /** - * https://github.com/solspace/craft-calendar/issues/122 - * - * Adds original event date as an occurrence - * - * @return array - */ - public function addOriginalEventToSelectDates(array &$selectDates) - { - if (array_key_exists(0, $selectDates) && ! empty($selectDates[0]) && ! empty($selectDates[0]->eventId)) { - $event = Calendar::getInstance()->events->getEventById($selectDates[0]->eventId); - if ($event) { - $originalEventDate = new SelectDateModel(); - $originalEventDate->id = (int)$event->getId(); - $originalEventDate->eventId = (int)$event->getId(); - $originalEventDate->date = new Carbon($event->getStartDate(), DateHelper::UTC); - - array_unshift($selectDates, $originalEventDate); - } - } - } - - /** - * Removes original event date as an occurrence - * - * @return array - */ - public function removeOriginalEventFromSelectDates(array &$selectDates) - { - if (array_key_exists(0, $selectDates) && ! empty($selectDates[0]) && ! empty($selectDates[0]->eventId)) { - $event = Calendar::getInstance()->events->getEventById($selectDates[0]->eventId); - - // Only remove if it matches the original event - if ($event && $event->getId() == $selectDates[0]->id && $event->getId() == $selectDates[0]->eventId && $event->getStartDate() == $selectDates[0]->date) { - array_shift($selectDates); - } - } - } } diff --git a/packages/plugin/src/FieldTypes/CalendarFieldType.php b/packages/plugin/src/FieldTypes/CalendarFieldType.php index fa7106aa..faff57c5 100644 --- a/packages/plugin/src/FieldTypes/CalendarFieldType.php +++ b/packages/plugin/src/FieldTypes/CalendarFieldType.php @@ -41,10 +41,8 @@ public function getContentColumnType(): array|string /** * {@inheritDoc IFieldType::getInputHtml()}. - * - * @param mixed $value */ - public function getInputHtml(mixed $value, ?\craft\base\ElementInterface $element = null): string + public function getInputHtml(mixed $value, ?ElementInterface $element = null): string { $calendars = Calendar::getInstance()->calendars->getAllAllowedCalendars(); @@ -93,7 +91,7 @@ public static function supportedTranslationMethods(): array return []; } - public function getIsTranslatable(?\craft\base\ElementInterface $element = null): bool + public function getIsTranslatable(?ElementInterface $element = null): bool { return false; } @@ -101,7 +99,7 @@ public function getIsTranslatable(?\craft\base\ElementInterface $element = null) /** * {@inheritDoc} */ - public function serializeValue(mixed $value, ?\craft\base\ElementInterface $element = null): mixed + public function serializeValue(mixed $value, ?ElementInterface $element = null): mixed { if ($value instanceof CalendarModel) { return $value->id; @@ -113,7 +111,7 @@ public function serializeValue(mixed $value, ?\craft\base\ElementInterface $elem /** * {@inheritDoc} */ - public function normalizeValue(mixed $value, ?\craft\base\ElementInterface $element = null): mixed + public function normalizeValue(mixed $value, ?ElementInterface $element = null): mixed { if ($value instanceof CalendarModel) { return $value; diff --git a/packages/plugin/src/FieldTypes/EventFieldType.php b/packages/plugin/src/FieldTypes/EventFieldType.php index f83baefd..c4e9fb16 100644 --- a/packages/plugin/src/FieldTypes/EventFieldType.php +++ b/packages/plugin/src/FieldTypes/EventFieldType.php @@ -35,9 +35,6 @@ public static function valueType(): string return EventQuery::class; } - /** - * @param mixed $value - */ public function getTableAttributeHtml(mixed $value, ElementInterface $element): string { if (\is_array($value)) { @@ -52,7 +49,7 @@ public function getTableAttributeHtml(mixed $value, ElementInterface $element): return parent::getTableAttributeHtml($value, $element); } - public function getContentGqlType(): array|\GraphQL\Type\Definition\Type + public function getContentGqlType(): array|Type { $gqlType = [ 'name' => $this->handle, @@ -69,11 +66,9 @@ public function getContentGqlType(): array|\GraphQL\Type\Definition\Type } /** - * @param mixed $value - * * @return ElementQuery|mixed */ - public function normalizeValue(mixed $value, ?\craft\base\ElementInterface $element = null): mixed + public function normalizeValue(mixed $value, ?ElementInterface $element = null): mixed { $query = parent::normalizeValue($value, $element); diff --git a/packages/plugin/src/Library/Attributes/AbstractAttributes.php b/packages/plugin/src/Library/Attributes/AbstractAttributes.php index 2940aeea..8b617e00 100644 --- a/packages/plugin/src/Library/Attributes/AbstractAttributes.php +++ b/packages/plugin/src/Library/Attributes/AbstractAttributes.php @@ -8,8 +8,8 @@ abstract class AbstractAttributes { - const SORT_ASC = 'ASC'; - const SORT_DESC = 'DESC'; + public const SORT_ASC = 'ASC'; + public const SORT_DESC = 'DESC'; /** @var array */ protected $validAttributes; @@ -58,7 +58,7 @@ public function getQuery(): Query $query = $this->query; foreach ($this->attributes as $name => $value) { - list($operator, $value) = DatabaseHelper::prepareOperator($value); + [$operator, $value] = DatabaseHelper::prepareOperator($value); $query->andWhere([$operator, $name, $value]); } diff --git a/packages/plugin/src/Library/CodePack/CodePack.php b/packages/plugin/src/Library/CodePack/CodePack.php index fb5fe717..5edf574a 100644 --- a/packages/plugin/src/Library/CodePack/CodePack.php +++ b/packages/plugin/src/Library/CodePack/CodePack.php @@ -9,7 +9,7 @@ class CodePack { - const MANIFEST_NAME = 'manifest.json'; + public const MANIFEST_NAME = 'manifest.json'; /** @var string */ private $location; diff --git a/packages/plugin/src/Library/CodePack/Components/AssetsFileComponent.php b/packages/plugin/src/Library/CodePack/Components/AssetsFileComponent.php index 1a46e75b..e8b2fd2b 100644 --- a/packages/plugin/src/Library/CodePack/Components/AssetsFileComponent.php +++ b/packages/plugin/src/Library/CodePack/Components/AssetsFileComponent.php @@ -52,7 +52,7 @@ public function postFileCopyAction($newFilePath, $prefix = null) if (\in_array($extension, self::$modifiableCssFiles, true)) { $content = $this->updateImagesURL($content, $prefix); - //$content = $this->updateRelativePaths($content, $prefix); + // $content = $this->updateRelativePaths($content, $prefix); $content = $this->replaceCustomPrefixCalls($content, $prefix); } diff --git a/packages/plugin/src/Library/ColorJizz/Formats/CIELab.php b/packages/plugin/src/Library/ColorJizz/Formats/CIELab.php index 7138ce56..c95a7e43 100755 --- a/packages/plugin/src/Library/ColorJizz/Formats/CIELab.php +++ b/packages/plugin/src/Library/ColorJizz/Formats/CIELab.php @@ -42,9 +42,9 @@ class CIELab extends ColorJizz public function __construct($lightness, $a_dimension, $b_dimension) { $this->toSelf = 'toCIELab'; - $this->lightness = $lightness; //$this->roundDec($l, 3); - $this->a_dimension = $a_dimension; //$this->roundDec($a, 3); - $this->b_dimension = $b_dimension; //$this->roundDec($b, 3); + $this->lightness = $lightness; // $this->roundDec($l, 3); + $this->a_dimension = $a_dimension; // $this->roundDec($a, 3); + $this->b_dimension = $b_dimension; // $this->roundDec($b, 3); } /** diff --git a/packages/plugin/src/Library/DataObjects/EventListOptions.php b/packages/plugin/src/Library/DataObjects/EventListOptions.php index a07e3c7d..17d38953 100644 --- a/packages/plugin/src/Library/DataObjects/EventListOptions.php +++ b/packages/plugin/src/Library/DataObjects/EventListOptions.php @@ -7,8 +7,8 @@ class EventListOptions { - const SORT_ASC = 'ASC'; - const SORT_DESC = 'DESC'; + public const SORT_ASC = 'ASC'; + public const SORT_DESC = 'DESC'; /** @var Carbon */ private $rangeStart; diff --git a/packages/plugin/src/Library/DatabaseHelper.php b/packages/plugin/src/Library/DatabaseHelper.php index 9cd86845..9d392a8a 100644 --- a/packages/plugin/src/Library/DatabaseHelper.php +++ b/packages/plugin/src/Library/DatabaseHelper.php @@ -7,10 +7,10 @@ class DatabaseHelper { - const OPERATOR_EQUALS = '='; - const OPERATOR_NOT_EQUAL = '!='; - const OPERATOR_NOT_IN = 'not'; - const OPERATOR_IN = 'in'; + public const OPERATOR_EQUALS = '='; + public const OPERATOR_NOT_EQUAL = '!='; + public const OPERATOR_NOT_IN = 'not'; + public const OPERATOR_IN = 'in'; private static $operatorList = [ self::OPERATOR_NOT_EQUAL, diff --git a/packages/plugin/src/Library/DateHelper.php b/packages/plugin/src/Library/DateHelper.php index 2d11057b..352176ab 100644 --- a/packages/plugin/src/Library/DateHelper.php +++ b/packages/plugin/src/Library/DateHelper.php @@ -8,8 +8,8 @@ class DateHelper { - const FLOATING_TIMEZONE = 'floating'; - const UTC = 'utc'; + public const FLOATING_TIMEZONE = 'floating'; + public const UTC = 'utc'; /** @var array */ private static $weekDays = [ diff --git a/packages/plugin/src/Library/Export/ExportCalendarInterface.php b/packages/plugin/src/Library/Export/ExportCalendarInterface.php index df3c8b12..c50fbb92 100644 --- a/packages/plugin/src/Library/Export/ExportCalendarInterface.php +++ b/packages/plugin/src/Library/Export/ExportCalendarInterface.php @@ -6,8 +6,8 @@ interface ExportCalendarInterface { - const DATE_TIME_FORMAT = 'Ymd\THis'; - const DATE_FORMAT = 'Ymd'; + public const DATE_TIME_FORMAT = 'Ymd\THis'; + public const DATE_FORMAT = 'Ymd'; /** * ExportCalendarInterface constructor. diff --git a/packages/plugin/src/Library/Export/ExportCalendarToIcs.php b/packages/plugin/src/Library/Export/ExportCalendarToIcs.php index 7514294f..da5efae3 100644 --- a/packages/plugin/src/Library/Export/ExportCalendarToIcs.php +++ b/packages/plugin/src/Library/Export/ExportCalendarToIcs.php @@ -112,7 +112,7 @@ private function combineExportString(Event $event, Carbon $date): string $selectDates = $event->getSelectDates(); if (empty($selectDates) && $event->isRepeating()) { $rrule = $event->getRRule(); - list($dtstart, $rrule) = explode("\n", $rrule); + [$dtstart, $rrule] = explode("\n", $rrule); $exportString .= sprintf("%s\r\n", $rrule); diff --git a/packages/plugin/src/Library/RecurrenceHelper.php b/packages/plugin/src/Library/RecurrenceHelper.php index 1e3eaf33..a0a4db9e 100644 --- a/packages/plugin/src/Library/RecurrenceHelper.php +++ b/packages/plugin/src/Library/RecurrenceHelper.php @@ -6,11 +6,11 @@ class RecurrenceHelper { - const DAILY = 'DAILY'; - const WEEKLY = 'WEEKLY'; - const MONTHLY = 'MONTHLY'; - const YEARLY = 'YEARLY'; - const SELECT_DATES = 'SELECT_DATES'; + public const DAILY = 'DAILY'; + public const WEEKLY = 'WEEKLY'; + public const MONTHLY = 'MONTHLY'; + public const YEARLY = 'YEARLY'; + public const SELECT_DATES = 'SELECT_DATES'; /** * @var array diff --git a/packages/plugin/src/Models/CalendarModel.php b/packages/plugin/src/Models/CalendarModel.php index d4026260..6c48f4c9 100644 --- a/packages/plugin/src/Models/CalendarModel.php +++ b/packages/plugin/src/Models/CalendarModel.php @@ -14,8 +14,8 @@ class CalendarModel extends Model implements \JsonSerializable { - const COLOR_LIGHTEN_MULTIPLIER = 0.2; - const COLOR_DARKEN_MULTIPLIER = -0.2; + public const COLOR_LIGHTEN_MULTIPLIER = 0.2; + public const COLOR_DARKEN_MULTIPLIER = -0.2; /** @var int */ public $id; diff --git a/packages/plugin/src/Models/SettingsModel.php b/packages/plugin/src/Models/SettingsModel.php index 2c730c33..2ce591de 100644 --- a/packages/plugin/src/Models/SettingsModel.php +++ b/packages/plugin/src/Models/SettingsModel.php @@ -7,20 +7,20 @@ class SettingsModel extends Model { - const DEFAULT_DATE_OVERLAP_THRESHOLD = 5; - const DEFAULT_TIME_INTERVAL = 30; - const DEFAULT_DURATION = 60; - const DEFAULT_ALL_DAY = false; - const DEFAULT_SHOW_MINI_CAL = true; - const DEFAULT_SHOW_DISABLED_EVENTS = true; - const DEFAULT_VIEW = Calendar::VIEW_MONTH; - const DEFAULT_ALLOW_QUICK_CREATE = true; - const DEFAULT_AUTHORED_EVENT_EDIT_ONLY = false; - const DEFAULT_FIRST_DAY_OF_WEEK = -1; - - const TIME_FORMAT_AUTO = 'auto'; - const TIME_FORMAT_12_HOUR = '12-hour'; - const TIME_FORMAT_24_HOUR = '24-hour'; + public const DEFAULT_DATE_OVERLAP_THRESHOLD = 5; + public const DEFAULT_TIME_INTERVAL = 30; + public const DEFAULT_DURATION = 60; + public const DEFAULT_ALL_DAY = false; + public const DEFAULT_SHOW_MINI_CAL = true; + public const DEFAULT_SHOW_DISABLED_EVENTS = true; + public const DEFAULT_VIEW = Calendar::VIEW_MONTH; + public const DEFAULT_ALLOW_QUICK_CREATE = true; + public const DEFAULT_AUTHORED_EVENT_EDIT_ONLY = false; + public const DEFAULT_FIRST_DAY_OF_WEEK = -1; + + public const TIME_FORMAT_AUTO = 'auto'; + public const TIME_FORMAT_12_HOUR = '12-hour'; + public const TIME_FORMAT_24_HOUR = '24-hour'; /** @var int */ public $overlapThreshold; @@ -95,8 +95,6 @@ class SettingsModel extends Model /** * Setting default values upon construction. - * - * @param array $attributes */ public function __construct(array $attributes = []) { diff --git a/packages/plugin/src/Records/CalendarRecord.php b/packages/plugin/src/Records/CalendarRecord.php index 6f67de2c..cda009d9 100644 --- a/packages/plugin/src/Records/CalendarRecord.php +++ b/packages/plugin/src/Records/CalendarRecord.php @@ -24,8 +24,8 @@ */ class CalendarRecord extends ActiveRecord { - const TABLE = '{{%calendar_calendars}}'; - const TABLE_STD = 'calendar_calendars'; + public const TABLE = '{{%calendar_calendars}}'; + public const TABLE_STD = 'calendar_calendars'; public static function tableName(): string { diff --git a/packages/plugin/src/Records/CalendarSiteSettingsRecord.php b/packages/plugin/src/Records/CalendarSiteSettingsRecord.php index 1f68cef6..75d7951e 100644 --- a/packages/plugin/src/Records/CalendarSiteSettingsRecord.php +++ b/packages/plugin/src/Records/CalendarSiteSettingsRecord.php @@ -19,7 +19,7 @@ */ class CalendarSiteSettingsRecord extends ActiveRecord { - const TABLE = '{{%calendar_calendar_sites}}'; + public const TABLE = '{{%calendar_calendar_sites}}'; public static function tableName(): string { diff --git a/packages/plugin/src/Records/ExceptionRecord.php b/packages/plugin/src/Records/ExceptionRecord.php index 39d794cd..50d1793b 100644 --- a/packages/plugin/src/Records/ExceptionRecord.php +++ b/packages/plugin/src/Records/ExceptionRecord.php @@ -11,7 +11,7 @@ */ class ExceptionRecord extends ActiveRecord { - const TABLE = '{{%calendar_exceptions}}'; + public const TABLE = '{{%calendar_exceptions}}'; public static function tableName(): string { diff --git a/packages/plugin/src/Records/SelectDateRecord.php b/packages/plugin/src/Records/SelectDateRecord.php index 4bebecf8..8da86951 100644 --- a/packages/plugin/src/Records/SelectDateRecord.php +++ b/packages/plugin/src/Records/SelectDateRecord.php @@ -13,7 +13,7 @@ */ class SelectDateRecord extends ActiveRecord { - const TABLE = '{{%calendar_select_dates}}'; + public const TABLE = '{{%calendar_select_dates}}'; public static function tableName(): string { diff --git a/packages/plugin/src/Services/CalendarsService.php b/packages/plugin/src/Services/CalendarsService.php index 3c615e60..4a2e71d5 100644 --- a/packages/plugin/src/Services/CalendarsService.php +++ b/packages/plugin/src/Services/CalendarsService.php @@ -23,10 +23,10 @@ class CalendarsService extends Component { - const EVENT_BEFORE_SAVE = 'beforeSave'; - const EVENT_AFTER_SAVE = 'afterSave'; - const EVENT_BEFORE_DELETE = 'beforeDelete'; - const EVENT_AFTER_DELETE = 'afterDelete'; + public const EVENT_BEFORE_SAVE = 'beforeSave'; + public const EVENT_AFTER_SAVE = 'afterSave'; + public const EVENT_BEFORE_DELETE = 'beforeDelete'; + public const EVENT_AFTER_DELETE = 'afterDelete'; /** @var CalendarModel[] */ private $calendarCache; diff --git a/packages/plugin/src/Services/EventsService.php b/packages/plugin/src/Services/EventsService.php index a14f3a16..5fe31f37 100644 --- a/packages/plugin/src/Services/EventsService.php +++ b/packages/plugin/src/Services/EventsService.php @@ -21,10 +21,10 @@ class EventsService extends Component { - const EVENT_BEFORE_SAVE = 'beforeSave'; - const EVENT_AFTER_SAVE = 'afterSave'; - const EVENT_BEFORE_DELETE = 'beforeDelete'; - const EVENT_AFTER_DELETE = 'afterDelete'; + public const EVENT_BEFORE_SAVE = 'beforeSave'; + public const EVENT_AFTER_SAVE = 'afterSave'; + public const EVENT_BEFORE_DELETE = 'beforeDelete'; + public const EVENT_AFTER_DELETE = 'afterDelete'; /** * Returns an event by its ID. diff --git a/packages/plugin/src/Services/FormatsService.php b/packages/plugin/src/Services/FormatsService.php index a3291dcf..6e0684bf 100644 --- a/packages/plugin/src/Services/FormatsService.php +++ b/packages/plugin/src/Services/FormatsService.php @@ -12,7 +12,7 @@ class FormatsService extends Component { public function getDateFormat($length = null, string $format = Locale::FORMAT_ICU): string { - $length = $length ?? \Craft::$app->locale->getFormatter()->dateFormat; + $length ??= \Craft::$app->locale->getFormatter()->dateFormat; $dateTimeFormats = \Craft::$app->locale->getFormatter()->dateTimeFormats; $dateFormat = $dateTimeFormats[$length]['date']; @@ -42,7 +42,7 @@ public function getDateTimeFormat(): string private function getSettingsTimeFormat(string $length = null) { - $length = $length ?? \Craft::$app->locale->getFormatter()->timeFormat; + $length ??= \Craft::$app->locale->getFormatter()->timeFormat; switch (Calendar::getInstance()->settings->getSettingsModel()->timeFormat) { case SettingsModel::TIME_FORMAT_12_HOUR: diff --git a/packages/plugin/src/Twig/Extensions/RequireEventEditPermissions_Node.php b/packages/plugin/src/Twig/Extensions/RequireEventEditPermissions_Node.php index dda27d94..4d0a65a4 100644 --- a/packages/plugin/src/Twig/Extensions/RequireEventEditPermissions_Node.php +++ b/packages/plugin/src/Twig/Extensions/RequireEventEditPermissions_Node.php @@ -6,7 +6,7 @@ class RequireEventEditPermissions_Node extends \Twig\Node\Node { - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/packages/plugin/src/Twig/Extensions/RequireEventEditPermissions_TokenParser.php b/packages/plugin/src/Twig/Extensions/RequireEventEditPermissions_TokenParser.php index 3bf002dd..d14d9f66 100644 --- a/packages/plugin/src/Twig/Extensions/RequireEventEditPermissions_TokenParser.php +++ b/packages/plugin/src/Twig/Extensions/RequireEventEditPermissions_TokenParser.php @@ -6,7 +6,7 @@ class RequireEventEditPermissions_TokenParser extends \Twig\TokenParser\AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $lineNumber = $token->getLine(); $parser = $this->parser; diff --git a/packages/plugin/tests/Library/DatabaseHelperTest.php b/packages/plugin/tests/Library/DatabaseHelperTest.php index 1b81496a..40847526 100644 --- a/packages/plugin/tests/Library/DatabaseHelperTest.php +++ b/packages/plugin/tests/Library/DatabaseHelperTest.php @@ -32,7 +32,7 @@ public function operatorDataProvider(): array */ public function testOperators($input, string $expectedOperator, $expectedValue): void { - list($operator, $value) = DatabaseHelper::prepareOperator($input); + [$operator, $value] = DatabaseHelper::prepareOperator($input); self::assertSame($expectedOperator, $operator); self::assertSame($expectedValue, $value);