Code Duplication    Length = 29-29 lines in 2 locations

Bundle/BlogBundle/Listener/ArticleSubscriber.php 1 location

@@ 70-98 (lines=29) @@
67
     *
68
     * @param LoadClassMetadataEventArgs $eventArgs
69
     */
70
    public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
71
    {
72
        $metadata = $eventArgs->getClassMetadata();
73
74
        //set a relation between Page and User to define the page author
75
        $metaBuilder = new ClassMetadataBuilder($metadata);
76
77
        //Add author relation on view
78
        if ($this->userClass && $metadata->name === 'Victoire\Bundle\BlogBundle\Entity\Article') {
79
            $metadata->mapManyToOne([
80
                'fieldName'    => 'author',
81
                'targetEntity' => $this->userClass,
82
                'cascade'      => ['persist'],
83
                'inversedBy'   => 'articles',
84
                'joinColumns'  => [
85
                    [
86
                        'name'                 => 'author_id',
87
                        'referencedColumnName' => 'id',
88
                        'onDelete'             => 'SET NULL',
89
                    ],
90
                ],
91
            ]);
92
        }
93
94
        // if $article's property exists, add the inversed side on User
95
        if ($metadata->name === $this->userClass && property_exists($this->userClass, 'articles')) {
96
            $metaBuilder->addOneToMany('articles', 'Victoire\Bundle\BlogBundle\Entity\Article', 'author');
97
        }
98
    }
99
}
100

Bundle/PageBundle/EventSubscriber/PageSubscriber.php 1 location

@@ 101-129 (lines=29) @@
98
     *
99
     * @param LoadClassMetadataEventArgs $eventArgs
100
     */
101
    public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
102
    {
103
        $metadata = $eventArgs->getClassMetadata();
104
105
        //set a relation between Page and User to define the page author
106
        $metaBuilder = new ClassMetadataBuilder($metadata);
107
108
        //Add author relation on view
109
        if ($this->userClass && $metadata->name === 'Victoire\Bundle\CoreBundle\Entity\View') {
110
            $metadata->mapManyToOne([
111
                'fieldName'    => 'author',
112
                'targetEntity' => $this->userClass,
113
                'cascade'      => ['persist'],
114
                'inversedBy'   => 'pages',
115
                'joinColumns'  => [
116
                    [
117
                        'name'                 => 'author_id',
118
                        'referencedColumnName' => 'id',
119
                        'onDelete'             => 'SET NULL',
120
                    ],
121
                ],
122
            ]);
123
        }
124
125
        // if $pages property exists, add the inversed side on User
126
        if ($metadata->name === $this->userClass && property_exists($this->userClass, 'pages')) {
127
            $metaBuilder->addOneToMany('pages', 'Victoire\Bundle\CoreBundle\Entity\View', 'author');
128
        }
129
    }
130
131
    /**
132
     * If entity is a View