Completed
Push — develop ( 69bf64...c61561 )
by
unknown
09:01
created

Contact   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 4
dl 45
loc 45
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 2
A inherit() 12 12 1

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
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
namespace Cv\Entity;
11
12
use Auth\Entity\Info;
13
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
14
use Auth\Entity\InfoInterface;
15
use Core\Entity\Hydrator\EntityHydrator;
16
use Core\Entity\Hydrator\Strategy\FileCopyStrategy;
17
18
/**
19
 * Holds the contact information including the optional photo of the applicant.
20
 *
21
 * @ODM\EmbeddedDocument
22
 */
23 View Code Duplication
class Contact extends Info
0 ignored issues
show
Duplication introduced by
This class 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...
24
{
25
26
    /**
27
     * Contact image
28
     *
29
     * @var ContactImage
30
     * @ODM\ReferenceOne(targetDocument="\Cv\Entity\ContactImage", simple=true, nullable=true, cascade={"persist"})
31
     * @ODM\Index
32
     */
33
    protected $image;
34
    
35
    /**
36
     * Creates a Contact
37
     *
38
     * @param InfoInterface|null $userInfo
39
     * @uses inherit()
40
     */
41
    public function __construct(InfoInterface $userInfo = null)
42
    {
43
        if ($userInfo) {
44
            $this->inherit($userInfo);
45
        }
46
    }
47
48
    /**
49
     * Inherit data from an {@link UserInfoInterface}.
50
     *
51
     * Copies the user image to an application attachment.
52
     * @param InfoInterface $info
53
     * @return $this
54
     */
55
    public function inherit(InfoInterface $info)
56
    {
57
        $hydrator      = new EntityHydrator();
58
        $imageStrategy = new FileCopyStrategy(new ContactImage());
59
        
60
        $hydrator->addStrategy('image', $imageStrategy);
61
        
62
        $data = $hydrator->extract($info);
63
        $hydrator->hydrate($data, $this);
64
        
65
        return $this;
66
    }
67
}
68