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

See   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 216
Duplicated Lines 8.33 %

Coupling/Cohesion

Components 2
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 17
lcom 2
cbo 6
dl 18
loc 216
ccs 0
cts 72
cp 0
rs 10
c 0
b 0
f 0

15 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 1
A setBuilderOptions() 0 4 1
A setCachePath() 0 4 1
A setCertificate() 0 4 1
A setCredentials() 0 4 1
A setService() 0 4 1
A setCodeProvider() 0 4 1
A getXmlSigned() 0 8 1
A send() 9 9 1
A sendForce() 9 9 1
A genXML() 0 8 1
A getStatus() 0 7 1
A getFactory() 0 4 1
A getBuilder() 0 6 1
A getSender() 0 10 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Administrador
5
 * Date: 16/10/2017
6
 * Time: 04:23 PM.
7
 */
8
9
namespace Greenter;
10
11
use Greenter\Builder\BuilderInterface;
12
use Greenter\Factory\FeFactory;
13
use Greenter\Model\DocumentInterface;
14
use Greenter\Model\Summary\Summary;
15
use Greenter\Model\Voided\Reversion;
16
use Greenter\Model\Voided\Voided;
17
use Greenter\Services\SenderInterface;
18
use Greenter\Validator\ErrorCodeProviderInterface;
19
use Greenter\Ws\Services\BillSender;
20
use Greenter\Ws\Services\ExtService;
21
use Greenter\Ws\Services\SoapClient;
22
use Greenter\Ws\Services\SummarySender;
23
use Greenter\XMLSecLibs\Sunat\SignedXml;
24
25
/**
26
 * Sistema de Emision del Contribuyente.
27
 *
28
 * Class See
29
 */
30
class See
31
{
32
    /**
33
     * @var FeFactory
34
     */
35
    private $factory;
36
37
    /**
38
     * @var SoapClient
39
     */
40
    private $wsClient;
41
42
    /**
43
     * @var array
44
     */
45
    private $builders;
46
47
    /**
48
     * @var array
49
     */
50
    private $summarys;
51
52
    /**
53
     * @var SignedXml
54
     */
55
    private $signer;
56
57
    /**
58
     * @var ErrorCodeProviderInterface
59
     */
60
    private $codeProvider;
61
62
    /**
63
     * Twig Render Options.
64
     *
65
     * @var array
66
     */
67
    private $options = ['autoescape' => false];
68
69
    /**
70
     * See constructor.
71
     */
72
    public function __construct()
73
    {
74
        $this->factory = new FeFactory();
75
        $this->wsClient = new SoapClient();
76
        $this->signer = new SignedXml();
77
        $this->builders = [
78
            Model\Sale\Invoice::class => Xml\Builder\InvoiceBuilder::class,
79
            Model\Sale\Note::class => Xml\Builder\NoteBuilder::class,
80
            Model\Summary\Summary::class => Xml\Builder\SummaryBuilder::class,
81
            Model\Voided\Voided::class => Xml\Builder\VoidedBuilder::class,
82
            Model\Despatch\Despatch::class => Xml\Builder\DespatchBuilder::class,
83
            Model\Retention\Retention::class => Xml\Builder\RetentionBuilder::class,
84
            Model\Perception\Perception::class => Xml\Builder\PerceptionBuilder::class,
85
            Model\Voided\Reversion::class => Xml\Builder\VoidedBuilder::class,
86
        ];
87
        $this->summarys = [Summary::class, Summary::class, Voided::class, Reversion::class];
88
        $this->factory->setSigner($this->signer);
89
    }
90
91
    /**
92
     * Set Xml Builder Options.
93
     *
94
     * @param array $options
95
     */
96
    public function setBuilderOptions(array $options)
97
    {
98
        $this->options = array_merge($this->options, $options);
99
    }
100
101
    /**
102
     * @param string $directory
103
     */
104
    public function setCachePath($directory)
105
    {
106
        $this->options['cache'] = $directory;
107
    }
108
109
    /**
110
     * @param string $certificate
111
     */
112
    public function setCertificate($certificate)
113
    {
114
        $this->signer->setCertificate($certificate);
115
    }
116
117
    /**
118
     * @param string $user
119
     * @param string $password
120
     */
121
    public function setCredentials($user, $password)
122
    {
123
        $this->wsClient->setCredentials($user, $password);
124
    }
125
126
    /**
127
     * @param string $service
128
     */
129
    public function setService($service)
130
    {
131
        $this->wsClient->setService($service);
132
    }
133
134
    /**
135
     * Set error code provider.
136
     *
137
     * @param ErrorCodeProviderInterface $codeProvider
138
     */
139
    public function setCodeProvider($codeProvider)
140
    {
141
        $this->codeProvider = $codeProvider;
142
    }
143
144
    /**
145
     * Get signed xml from document.
146
     *
147
     * @param DocumentInterface $document
148
     *
149
     * @return string
150
     */
151
    public function getXmlSigned(DocumentInterface $document)
152
    {
153
        $classDoc = get_class($document);
154
155
        return $this->factory
156
            ->setBuilder($this->getBuilder($classDoc))
157
            ->getXmlSigned($document);
158
    }
159
160
    /**
161
     * Envia documento.
162
     *
163
     * @param DocumentInterface $document
164
     *
165
     * @return Model\Response\BaseResult
166
     */
167 View Code Duplication
    public function send(DocumentInterface $document)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
168
    {
169
        $classDoc = get_class($document);
170
        $this->factory
171
            ->setBuilder($this->getBuilder($classDoc))
172
            ->setSender($this->getSender($classDoc));
173
174
        return $this->factory->send($document);
175
    }
176
    
177
	// Solicitar CDR desde un XML ya generado. by thefantas
178 View Code Duplication
    public function sendForce(DocumentInterface $document, $dir_xml)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
179
    {
180
        $classDoc = get_class($document);
181
        $this->factory
182
            ->setBuilder($this->getBuilder($classDoc))
183
            ->setSender($this->getSender($classDoc));
184
185
        return $this->factory->send($document, $dir_xml);
0 ignored issues
show
Unused Code introduced by
The call to FeFactory::send() has too many arguments starting with $dir_xml.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
186
    }
187
	// Generar solo XML. by thefantas
188
    public function genXML(DocumentInterface $document)
189
    {
190
        $classDoc = get_class($document);
191
        $this->factory
192
            ->setBuilder($this->getBuilder($classDoc));
193
194
        return $this->factory->genXML($document);
195
    }
196
197
    /**
198
     * @param $ticket
199
     *
200
     * @return Model\Response\StatusResult
201
     */
202
    public function getStatus($ticket)
203
    {
204
        $sender = new ExtService();
205
        $sender->setClient($this->wsClient);
206
207
        return $sender->getStatus($ticket);
208
    }
209
210
    /**
211
     * @return FeFactory
212
     */
213
    public function getFactory()
214
    {
215
        return $this->factory;
216
    }
217
218
    /**
219
     * @param string $class
220
     *
221
     * @return BuilderInterface
222
     */
223
    private function getBuilder($class)
224
    {
225
        $builder = $this->builders[$class];
226
227
        return new $builder($this->options);
228
    }
229
230
    /**
231
     * @param string $class
232
     *
233
     * @return SenderInterface
234
     */
235
    private function getSender($class)
236
    {
237
        $sender = in_array($class, $this->summarys) ? new SummarySender() : new BillSender();
238
        $sender->setClient($this->wsClient);
239
        if ($this->codeProvider) {
240
            $sender->setCodeProvider($this->codeProvider);
241
        }
242
243
        return $sender;
244
    }
245
}
246