Completed
Push — master ( b2acd3...46961e )
by Axel
03:30
created

DynamicRelationSubscriber::mapFeedback()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1.0156

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 24
ccs 9
cts 12
cp 0.75
rs 8.9713
cc 1
eloc 19
nc 1
nop 1
crap 1.0156
1
<?php
2
3
namespace Developtech\AgilityBundle\EventSubscriber;
4
5
use Doctrine\Common\EventSubscriber;
6
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
7
use Doctrine\ORM\Events;
8
use Doctrine\ORM\Mapping\ClassMetadata;
9
10
class DynamicRelationSubscriber implements EventSubscriber
11
{
12
    const MODEL_PROJECT = 'Developtech\AgilityBundle\Entity\Project';
13
    const MODEL_FEATURE = 'Developtech\AgilityBundle\Entity\Feature';
14
    const MODEL_FEEDBACK = 'Developtech\AgilityBundle\Entity\Feedback';
15
16
    /** @var string **/
17
    protected $userClass;
18
19
    /**
20
     * @param string $userClass
21
     */
22 1
    public function __construct($userClass) {
23 1
        $this->userClass = $userClass;
24 1
    }
25
26
    /**
27
     * {@inheritDoc}
28
     */
29 1
    public function getSubscribedEvents()
30
    {
31
        return array(
32 1
            Events::loadClassMetadata,
33 1
        );
34
    }
35
36
    /**
37
     * @param LoadClassMetadataEventArgs $eventArgs
38
     */
39
    public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
40
    {
41
        // the $metadata is the whole mapping info for this class
42
        $metadata = $eventArgs->getClassMetadata();
43
44
        switch($metadata->getName()) {
0 ignored issues
show
Bug introduced by
The method getName() does not seem to exist on object<Doctrine\ORM\EntityManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Coding Style introduced by
Expected 1 space after SWITCH keyword; 0 found
Loading history...
45
            case self::MODEL_PROJECT: return $this->mapProject($metadata);
0 ignored issues
show
Documentation introduced by
$metadata is of type object<Doctrine\ORM\EntityManager>, but the function expects a object<Doctrine\ORM\Mapping\ClassMetadata>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
46
            case self::MODEL_FEATURE: return $this->mapFeature($metadata);
0 ignored issues
show
Documentation introduced by
$metadata is of type object<Doctrine\ORM\EntityManager>, but the function expects a object<Doctrine\ORM\Mapping\ClassMetadata>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
47
            case self::MODEL_FEEDBACK: return $this->mapFeedback($metadata);
0 ignored issues
show
Documentation introduced by
$metadata is of type object<Doctrine\ORM\EntityManager>, but the function expects a object<Doctrine\ORM\Mapping\ClassMetadata>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
48
            default: return;
0 ignored issues
show
Coding Style introduced by
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
49
        }
50
    }
51
52
    /**
53
     * @param CLassMetadata $metadata
54
     */
55 1
    public function mapProject(ClassMetadata $metadata) {
56
        $metadata->mapManyToOne(array(
57 1
            'targetEntity'  => $this->userClass,
58 1
            'fieldName'     => 'productOwner',
59 1
            'cascade'       => array(),
60
            'joinColumn'    => array(
61
                'name' => 'product_owner_id',
62
                'referencedColumnName' => 'id',
63
                'onDelete' => 'SET NULL',
64
                'nullable' => true
65 1
            )
66
        ));
67
    }
68
69
    /**
70
     * @param CLassMetadata $metadata
71
     */
72 1
    public function mapFeature(ClassMetadata $metadata) {
73
        $metadata->mapManyToOne(array(
74 1
            'targetEntity'  => $this->userClass,
75 1
            'fieldName'     => 'responsible',
76 1
            'cascade'       => array(),
77
            'joinColumn'    => array(
78
                'name' => 'responsible_id',
79
                'referencedColumnName' => 'id',
80
                'onDelete' => 'SET NULL',
81
                'nullable' => true
82 1
            )
83
        ));
84
    }
85
86
    /**
87
     * @param CLassMetadata $metadata
88
     */
89 1
    public function mapFeedback(ClassMetadata $metadata) {
90
        $metadata->mapManyToOne(array(
91 1
            'targetEntity'  => $this->userClass,
92 1
            'fieldName'     => 'author',
93 1
            'cascade'       => array(),
94
            'joinColumn'    => array(
95
                'name' => 'author_id',
96
                'referencedColumnName' => 'id',
97
                'onDelete' => 'CASCADE',
98
                'nullable' => false
99 1
            )
100
        ));
101
        $metadata->mapManyToOne(array(
102 1
            'targetEntity'  => $this->userClass,
103 1
            'fieldName'     => 'responsible',
104 1
            'cascade'       => array(),
105
            'joinColumn'    => array(
106
                'name' => 'responsible_id',
107
                'referencedColumnName' => 'id',
108
                'onDelete' => 'SET NULL',
109
                'nullable' => true
110 1
            )
111
        ));
112
    }
113
}
114