Passed
Push — master ( b8d623...b21d4a )
by Joe Nilson
01:59
created

FacturaCliente::saveBefore()   C

Complexity

Conditions 12
Paths 1

Size

Total Lines 41
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 33
nc 1
nop 0
dl 0
loc 41
rs 6.9666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Copyright (C) 2020 joenilson.
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 3 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA 02110-1301  USA
19
 */
20
21
namespace FacturaScripts\Plugins\fsRepublicaDominicana\Extension\Model;
22
23
use Closure;
24
use FacturaScripts\Core\Base\DataBase\DataBaseWhere;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Base\DataBase\DataBaseWhere was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use FacturaScripts\Dinamic\Model\NCFRango;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Model\NCFRango was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
use FacturaScripts\Dinamic\Model\NCFTipoMovimiento;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Model\NCFTipoMovimiento was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
use FacturaScripts\Dinamic\Model\Cliente;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, FacturaScripts\Plugins\f...Extension\Model\Cliente. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
Bug introduced by
The type FacturaScripts\Dinamic\Model\Cliente was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
use FacturaScripts\Core\App\AppSettings;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\App\AppSettings was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
30
/**
31
 * Description of FacturaCliente
32
 *
33
 * @author joenilson
34
 */
35
class FacturaCliente
36
{
37
    /**
38
     * @var date
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Plugins\f...na\Extension\Model\date was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
     */
40
    public $ncffechavencimiento;
41
    /**
42
     * @var string
43
     */
44
    public $tipocomprobante;
45
    /**
46
     *
47
     * @var string
48
     */
49
    public $ncftipopago;
50
    /**
51
     *
52
     * @var string
53
     */
54
    public $ncftipomovimiento;
55
    /**
56
     *
57
     * @var string
58
     */
59
    public $ncftipoanulacion;
60
61
    /**
62
     * @var string
63
     */
64
    public $facturarectnumero2;
65
66
    public function saveBefore(): Closure
67
    {
68
        return function () {
69
70
            $ncfrango = new NCFRango();
71
            $cliente = new Cliente();
72
            $appSettins = new AppSettings;
73
            $actualCliente = $cliente->get($this->codcliente);
0 ignored issues
show
Bug Best Practice introduced by
The property codcliente does not exist on FacturaScripts\Plugins\f...on\Model\FacturaCliente. Did you maybe forget to declare it?
Loading history...
74
            $actualCliente->idempresa = $appSettins::get('default', 'idempresa');
75
            $this->tipocomprobante = $this->tipocomprobante ?? $actualCliente->tipocomprobante;
76
            $this->tipocomprobante = $_REQUEST['tipocomprobanter'] ?? $this->tipocomprobante;
77
            $this->numeroncf = (isset($_REQUEST['tipocomprobanter'])) ? '' : $this->numeroncf;
0 ignored issues
show
Bug Best Practice introduced by
The property numeroncf does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
78
            if ($this->tipocomprobante !== '' && \in_array($this->numeroncf, ['', null], true)) {
79
                $tipocomprobante = "02";
80
                if (($this->tipocomprobante !== null) === true) {
81
                    $tipocomprobante = $this->tipocomprobante;
82
                } elseif (($this->tipocomprobante === null) === true) {
83
                    $tipocomprobante = $actualCliente->tipocomprobante;
84
                }
85
86
                $ncfRangoToUse = $ncfrango->getByTipoComprobante($actualCliente->idempresa, $tipocomprobante);
87
                if (!$ncfRangoToUse) {
88
                    $this->toolBox()->i18nLog()->error("no-ncf-range-for-$tipocomprobante");
0 ignored issues
show
Bug introduced by
The method toolBox() does not exist on FacturaScripts\Plugins\f...on\Model\FacturaCliente. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

88
                    $this->/** @scrutinizer ignore-call */ 
89
                           toolBox()->i18nLog()->error("no-ncf-range-for-$tipocomprobante");

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
89
                    return false;
90
                }
91
                $ncf = $ncfRangoToUse->generateNCF();
92
                $this->numeroncf = $ncf;
93
                $this->ncffechavencimiento = $ncfRangoToUse->fechavencimiento;
94
                $this->tipocomprobante = $ncfRangoToUse->tipocomprobante;
95
                $ncfRangoToUse->correlativo++;
96
                $ncfRangoToUse->save();
97
                if (($this->tipocomprobante === '03' || $this->tipocomprobante === '04') === true) {
98
                    $this->ncftipoanulacion = isset($_REQUEST['ncftipoanulacionr'])
99
                        ? $_REQUEST['ncftipoanulacionr']
100
                        : $this->ncftipoanulacion;
101
                    $this->ncffechavencimiento = isset($_REQUEST['ncffechavencimientor'])
102
                        ? $_REQUEST['ncffechavencimientor']
103
                        : $this->ncffechavencimiento;
104
                }
105
            }
106
            $this->ncffechavencimiento = ($this->ncffechavencimiento == '') ? null : $this->ncffechavencimiento;
0 ignored issues
show
introduced by
The condition $this->ncffechavencimiento == '' is always false.
Loading history...
107
        };
108
    }
109
110
    public function all(): Closure
111
    {
112
        return function () {
113
            $this->facturarectnumero2 = '';
114
            if ($this->idfacturarect !== '') {
0 ignored issues
show
Bug Best Practice introduced by
The property idfacturarect does not exist on FacturaScripts\Plugins\f...on\Model\FacturaCliente. Did you maybe forget to declare it?
Loading history...
115
                $facturaRectificativa = $this->get($this->idfacturarect);
0 ignored issues
show
Bug introduced by
The method get() does not exist on FacturaScripts\Plugins\f...on\Model\FacturaCliente. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

115
                /** @scrutinizer ignore-call */ 
116
                $facturaRectificativa = $this->get($this->idfacturarect);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
116
                $this->loadFromData(['facturarectnumero2' => 'SI' ]);
0 ignored issues
show
Bug introduced by
The method loadFromData() does not exist on FacturaScripts\Plugins\f...on\Model\FacturaCliente. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

116
                $this->/** @scrutinizer ignore-call */ 
117
                       loadFromData(['facturarectnumero2' => 'SI' ]);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
117
                $this->facturarectnumero2 = $facturaRectificativa->numero2;
118
            } else {
119
                $this->loadFromData(['facturarectnumero2' => 'NO HAY']);
120
            }
121
            return $this;
122
        };
123
    }
124
}
125