Completed
Push — master ( d535d3...8c6cf6 )
by Felix
16:53
created

EidProcessor::processRequest()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 27
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 5.1727

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 17
cts 21
cp 0.8095
rs 8.439
c 0
b 0
f 0
cc 5
eloc 21
nc 5
nop 0
crap 5.1727
1
<?php
2
namespace Aoe\FeatureFlag\Service;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2018 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 TYPO3\CMS\Core\Utility\GeneralUtility;
29
30
/**
31
 * @package FeatureFlag
32
 */
33
class EidProcessor
34
{
35
    /**
36
     * @var \Tx_FeatureFlag_Service
37
     */
38
    protected $featureFlagService;
39
40
    /**
41
     * @var \Tx_FeatureFlag_System_Typo3_CacheManager
42
     */
43
    protected $cacheManager;
44
45
    /**
46
     * Tx_FeatureFlag_Service_Eid constructor.
47
     * @param \Tx_FeatureFlag_Service $service
48
     * @param \Tx_FeatureFlag_System_Typo3_CacheManager $cacheManager
49
     */
50 3
    public function __construct(
51
        \Tx_FeatureFlag_Service $service,
52
        \Tx_FeatureFlag_System_Typo3_CacheManager $cacheManager
53
    )
54
    {
0 ignored issues
show
Coding Style introduced by
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Loading history...
55 3
        $this->featureFlagService = $service;
56 3
        $this->cacheManager = $cacheManager;
57 3
    }
58
59
    /**
60
     * Process request
61
     * @throws \Tx_FeatureFlag_Service_Exception_ActionNotFound
62
     * @throws \Tx_FeatureFlag_Service_Exception_FeatureNotFound
63
     * @throws \TYPO3\CMS\Extbase\Persistence\Exception\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
        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 1
            default:
86 1
                throw new \Tx_FeatureFlag_Service_Exception_ActionNotFound('Action not found', 1515750886);
87
                break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
88 1
        }
89
90 2
        echo json_encode(['status' => 200, 'response' => $response]);
91
    }
92
}