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

Contact::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 6
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
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