Completed
Push — master ( 0c2aa0...b1edbb )
by Michiel
03:00 queued 10s
created

ConfigurationController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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();
0 ignored issues
show
Documentation Bug introduced by
It seems like $request->getContent() can also be of type resource. However, the property $configuration is declared as type string. Maybe add an additional type check?

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 the id property of an instance of the Account 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.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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