Passed
Pull Request — master (#925)
by Asmir
02:44
created

setDefaultEncoding()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright 2016 Johannes M. Schmitt <[email protected]>
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
namespace JMS\Serializer\VisitorFactory;
22
23
use JMS\Serializer\Accessor\AccessorStrategyInterface;
24
use JMS\Serializer\GraphNavigatorInterface;
25
use JMS\Serializer\JsonSerializationVisitor;
26
use JMS\Serializer\SerializationContext;
27
use JMS\Serializer\SerializationVisitorInterface;
28
use JMS\Serializer\XmlSerializationVisitor;
29
30
/**
31
 *
32
 * @author Asmir Mustafic <[email protected]>
33
 */
34
class XmlSerializationVisitorFactory implements SerializationVisitorFactory
35
{
36
    private $defaultRootName = 'result';
37
    private $defaultVersion = '1.0';
38
    private $defaultEncoding = 'UTF-8';
39
    private $formatOutput = true;
40
    private $defaultRootNamespace;
41
42 116
    public function getVisitor(): SerializationVisitorInterface
43
    {
44 116
        return new XmlSerializationVisitor(
45 116
            $this->formatOutput,
46 116
            $this->defaultEncoding,
47 116
            $this->defaultVersion,
48 116
            $this->defaultRootName,
49 116
            $this->defaultRootNamespace
50
        );
51
    }
52
53
    public function setDefaultRootName(string $name, ?string $namespace = null)
54
    {
55
        $this->defaultRootName = $name;
56
        $this->defaultRootNamespace = $namespace;
57
    }
58
59
    public function setDefaultVersion(string $version)
60
    {
61
        $this->defaultVersion = $version;
62
    }
63
64
    public function setDefaultEncoding(string $encoding)
65
    {
66
        $this->defaultEncoding = $encoding;
67
    }
68
69 1
    public function setFormatOutput(bool $formatOutput)
70
    {
71 1
        $this->formatOutput = (boolean)$formatOutput;
72 1
    }
73
}
74