Passed
Push — master ( a90170...48fa57 )
by Joe Nilson
03:30
created

EditProveedor   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 38
dl 0
loc 51
rs 10
c 1
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execPreviousAction() 0 28 4
A createViews() 0 16 3
1
<?php
2
/**
3
 * Copyright (C) 2020 Joe Nilson <joenilson at gmail dot com>
4
 * 
5
 * fsRepublicaDominicana is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Lesser General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 * 
10
 * fsRepublicaDominicana 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
13
 * GNU Lesser General Public License for more details.
14
 * 
15
 * You should have received a copy of the GNU Lesser General Public License
16
 * along with fsRepublicaDominicana. If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace FacturaScripts\Plugins\fsRepublicaDominicana\Extension\Controller;
20
21
use Closure;
22
use FacturaScripts\Dinamic\Lib\AssetManager;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Lib\AssetManager 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...
23
use FacturaScripts\Dinamic\Model\NCFTipoPago;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Model\NCFTipoPago 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...
24
use FacturaScripts\Plugins\fsRepublicaDominicana\Lib\WebserviceDgii;
25
26
class EditProveedor
27
{
28
29
    public function createViews(): Closure
30
    {
31
        return function () {
32
            AssetManager::add('js', \FS_ROUTE . '/Plugins/fsRepublicaDominicana/Assets/JS/CommonModals.js');
0 ignored issues
show
Bug introduced by
The constant FS_ROUTE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
33
            AssetManager::add('js', \FS_ROUTE . '/Plugins/fsRepublicaDominicana/Assets/JS/CommonDomFunctions.js');
34
            AssetManager::add('js', \FS_ROUTE . '/Plugins/fsRepublicaDominicana/Assets/JS/BusquedaRNCDGII.js');
35
            $ncfTipoPago = new NCFTipoPago();
36
            $ncfTiposPago = $ncfTipoPago->findAllByTipopago('02');
37
            $customValuesNTP = [];
38
            $customValuesNTP[] = ['value'=>'', 'title'=>'-----------'];
39
            foreach ($ncfTiposPago as $tipopago) {
40
                $customValuesNTP[] = ['value'=>$tipopago->codigo, 'title'=>$tipopago->descripcion];
41
            }
42
            $columnToModifyNTP = $this->views['EditProveedor']->columnForName('ncf-payment-types');
0 ignored issues
show
Bug Best Practice introduced by
The property views does not exist on FacturaScripts\Plugins\f...ontroller\EditProveedor. Did you maybe forget to declare it?
Loading history...
43
            if ($columnToModifyNTP) {
44
                $columnToModifyNTP->widget->setValuesFromArray($customValuesNTP);
45
            }
46
        };
47
    }
48
49
    public function execPreviousAction()
50
    {
51
        return function ($action) {
52
            switch ($action) {
53
                case 'busca_rnc':
54
                    $this->setTemplate(false);
0 ignored issues
show
Bug introduced by
The method setTemplate() does not exist on FacturaScripts\Plugins\f...ontroller\EditProveedor. ( Ignorable by Annotation )

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

54
                    $this->/** @scrutinizer ignore-call */ 
55
                           setTemplate(false);

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...
55
                    $consulta = new WebserviceDgii();
56
                    $rncNotFound = self::toolBox()->i18n()->trans('rnc-not-found');
0 ignored issues
show
Bug introduced by
The method toolBox() does not exist on FacturaScripts\Plugins\f...ontroller\EditProveedor. ( Ignorable by Annotation )

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

56
                    $rncNotFound = self::/** @scrutinizer ignore-call */ toolBox()->i18n()->trans('rnc-not-found');

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...
57
                    $respuesta = $consulta->getExternalAPI($_REQUEST['cifnif']);
58
                    $registros = $respuesta->totalResults;
59
                    if ($registros !== 0) {
60
                        $resultado = $respuesta->entry[0];
61
                        if ($resultado) {
62
                            $arrayResultado = [];
63
                            $arrayResultado["RGE_RUC"] = $resultado->rnc;
64
                            $arrayResultado["RGE_NOMBRE"] = $resultado->nombre;
65
                            $arrayResultado["NOMBRE_COMERCIAL"] = $resultado->razonsocial;
66
                            $arrayResultado["ESTATUS"] = $resultado->estado;
67
                            echo json_encode($arrayResultado);
68
                        } else {
69
                            echo '{"RGE_ERROR": "true", "message": "'.$rncNotFound.'"}';
70
                        }
71
                    } else {
72
                        echo '{"RGE_ERROR": "true", "message": "'.$rncNotFound.'"}';
73
                    }
74
                    break;
75
                default:
76
                    break;
77
            }
78
        };
79
    }
80
}
81