1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 SURFnet bv |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Surfnet\StepupMiddleware\ManagementBundle\Controller; |
20
|
|
|
|
21
|
|
|
use DateTime; |
22
|
|
|
use Rhumsaa\Uuid\Uuid; |
23
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Command\Command; |
24
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\UpdateConfigurationCommand; |
25
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Pipeline\TransactionAwarePipeline; |
26
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
27
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
28
|
|
|
use Symfony\Component\HttpFoundation\Request; |
29
|
|
|
|
30
|
|
|
class ConfigurationController extends Controller |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @return TransactionAwarePipeline |
34
|
|
|
*/ |
35
|
|
|
private $pipeline; |
36
|
|
|
|
37
|
|
|
public function __construct(TransactionAwarePipeline $pipeline) |
38
|
|
|
{ |
39
|
|
|
$this->pipeline = $pipeline; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function updateAction(Request $request) |
43
|
|
|
{ |
44
|
|
|
$command = new UpdateConfigurationCommand(); |
45
|
|
|
$command->UUID = (string) Uuid::uuid4(); |
46
|
|
|
$command->configuration = $request->getContent(); |
|
|
|
|
47
|
|
|
|
48
|
|
|
return $this->handleCommand($request, $command); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param Request $request |
53
|
|
|
* @param Command $command |
54
|
|
|
* @return JsonResponse |
55
|
|
|
*/ |
56
|
|
View Code Duplication |
private function handleCommand(Request $request, Command $command) |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$this->pipeline->process($command); |
59
|
|
|
|
60
|
|
|
$serverName = $request->server->get('SERVER_NAME') ?: $request->server->get('SERVER_ADDR'); |
61
|
|
|
$response = new JsonResponse([ |
62
|
|
|
'status' => 'OK', |
63
|
|
|
'processed_by' => $serverName, |
64
|
|
|
'applied_at' => (new DateTime())->format(DateTime::ISO8601) |
65
|
|
|
]); |
66
|
|
|
|
67
|
|
|
return $response; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.