TimeRestrictionEvaluator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 48
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A evaluateFieldValue() 0 38 5
A getLanguageService() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
5
 *
6
 * For the full copyright and license information, please read the
7
 * LICENSE.txt file that was distributed with this source code.
8
 */
9
10
namespace DERHANSEN\SfEventMgt\Evaluation;
11
12
use TYPO3\CMS\Core\Localization\LanguageService;
13
use TYPO3\CMS\Core\Messaging\FlashMessage;
14
use TYPO3\CMS\Core\Messaging\FlashMessageService;
15
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
18
class TimeRestrictionEvaluator
19
{
20
    /**
21
     * Checks if $value can be interpreted with strtotime()
22
     */
23
    public function evaluateFieldValue(string $value, string $is_in, bool &$set): string
0 ignored issues
show
Unused Code introduced by
The parameter $is_in is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

23
    public function evaluateFieldValue(string $value, /** @scrutinizer ignore-unused */ string $is_in, bool &$set): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
    {
25
        $timestamp = strtotime($value);
26
        $set = empty($value) || $timestamp !== false;
27
28
        if (!empty($value) && $timestamp !== false) {
29
            $languageService = $this->getLanguageService();
30
31
            if ($set) {
32
                $severity = ContextualFeedbackSeverity::INFO;
33
                $message = sprintf(
34
                    $languageService->sL('LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:evaluation.timeRestriction.info'),
35
                    $value,
36
                    date($languageService->sL('LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:evaluation.timeRestriction.format'), $timestamp)
37
                );
38
            } else {
39
                $severity = ContextualFeedbackSeverity::ERROR;
40
                $message = sprintf(
41
                    $languageService->sL('LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:evaluation.timeRestriction.error'),
42
                    $value
43
                );
44
            }
45
46
            /** @var FlashMessage $message */
47
            $message = GeneralUtility::makeInstance(
48
                FlashMessage::class,
49
                $message,
50
                $languageService->sL('LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:evaluation.timeRestriction.header'),
51
                $severity,
52
                false
53
            );
54
55
            /** @var FlashMessageService $flashMessageService */
56
            $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
57
            $flashMessageService->getMessageQueueByIdentifier()->enqueue($message);
58
        }
59
60
        return $value;
61
    }
62
63
    protected function getLanguageService(): LanguageService
64
    {
65
        return $GLOBALS['LANG'];
66
    }
67
}
68