Test Failed
Pull Request — master (#30)
by
unknown
07:34
created

FeFactory   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 144
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 53.56%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 4
dl 0
loc 144
ccs 15
cts 28
cp 0.5356
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setSender() 0 6 1
A setBuilder() 0 6 1
A setSigner() 0 6 1
A send() 0 6 1
A getBuilder() 0 4 1
A getSender() 0 4 1
A getSigner() 0 4 1
A sendForce() 0 4 1
A genXML() 0 4 1
A getLastXml() 0 4 1
A getXmlSigned() 0 6 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Administrador
5
 * Date: 20/07/2017
6
 * Time: 04:06 PM.
7
 */
8
9
namespace Greenter\Factory;
10
11
use Greenter\Builder\BuilderInterface;
12
use Greenter\Model\DocumentInterface;
13
use Greenter\Model\Response\BaseResult;
14
use Greenter\Services\SenderInterface;
15
use Greenter\XMLSecLibs\Sunat\SignedXml;
16
17
/**
18
 * Class FeFactory.
19
 */
20
class FeFactory implements FactoryInterface
21
{
22
    /**
23
     * @var SignedXml
24
     */
25
    private $signer;
26
27
    /**
28
     * Sender service.
29
     *
30
     * @var SenderInterface
31
     */
32
    private $sender;
33
34
    /**
35
     * Ultimo xml generado.
36
     *
37
     * @var string
38
     */
39
    private $lastXml;
40
41
    /**
42
     * Xml Builder.
43
     *
44
     * @var BuilderInterface
45
     */
46
    private $builder;
47
48
    /**
49
     * Get document builder.
50
     *
51
     * @return BuilderInterface
52
     */
53
    public function getBuilder()
54
    {
55
        return $this->builder;
56
    }
57
58
    /**
59
     * Get sender service.
60
     *
61
     * @return SenderInterface
62
     */
63
    public function getSender()
64
    {
65
        return $this->sender;
66
    }
67
68
    /**
69
     * Set sender service.
70
     *
71
     * @param SenderInterface $sender
72
     *
73
     * @return FeFactory
74
     */
75 4
    public function setSender($sender)
76
    {
77 4
        $this->sender = $sender;
78
79 4
        return $this;
80
    }
81
82
    /**
83
     * Set document builder.
84
     *
85
     * @param BuilderInterface $builder
86
     *
87
     * @return FeFactory
88
     */
89 4
    public function setBuilder($builder)
90
    {
91 4
        $this->builder = $builder;
92
93 4
        return $this;
94
    }
95
96
    /**
97
     * @return SignedXml
98
     */
99
    public function getSigner()
100
    {
101
        return $this->signer;
102
    }
103
104
    /**
105
     * @param SignedXml $signer
106
     *
107
     * @return FeFactory
108
     */
109 4
    public function setSigner($signer)
110
    {
111 4
        $this->signer = $signer;
112
113 4
        return $this;
114
    }
115
116
    /**
117
     * Build and send document.
118
     *
119
     * @param DocumentInterface $document
120
     *
121
     * @return BaseResult
122
     */
123 4
    public function send(DocumentInterface $document)
124
    {
125 4
        $this->lastXml = $this->getXmlSigned($document);
126
127 4
        return $this->sender->send($document->getName(), $this->lastXml);
128
    }
129
    
130
    // by thefantas
131
    public function sendForce(DocumentInterface $document, $dir_xml)
132
    {
133
        return $this->sender->send($document->getName(), $dir_xml);
134
    }
135
136
    // by thefantas
137
    public function genXML(DocumentInterface $document)
138
    {
139
        $this->lastXml = $this->getXmmlSigned($document);
0 ignored issues
show
Bug introduced by
The method getXmmlSigned() does not exist on Greenter\Factory\FeFactory. Did you maybe mean getXmlSigned()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
140
    }
141
    
142
    /**
143
     * Get Last XML Signed.
144
     *
145
     * @return string
146
     */
147
    public function getLastXml()
148
    {
149
        return $this->lastXml;
150
    }
151
152
    /**
153
     * @param DocumentInterface $document
154
     *
155
     * @return string
156
     */
157 4
    public function getXmlSigned(DocumentInterface $document)
158
    {
159 4
        $xml = $this->builder->build($document);
160
161 4
        return $this->signer->signXml($xml);
162
    }
163
}
164