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

BaseFactory::getXmmlSigned()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Giansalex
5
 * Date: 12/08/2017
6
 * Time: 18:06
7
 */
8
9
namespace Greenter\Factory;
10
11
use Greenter\Model\Company\Company;
12
use Greenter\Model\Response\BillResult;
13
use Greenter\Model\Response\SummaryResult;
14
use Greenter\Security\SignedXml;
15
use Greenter\Ws\Services\FeSunat;
16
use Greenter\Ws\Services\WsSunatInterface;
17
use Greenter\Zip\ZipFactory;
18
19
/**
20
 * Class BaseFactory
21
 * @package Greenter\Factory
22
 */
23
class BaseFactory
24
{
25
    /**
26
     * @var SignedXml
27
     */
28
    protected $signer;
29
30
    /**
31
     * @var ZipFactory
32
     */
33
    protected $zipper;
34
35
    /**
36
     * @var WsSunatInterface
37
     */
38
    protected $sender;
39
40
    /**
41
     * @var Company
42
     */
43
    protected $company;
44
45
    /**
46
     * Ultimo xml generado.
47
     *
48
     * @var string
49
     */
50
    protected $lastXml;
51
52
    /**
53
     * BaseFactory constructor.
54
     */
55 54
    public function __construct()
56
    {
57 54
        $this->signer = new SignedXml();
58 54
        $this->sender = new FeSunat();
59 54
        $this->zipper = new ZipFactory();
60 54
        $this->sender->setUrlWsdl(__DIR__.'/../Resources/wsdl/billService.wsdl');
61 54
    }
62
63
    /**
64
     * @param array $ws
65
     */
66 54
    protected function setWsParams($ws)
67
    {
68 54
        $this->sender->setCredentials($ws['user'], $ws['pass']);
69 54
        if (isset($ws['service'])) {
70 54
            $this->sender->setService($ws['service']);
71 54
        }
72 54
        if (isset($ws['wsdl'])) {
73
            $this->sender->setUrlWsdl($ws['wsdl']);
74
        }
75 54
    }
76
77
    /**
78
     * @param string $xml
79
     * @param string $filename
80
     * @return BillResult
81
     */
82 22 View Code Duplication
    protected function getBillResult($xml, $filename)
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...
83
    {
84 22
        $this->lastXml = $this->getXmmlSigned($xml);
85
86 22
        $zip = $this->zipper->compress("$filename.xml", $this->lastXml);
87 22
        return $this->sender->send("$filename.zip", $zip);
88
    }
89
90
    /**
91
     * @param string $xml
92
     * @param string $filename
93
     * @return SummaryResult
94
     */
95 10 View Code Duplication
    protected function getSummaryResult($xml, $filename)
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...
96
    {
97 10
        $this->lastXml = $this->getXmmlSigned($xml);
98
99 10
        $zip = $this->zipper->compress("$filename.xml", $this->lastXml);
100 10
        return $this->sender->sendSummary("$filename.zip", $zip);
101
    }
102
103
    /**
104
     * @param string $xml
105
     * @return string
106
     */
107 32
    private function getXmmlSigned($xml)
108
    {
109 32
        return $this->signer->sign($xml);
110
    }
111
}