Code Duplication    Length = 22-22 lines in 2 locations

src/DataFormatter/XMLDataFormatter.php 2 locations

@@ 113-134 (lines=22) @@
110
                    . "\"></$relName>\n";
111
            }
112
113
            foreach ($obj->hasMany() as $relName => $relClass) {
114
                //remove dot notation from relation names
115
                $parts = explode('.', $relClass);
116
                $relClass = array_shift($parts);
117
                if (!singleton($relClass)->stat('api_access')) {
118
                    continue;
119
                }
120
                // backslashes in FQCNs kills both URIs and XML
121
                $relClass = $this->sanitiseClassName($relClass);
122
123
                // Field filtering
124
                if ($fields && !in_array($relName, $fields)) {
125
                    continue;
126
                }
127
                if ($this->customRelations && !in_array($relName, $this->customRelations)) {
128
                    continue;
129
                }
130
131
                $xml .= "<$relName linktype=\"has_many\" href=\"$objHref/$relName.xml\">\n";
132
                $items = $obj->$relName();
133
                if ($items) {
134
                    foreach ($items as $item) {
135
                        $href = Director::absoluteURL($this->config()->api_base . "$relClass/$item->ID");
136
                        $xml .= "<$relClass href=\"$href.xml\" id=\"{$item->ID}\"></$relClass>\n";
137
                    }
@@ 142-163 (lines=22) @@
139
                $xml .= "</$relName>\n";
140
            }
141
142
            foreach ($obj->manyMany() as $relName => $relClass) {
143
                //remove dot notation from relation names
144
                $parts = explode('.', $relClass);
145
                $relClass = array_shift($parts);
146
                if (!singleton($relClass)->stat('api_access')) {
147
                    continue;
148
                }
149
                // backslashes in FQCNs kills both URIs and XML
150
                $relClass = $this->sanitiseClassName($relClass);
151
152
                // Field filtering
153
                if ($fields && !in_array($relName, $fields)) {
154
                    continue;
155
                }
156
                if ($this->customRelations && !in_array($relName, $this->customRelations)) {
157
                    continue;
158
                }
159
160
                $xml .= "<$relName linktype=\"many_many\" href=\"$objHref/$relName.xml\">\n";
161
                $items = $obj->$relName();
162
                if ($items) {
163
                    foreach ($items as $item) {
164
                        $href = Director::absoluteURL($this->config()->api_base . "$relClass/$item->ID");
165
                        $xml .= "<$relClass href=\"$href.xml\" id=\"{$item->ID}\"></$relClass>\n";
166
                    }