settings = $settings; $this->servicesChecker = $servicesChecker; $this->subscribersFeature = $subscribersFeature; } private function getTier(): ?int { $tier = $this->settings->get(self::MSS_TIER_SETTING_KEY); return isset($tier) ? (int)$tier : null; } private function isMailpoetLogoInEmailsRequired(): bool { $mailpoetLogoInEmails = $this->settings->get(self::MSS_MAILPOET_LOGO_IN_EMAILS_SETTING_KEY); if (!isset($this->tier) && !isset($mailpoetLogoInEmails)) { return !$this->servicesChecker->isUserActivelyPaying(); // Backward compatibility } if (!$this->isKeyValid) { return true; } // Allow for less restrictive individual capability to take precedence over tier if (isset($mailpoetLogoInEmails) && (bool)$mailpoetLogoInEmails === false) { return false; } return (isset($this->tier) && $this->tier < self::MIN_TIER_LOGO_NOT_REQUIRED) || (isset($mailpoetLogoInEmails) && (bool)$mailpoetLogoInEmails === true); } private function isDetailedAnalyticsEnabled(): bool { // Preconditions if (!$this->subscribersFeature->hasValidPremiumKey() || !$this->subscribersFeature->check() || !$this->servicesChecker->isPremiumPluginActive()) { return false; } $detailedAnalytics = $this->settings->get(self::MSS_DETAILED_ANALYTICS_SETTING_KEY); if (!isset($this->tier) && !isset($detailedAnalytics)) { return true; // Backward compatibility is true when preconditions have been met } // Allow for less restrictive individual capability to take precedence if (isset($detailedAnalytics) && (bool)$detailedAnalytics === true) { return true; } return (isset($this->tier) && $this->tier >= self::MIN_TIER_ANALYTICS_ENABLED) || (isset($detailedAnalytics) && (bool)$detailedAnalytics === true); } private function getAutomationStepsLimit(): int { $automationSteps = $this->settings->get(self::MSS_AUTOMATION_STEPS_SETTING_KEY); if (!isset($this->tier) && !isset($automationSteps)) { return 0; // Backward compatibility } $stepsFromTier = isset($this->tier) && $this->tier >= self::MIN_TIER_UNLIMITED_AUTOMATION_STEPS ? 0 : 1; // 0 is unlimited // Allow for less restrictive individual capability to take precedence return (isset($automationSteps) && ((int)$automationSteps === 0 || (int)$automationSteps > $stepsFromTier)) ? (int)$automationSteps : $stepsFromTier; } private function getSegmentFiltersLimit(): int { $segmentFilters = $this->settings->get(self::MSS_SEGMENT_FILTERS_SETTING_KEY); if (!isset($this->tier) && !isset($segmentFilters)) { return 0; // Backward compatibility } $segmentFiltersFromTier = isset($this->tier) && $this->tier >= self::MIN_TIER_UNLIMITED_SEGMENT_FILTERS ? 0 : 1; // 0 is unlimited // Allow for less restrictive individual capability to take precedence return (isset($segmentFilters) && ((int)$segmentFilters === 0 || (int)$segmentFilters > $segmentFiltersFromTier)) ? (int)$segmentFilters : $segmentFiltersFromTier; } public function getCapabilities(): Capabilities { $this->tier = $this->getTier(); $isPremiumKeyValid = $this->servicesChecker->isPremiumKeyValid(false); $this->isKeyValid = $isPremiumKeyValid || $this->servicesChecker->isMailPoetAPIKeyValid(false); return new Capabilities( $this->isMailpoetLogoInEmailsRequired(), $this->isDetailedAnalyticsEnabled(), $this->getAutomationStepsLimit(), $this->getSegmentFiltersLimit(), ); } }