GoogleExtendedConverter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
lcom 2
cbo 4
dl 0
loc 32
c 1
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setSchema() 0 4 1
A setNormalizer() 0 4 1
B extended() 0 19 5
1
<?php
2
3
/*
4
 * This file is part of gpupo/pipe2
5
 *
6
 * (c) Gilmar Pupo <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * For more information, see
12
 * <https://opensource.gpupo.com/pipe2/>.
13
 */
14
15
namespace Gpupo\Pipe2\Converter;
16
17
use Gpupo\CommonSchema\Sphinx\GoogleExtendedSchema;
18
use Gpupo\Pipe2\Normalizer\GoogleExtendedNormalizer;
19
20
class GoogleExtendedConverter extends GoogleConverter
21
{
22
    public function setSchema()
23
    {
24
        $this->schema = new GoogleExtendedSchema();
25
    }
26
27
    public function setNormalizer()
28
    {
29
        $this->normalizer = new GoogleExtendedNormalizer();
30
    }
31
32
    protected function extended($item)
33
    {
34
        if (array_key_exists('sale_price', $item) && !empty($item['sale_price'])) {
35
            $item['sale_price_discount'] = $item['price'] - $item['sale_price'];
36
            $item['sale_price_percentage'] = ($item['price'] - $item['sale_price']) / $item['price'] * 100;
37
        }
38
39
        $parts = [];
40
41
        foreach (['title', 'color', 'size', 'id', 'brand', 'channel', 'category', 'sku'] as $key) {
42
            if (array_key_exists($key, $item)) {
43
                $parts[] = $item[$key];
44
            }
45
        }
46
47
        $item['document_slug'] = $this->getNormalizer()->slugify(implode('-', $parts));
48
49
        return $item;
50
    }
51
}
52