Passed
Push — refactoring/typo3v10 ( 391308...5b953b )
by Felix
07:22
created

EidProcessorService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 82.61%

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 57
ccs 19
cts 23
cp 0.8261
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A processRequest() 0 26 5
A __construct() 0 7 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
    {
55 3
        $this->featureFlagService = $service;
56 3
        $this->cacheManager = $cacheManager;
57 3
    }
58
59
    /**
60
     * Process request
61
     * @throws ActionNotFoundException
62
     * @throws FeatureNotFoundException
63
     * @throws IllegalObjectTypeException
64
     */
65 3
    public function processRequest()
66
    {
67 3
        $action = GeneralUtility::_GP('action');
68 3
        $featureName = GeneralUtility::_GP('feature');
69
70 3
        $response = null;
71
72 3
        switch ($action) {
73 3
            case 'activate':
74 1
                $this->featureFlagService->updateFeatureFlag($featureName, true);
75 1
                break;
76 2
            case 'deactivate':
77 1
                $this->featureFlagService->updateFeatureFlag($featureName, false);
78 1
                break;
79 1
            case 'flagentries':
80
                $this->featureFlagService->flagEntries();
81
                break;
82 1
            case 'status':
83
                $response = $this->featureFlagService->isFeatureEnabled($featureName);
84
                break;
85
            default:
86 1
                throw new ActionNotFoundException('Action not found', 1515750886);
87
                break;
88
        }
89
90 2
        echo json_encode(['status' => 200, 'response' => $response]);
91
    }
92
}