GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 1b0ff5...fdecf9 )
by Alexsandr
74:11 queued 39:05
created

XMLWriterHelper   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 67
Duplicated Lines 19.4 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 14
lcom 0
cbo 2
dl 13
loc 67
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C renderOffer() 13 60 14

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
namespace corpsepk\yml\helpers;
4
5
use XMLWriter;
6
use yii\helpers\Html;
7
use corpsepk\yml\models\Offer;
8
9
class XMLWriterHelper
10
{
11
    /**
12
     * @param Offer $offer
13
     * @return string
14
     */
15
    public function renderOffer($offer)
16
    {
17
        $writer = new XMLWriter();
18
        $writer->openMemory();
19
20
        $writer->startElement('offer');
21
22
        foreach ($offer->offerElementAttributes as $attribute) {
23
            if (!empty($offer->$attribute)) {
24
                $writer->writeAttribute($attribute, Html::encode($offer->$attribute));
25
            }
26
        }
27
28
        foreach ($offer->customElements as $attribute) {
29
            if (!is_array($attribute)) {
30
                continue;
31
            }
32
33
            foreach ($attribute as $attrName => $attrValue) {
34
                if (is_array($attrValue)) {
35
                    $writer->startElement($attrName);
36
                    foreach ($attrValue as $name => $value) {
37
                        $writer->writeElement($name, Html::encode($value));
38
                    }
39
                    $writer->endElement();
40
                } else {
41
                    $writer->startElement($attrName);
42
                    $writer->writeRaw($attrValue);
43
                    $writer->endElement();
44
                }
45
            }
46
        }
47
48 View Code Duplication
        foreach ($offer->getOfferElements() as $attribute) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
49
            if (empty($offer->$attribute)) {
50
                continue;
51
            }
52
53
            if (is_array($offer->$attribute)) {
54
                foreach ($offer->$attribute as $value) {
55
                    $writer->writeElement($attribute, Html::encode($value));
56
                }
57
            } else {
58
                $writer->writeElement($attribute, Html::encode($offer->$attribute));
59
            }
60
        }
61
62
        if (is_array($offer->param)) {
63
            foreach ($offer->param as $param) {
64
                $writer->startElement('param');
65
                $writer->writeAttribute('name', $param['name']);
66
                $writer->text($param['value']);
67
                $writer->endElement();
68
            }
69
        }
70
71
        $writer->endElement();
72
73
        return $writer->outputMemory();
74
    }
75
}