Passed
Push — master ( c8468d...041863 )
by Michael
03:25
created

PageSEO   A

Complexity

Total Complexity 29

Size/Duplication

Total Lines 160
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 101
c 1
b 0
f 0
dl 0
loc 160
rs 10
wmc 29

3 Methods

Rating   Name   Duplication   Size   Complexity  
C title() 0 57 15
A all() 0 49 2
C description() 0 48 12
1
<?php
2
3
namespace PageSEO;
4
5
use ChrisKonnertz\OpenGraph\OpenGraph;
6
7
class PageSEO
8
{
9
    public function title($type, array $attr, $locale='en')
10
    {
11
        $name = $attr['name'];
12
        $brand = isset($attr['brand']) ? $attr['brand'] : null;
13
        $site = isset($attr['site']) ? $attr['site'] : null;
14
15
        $return = $name;
16
17
        switch ($locale) {
18
        case 'en':
19
        case 'english':
20
            switch ($type) {
21
            case 'article':
22
                $return = sprintf('%s | %s', $name, $site);
23
                break;
24
25
            case 'brand':
26
                $return = sprintf('1000s of DISCOUNTS on %s', $name);
27
                break;
28
29
            case 'product':
30
                if ($brand) {
31
                    $return = sprintf('NEW, %s by %s', $name, $brand);
32
                } else {
33
                    $return = sprintf('NEW, %s by %s', $name, $brand);
34
                }
35
36
                break;
37
            }
38
39
            break;
40
41
        case 'da':
42
        case 'danish':
43
            switch ($type) {
44
            case 'article':
45
                $return = sprintf('%s | %s', $name, $site);
46
                break;
47
48
            case 'brand':
49
                $return = sprintf('1000vis af RABATTER på %s', $name);
50
                break;
51
52
            case 'product':
53
                if ($brand) {
54
                    $return = sprintf('NYT, %s fra %s', $name, $brand);
55
                } else {
56
                    $return = sprintf('NYT, %s', $name);
57
                }
58
59
                break;
60
            }
61
62
            break;
63
        }
64
65
        return $return;
66
    }
67
68
    public function description($type, array $attr, $locale='en')
69
    {
70
        $name = $attr['name'];
71
        $brand = isset($attr['brand']) ? $attr['brand'] : null;
72
73
        $return = $name;
74
75
        switch ($locale) {
76
        case 'en':
77
        case 'english':
78
            switch ($type) {
79
            case 'brand':
80
                $return = sprintf('1000s of DISCOUNTS on %s', $name);
81
                break;
82
83
            case 'product':
84
                if ($brand) {
85
                    $return = sprintf('Current DISCOUNTS on %s / %s', $name, $brand);
86
                } else {
87
                    $return = sprintf('Current DISCOUNTS on %s', $name);
88
                }
89
90
                break;
91
            }
92
93
            break;
94
95
        case 'da':
96
        case 'danish':
97
            switch ($type) {
98
            case 'brand':
99
                $return = sprintf('1000vis af RABATTER på %s', $name);
100
                break;
101
102
            case 'product':
103
                if ($brand) {
104
                    $return = sprintf('Aktuelt TILBUD på %s / %s', $name, $brand);
105
                } else {
106
                    $return = sprintf('Aktuelt TILBUD på %s', $name);
107
                }
108
109
                break;
110
            }
111
112
            break;
113
        }
114
115
        return $return;
116
    }
117
118
    public function all($type, array $attr, $locale='en')
119
    {
120
        $res = new \StdClass();
121
122
        $res->title = $this->title(
123
            'product',
124
            [
125
                'name' => $attr['name'],
126
                'brand' => $attr['brand'],
127
            ],
128
            $locale
129
        );
130
131
        $res->description = $this->description(
132
            'product',
133
            [
134
                'name' => $attr['name'],
135
                'brand' => $attr['brand'],
136
            ],
137
            $locale
138
        );
139
140
        switch ($type) {
141
        case 'product':
142
            $res->json = \JsonLd\Context::create('product', [
143
                'name' => $attr['name'],
144
                'description' => $attr['description'],
145
                'brand' => $attr['brand'],
146
                'sku' => $attr['sku'],
147
                'url' => $attr['url'],
148
                'offers' => [
149
                    'price' => $attr['price'],
150
                    'priceCurrency' => $attr['currency'],
151
                ],
152
                'category' => $attr['category'],
153
            ]);
154
155
            $res->og = new OpenGraph();
156
            $res->og->type('product')
157
                ->title($res->title)
158
                ->image($attr['image_url'])
159
                ->description($res->description)
160
                ->url($url)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $url seems to be never defined.
Loading history...
161
                ;
162
163
            break;
164
        }
165
166
        return $res;
167
    }
168
}
169