Passed
Push — master ( 8cc5c3...c2f62f )
by Giancarlos
03:39
created

FeFactory::getSummaryResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 7
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
crap 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\Model\Company\Company;
12
use Greenter\Model\Response\BillResult;
13
use Greenter\Model\Response\StatusResult;
14
use Greenter\Model\Response\SummaryResult;
15
use Greenter\Model\Sale\Note;
16
use Greenter\Model\Summary\Summary;
17
use Greenter\Model\Voided\Voided;
18
use Greenter\Xml\Builder\FeBuilderInteface;
19
use Greenter\Xml\Builder\FeBuilder;
20
use Greenter\Model\Sale\Invoice;
21
22
/**
23
 * Class FeFactory
24
 * @package Greenter\Factory
25
 */
26
class FeFactory extends BaseFactory implements FeFactoryInterface
27
{
28
    /**
29
     * @var FeBuilderInteface
30
     */
31
    private $builder;
32
33
    /**
34
     * FeFactory constructor.
35
     */
36 34
    public function __construct()
37
    {
38 34
        parent::__construct();
39 34
        $this->builder = new FeBuilder();
40 34
    }
41
42
    /**
43
     * @param Invoice $invoice
44
     * @return BillResult
45
     */
46 8
    public function sendInvoice(Invoice $invoice)
47
    {
48 8
        $xml = $this->builder->buildInvoice($invoice);
49 6
        $filename = $invoice->getFilename($this->company->getRuc());
50
51 6
        return $this->getBillResult($xml, $filename);
52
    }
53
54
    /**
55
     * Envia una Nota de Credito o Debito.
56
     *
57
     * @param Note $note
58
     * @return BillResult
59
     */
60 12
    public function sendNote(Note $note)
61
    {
62 12
        $xml = $this->builder->buildNote($note);
63 8
        $filename = $note->getFilename($this->company->getRuc());
64
65 8
        return $this->getBillResult($xml, $filename);
66
    }
67
68
    /**
69
     * Envia un resumen diario de Boletas.
70
     *
71
     * @param Summary $summary
72
     * @return SummaryResult
73
     */
74 6
    public function sendResumen(Summary $summary)
75
    {
76 6
        $xml = $this->builder->buildSummary($summary);
77 4
        $filename = $summary->getFileName($this->company->getRuc());
78
79 4
        return $this->getSummaryResult($xml, $filename);
80
    }
81
82
    /**
83
     * Envia una comunicacion de Baja.
84
     *
85
     * @param Voided $voided
86
     * @return SummaryResult
87
     */
88 6
    public function sendBaja(Voided $voided)
89
    {
90 6
        $xml = $this->builder->buildVoided($voided);
91 4
        $filename = $voided->getFileName($this->company->getRuc());
92
93 4
        return $this->getSummaryResult($xml, $filename);
94
    }
95
96
    /**
97
     * Get Status by Ticket.
98
     *
99
     * @param string $ticket
100
     * @return StatusResult
101
     */
102 2
    public function getStatus($ticket)
103
    {
104 2
        return $this->sender->getStatus($ticket);
105
    }
106
107
    /**
108
     * @param $company
109
     * @return $this
110
     */
111 34
    public function setCompany(Company $company)
112
    {
113 34
        $this->company = $company;
114 34
        $this->builder->setCompany($company);
115
116 34
        return $this;
117
    }
118
119
    /**
120
     * @param array $params
121
     */
122 34 View Code Duplication
    public function setParameters($params)
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...
123
    {
124 34
        $this->setWsParams($params['ws']);
125
126 34
        if (isset($params['xml'])) {
127 34
            $this->builder->setParameters($params['xml']);
128 34
        }
129
130 34
        if (isset($params['cert'])) {
131 34
            $this->signer->setCertificate($params['cert']);
132 34
        }
133 34
    }
134
135
    /**
136
     * Get Last XML Signed.
137
     *
138
     * @return string
139
     */
140 10
    public function getLastXml()
141
    {
142 10
        return $this->lastXml;
143
    }
144
}