UpdateMemberCommandHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 25 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 9
loc 36
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A handle() 9 19 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * Storgman - Student Organizations Management
5
 * Copyright (C) 2014-2015, Dejan Angelov <[email protected]>
6
 *
7
 * This file is part of Storgman.
8
 *
9
 * Storgman is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation, either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * Storgman is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with Storgman.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 * @package Storgman
23
 * @copyright Copyright (C) 2014-2015, Dejan Angelov <[email protected]>
24
 * @license https://github.com/angelov/storgman/blob/master/LICENSE
25
 * @author Dejan Angelov <[email protected]>
26
 */
27
28
namespace Angelov\Storgman\Members\Handlers;
29
30
use Angelov\Storgman\Members\Commands\UpdateMemberCommand;
31
use Angelov\Storgman\Members\MembersPopulator;
32
use Angelov\Storgman\Members\Repositories\MembersRepositoryInterface;
33
use Angelov\Storgman\Members\Photos\Repositories\PhotosRepositoryInterface;
34
use Symfony\Component\HttpFoundation\File\UploadedFile;
35
36
class UpdateMemberCommandHandler
37
{
38
    protected $members;
39
    protected $photos;
40
    protected $populator;
41
42
    public function __construct(
43
        MembersRepositoryInterface $members,
44
        PhotosRepositoryInterface $photos,
45
        MembersPopulator $populator
46
    ) {
47
        $this->members = $members;
48
        $this->photos = $photos;
49
        $this->populator = $populator;
50
    }
51
52
    public function handle(UpdateMemberCommand $command)
53
    {
54
        $member = $this->members->get($command->getMemberId());
55
        $data = $command->getMemberData();
56
57
        $this->populator->populateFromArray($member, $data);
58
59 View Code Duplication
        if (isset($data['member_photo'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
60
            /** @var UploadedFile $photo */
61
            $photo = $data['member_photo'];
62
            $photoFileName = md5($member->getEmail()) . "." . $photo->getClientOriginalExtension();
63
64
            $this->photos->store($photo, 'members', $photoFileName);
0 ignored issues
show
Unused Code introduced by
The call to PhotosRepositoryInterface::store() has too many arguments starting with $photoFileName.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
65
66
            $member->setPhoto($photoFileName);
67
        }
68
69
        $this->members->store($member);
70
    }
71
}
72