Passed
Push — refactoring/typo3v10 ( 064584...244caa )
by Felix
07:56
created

EidProcessorService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 82.61%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 55
ccs 19
cts 23
cp 0.8261
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A processRequest() 0 25 5
A __construct() 0 6 1
1
<?php
2
namespace Aoe\FeatureFlag\Service;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2021 AOE GmbH <[email protected]>
8
 *
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use Aoe\FeatureFlag\Service\Exception\ActionNotFoundException;
29
use Aoe\FeatureFlag\Service\Exception\FeatureNotFoundException;
30
use Aoe\FeatureFlag\System\Typo3\CacheManager;
31
use TYPO3\CMS\Core\Utility\GeneralUtility;
32
use TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException;
33
34
class EidProcessorService
35
{
36
    /**
37
     * @var FeatureFlagService
38
     */
39
    protected $featureFlagService;
40
41
    /**
42
     * @var CacheManager
43
     */
44
    protected $cacheManager;
45
46
    /**
47
     * @param FeatureFlagService $service
48
     * @param CacheManager $cacheManager
49
     */
50 3
    public function __construct(
51
        FeatureFlagService $service,
52
        CacheManager $cacheManager
53
    ) {
54 3
        $this->featureFlagService = $service;
55 3
        $this->cacheManager = $cacheManager;
56 3
    }
57
58
    /**
59
     * Process request
60
     * @throws ActionNotFoundException
61
     * @throws FeatureNotFoundException
62
     * @throws IllegalObjectTypeException
63
     */
64 3
    public function processRequest()
65
    {
66 3
        $action = GeneralUtility::_GP('action');
67 3
        $featureName = GeneralUtility::_GP('feature');
68
69 3
        $response = null;
70
71 3
        switch ($action) {
72 3
            case 'activate':
73 1
                $this->featureFlagService->updateFeatureFlag($featureName, true);
74 1
                break;
75 2
            case 'deactivate':
76 1
                $this->featureFlagService->updateFeatureFlag($featureName, false);
77 1
                break;
78 1
            case 'flagentries':
79
                $this->featureFlagService->flagEntries();
80
                break;
81 1
            case 'status':
82
                $response = $this->featureFlagService->isFeatureEnabled($featureName);
83
                break;
84
            default:
85 1
                throw new ActionNotFoundException('Action not found', 1515750886);
86
        }
87
88 2
        echo json_encode(['status' => 200, 'response' => $response]);
89
    }
90
}