Passed
Branch master (a43e58)
by Giancarlos
04:04
created

BaseFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 84
Duplicated Lines 16.67 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 92%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 14
loc 84
ccs 23
cts 25
cp 0.92
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A setWsParams() 0 10 3
A getBillResult() 7 7 1
A getSummaryResult() 7 7 1
A getXmmlSigned() 0 4 1

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