OgSeoGenerator   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 145
Duplicated Lines 9.66 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 6
dl 14
loc 145
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A setType() 0 4 1
A getType() 0 4 1
A setTitle() 0 4 1
A getTitle() 0 4 1
A setDescription() 0 4 1
A getDescription() 0 4 1
A setImage() 0 9 1
A getImage() 0 4 1
A setUrl() 0 4 1
A getUrl() 0 4 1
A fromResource() 14 14 4
A get() 0 4 1
A set() 0 9 1

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 Leogout\Bundle\SeoBundle\Seo\Og;
4
5
use Leogout\Bundle\SeoBundle\Model\MetaTag;
6
use Leogout\Bundle\SeoBundle\Seo\AbstractSeoGenerator;
7
use Leogout\Bundle\SeoBundle\Seo\TitleSeoInterface;
8
use Leogout\Bundle\SeoBundle\Seo\DescriptionSeoInterface;
9
use Leogout\Bundle\SeoBundle\Seo\ImageSeoInterface;
10
11
/**
12
 * Description of OgSeoGenerator.
13
 *
14
 * @author: leogout
15
 */
16
class OgSeoGenerator extends AbstractSeoGenerator
17
{
18
    /**
19
     * @param string $content
20
     *
21
     * @return $this
22
     */
23
    public function setType($content)
24
    {
25
        return $this->set('og:type', $content);
26
    }
27
28
    /**
29
     * @return MetaTag
30
     */
31
    public function getType()
32
    {
33
        return $this->get('og:type');
34
    }
35
36
    /**
37
     * @param string $content
38
     *
39
     * @return $this
40
     */
41
    public function setTitle($content)
42
    {
43
        return $this->set('og:title', $content);
44
    }
45
46
    /**
47
     * @return MetaTag
48
     */
49
    public function getTitle()
50
    {
51
        return $this->get('og:title');
52
    }
53
54
    /**
55
     * @param string $content
56
     *
57
     * @return $this
58
     */
59
    public function setDescription($content)
60
    {
61
        return $this->set('og:description', $content);
62
    }
63
64
    /**
65
     * @return MetaTag
66
     */
67
    public function getDescription()
68
    {
69
        return $this->get('og:description');
70
    }
71
72
    /**
73
     * @param string $content
74
     *
75
     * @return $this
76
     */
77
    public function setImage($content)
78
    {
79
        $this->tagBuilder->addMeta('og:image')
80
            ->setType(MetaTag::NAME_TYPE)
81
            ->setValue('og:image')
82
            ->setContent((string) $content);
83
84
        return $this->set('og:image', $content);
85
    }
86
87
    /**
88
     * @return MetaTag
89
     */
90
    public function getImage()
91
    {
92
        return $this->get('og:image');
93
    }
94
95
    /**
96
     * @param string $content
97
     *
98
     * @return $this
99
     */
100
    public function setUrl($content)
101
    {
102
        return $this->set('og:url', $content);
103
    }
104
105
    /**
106
     * @return MetaTag
107
     */
108
    public function getUrl()
109
    {
110
        return $this->get('og:url');
111
    }
112
113
    /**
114
     * Generate seo tags from given resource.
115
     *
116
     * @param TitleSeoInterface|DescriptionSeoInterface|ImageSeoInterface $resource
117
     *
118
     * @return $this
119
     */
120 View Code Duplication
    public function fromResource($resource)
0 ignored issues
show
Duplication introduced by
This method 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...
121
    {
122
        if ($resource instanceof TitleSeoInterface) {
123
            $this->setTitle($resource->getSeoTitle());
124
        }
125
        if ($resource instanceof DescriptionSeoInterface) {
126
            $this->setDescription($resource->getSeoDescription());
127
        }
128
        if ($resource instanceof ImageSeoInterface) {
129
            $this->setImage($resource->getSeoImage());
130
        }
131
132
        return $this;
133
    }
134
135
    /**
136
     * @param string $type
137
     *
138
     * @return MetaTag
139
     */
140
    public function get($type)
141
    {
142
        return $this->tagBuilder->getMeta($type);
143
    }
144
145
    /**
146
     * @param string $type
147
     * @param string $value
148
     *
149
     * @return $this
150
     */
151
    public function set($type, $value)
152
    {
153
        $this->tagBuilder->addMeta($type)
154
            ->setType(MetaTag::NAME_TYPE)
155
            ->setValue($type)
156
            ->setContent((string) $value);
157
158
        return $this;
159
    }
160
}
161