• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fnagel / t3extblog / 23823603081

31 Mar 2026 11:05PM UTC coverage: 37.437% (-12.6%) from 50.045%
23823603081

push

github

fnagel
[FEATURE] Add YAML lint to composer scripts and CI

Using the new TYPO3 14.2 built in YAML linter.

https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.3/Feature-104973-ActivateLintYamlExecutableForTYPO3.html

1256 of 3355 relevant lines covered (37.44%)

3.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

7.69
/Classes/Service/AbstractNotificationService.php
1
<?php
2

3
namespace FelixNagel\T3extblog\Service;
4

5
/**
6
 * This file is part of the "t3extblog" Extension for TYPO3 CMS.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11

12
use FelixNagel\T3extblog\Exception\Exception;
13
use FelixNagel\T3extblog\Traits\LoggingTrait;
14
use FelixNagel\T3extblog\Utility\SiteUtility;
15
use Psr\EventDispatcher\EventDispatcherInterface;
16
use TYPO3\CMS\Core\Localization\Locale;
17
use TYPO3\CMS\Core\SingletonInterface;
18
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
19
use TYPO3\CMS\Core\Utility\GeneralUtility;
20
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
21
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
22
use FelixNagel\T3extblog\Domain\Model\AbstractSubscriber;
23
use FelixNagel\T3extblog\Domain\Model\Comment;
24
use TYPO3\CMS\Core\Http\ApplicationType;
25

26
/**
27
 * Handles all notification mails.
28
 *
29
 * @SuppressWarnings("PHPMD.CouplingBetweenObjects")
30
 */
31
abstract class AbstractNotificationService implements NotificationServiceInterface, SingletonInterface
32
{
33
    use LoggingTrait;
34

35
    protected $subscriberRepository;
36

37
    protected array $settings = [];
38

39
    protected array $subscriptionSettings = [];
40

41
    public function __construct(
12✔
42
        protected SettingsService $settingsService,
43
        protected EmailService $emailService,
44
        protected FlushCacheService $cacheService,
45
        protected readonly EventDispatcherInterface $eventDispatcher
46
    ) {
47

48
    }
12✔
49

50
    public function initializeObject()
12✔
51
    {
52
        $this->settings = $this->settingsService->getTypoScriptSettings();
12✔
53
    }
54

55
    /**
56
     * Send subscriber notification emails.
57
     */
58
    protected function sendSubscriberEmail(
×
59
        AbstractSubscriber $subscriber,
60
        string $subject,
61
        string $template,
62
        array $variables = [],
63
    ): void {
64
        if (empty($subscriber->getEmail())) {
×
65
            throw new Exception('Email address is a required property!', 1592248953);
×
66
        }
67

68
        $this->sendEmail(
×
69
            $subscriber->getMailTo(),
×
70
            $subject,
×
71
            $template,
×
72
            $this->subscriptionSettings['subscriber'],
×
73
            array_merge($variables, [
×
74
                'subscriber' => $subscriber,
×
75
                'validUntil' => $this->getValidUntil(),
×
76
            ]),
×
77
            SiteUtility::getLanguage($subscriber->getPid(), $subscriber->getSysLanguageUid())
×
78
        );
×
79
    }
80

81
    /**
82
     * Send notification emails.
83
     */
84
    protected function sendEmail(
×
85
        array $mailTo,
86
        string $subject,
87
        string $template,
88
        array $settings,
89
        array $variables = [],
90
        ?SiteLanguage $language = null
91
    ): void {
92
        $this->emailService->send(
×
93
            $mailTo,
×
94
            [$settings['mailFrom']['email'] => $settings['mailFrom']['name']],
×
95
            $subject,
×
96
            $variables,
×
97
            $template,
×
98
            $language->getLocale()
×
99
        );
×
100
    }
101

102
    /**
103
     * Render dateTime object for using in template.
104
     */
105
    protected function getValidUntil(): \DateTime
×
106
    {
107
        $date = new \DateTime();
×
108
        $modify = '+1 hour';
×
109

110
        if (isset($this->subscriptionSettings['subscriber']['emailHashTimeout'])) {
×
111
            $modify = trim($this->subscriptionSettings['subscriber']['emailHashTimeout']);
×
112
        }
113

114
        $date->modify($modify);
×
115

116
        return $date;
×
117
    }
118

119
    protected function translate(string $key, string $variable = '', ?Locale $locale = null): ?string
×
120
    {
121
        return LocalizationUtility::translate(
×
122
            $key,
×
123
            'T3extblog',
×
124
            [
×
125
                $this->settings['blogName'],
×
126
                $variable,
×
127
            ],
×
128
            // @todo Using the Local object directly will result in wrong localization!
129
            // Same issue is true for the Fluid view helpers.
130
            // Seems to be a core bug, see https://forge.typo3.org/issues/108102
131
            $locale->getLanguageCode()
×
132
        );
×
133
    }
134

135
    /**
136
     * Helper function for flush frontend page cache.
137
     *
138
     * Needed as we want to make sure new comments are visible after enabling in BE.
139
     * In addition, this clears the cache when a new comment is added in FE.
140
     *
141
     * @param Comment $comment Comment
142
     */
143
    public function flushFrontendCache(Comment $comment)
×
144
    {
145
        $this->cacheService->addCacheTagsToFlush([
×
146
            'tx_t3blog_post_uid_'.$comment->getPost()->getLocalizedUid(),
×
147
            'tx_t3blog_com_pid_'.$comment->getPid(),
×
148
        ]);
×
149
    }
150

151
    /**
152
     * Helper function for persisting all changed data to the DB.
153
     *
154
     * Needed as in non FE controller context (aka our hook) there is no
155
     * auto persisting.
156
     */
157
    protected function persistToDatabase(bool $force = false)
×
158
    {
159
        if ($force || ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()) {
×
160
            GeneralUtility::makeInstance(PersistenceManager::class)->persistAll();
×
161
        }
162
    }
163
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc