Document   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 26
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 21 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\SchemaInterface;
18
use Gpupo\Pipe2\DocumentAbstract;
19
20
/**
21
 * @see http://sphinxsearch.com/docs/current.html#xmlpipe2
22
 */
23
class Document extends DocumentAbstract
24
{
25
    protected $elementPrefix = 'sphinx:';
26
27
    public function __construct(SchemaInterface $schema, $slug = false)
28
    {
29
        parent::__construct();
30
        $this->docset = $this->createElement('sphinx:docset');
31
        $this->appendChild($this->docset);
32
        $elements = $this->createElement('sphinx:schema');
33
34
        foreach ($schema->getSchema() as $type => $list) {
35
            foreach ($list as $key => $prop) {
36
                $elements->appendChild($this->factoryTag($type, $key, $prop));
37
            }
38
        }
39
40
        if ($slug) {
41
            foreach ($schema->getSluggables() as $key) {
42
                $elements->appendChild($this->factoryTag('field', $key.'_slug', ['attr' => 'string']));
43
            }
44
        }
45
46
        $this->docset->appendChild($elements);
47
    }
48
}
49