Passed
Push — GENERAL_BUG_REVIEW_240911 ( 3362b2...8cbbee )
by Rafael
49:13
created

ModeleProductCode::getToolTip()   F

Complexity

Conditions 18
Paths 1600

Size

Total Lines 60
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 18
eloc 48
nc 1600
nop 3
dl 0
loc 60
rs 0.7
c 1
b 0
f 0

How to fix   Long Method    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) 2003-2005  Rodolphe Quiedeville        <[email protected]>
4
 * Copyright (C) 2004-2010  Laurent Destailleur         <[email protected]>
5
 * Copyright (C) 2004       Eric Seigne                 <[email protected]>
6
 * Copyright (C) 2005-2012  Regis Houssin               <[email protected]>
7
 * Copyright (C) 2024		Frédéric France			    <[email protected]>
8
 * Copyright (C) 2024		MDW							<[email protected]>
9
 * Copyright (C) 2024       Rafael San José             <[email protected]>
10
 *
11
 * This program is free software; you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation; either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23
 * or see https://www.gnu.org/
24
 */
25
26
namespace Dolibarr\Code\Product\Classes;
27
28
use Dolibarr\Code\Core\Classes\CommonNumRefGenerator;
29
use DoliDB;
30
31
/**
32
 *  \file       htdocs/core/modules/product/modules_product.class.php
33
 *  \ingroup    contract
34
 *  \brief      File with parent class for generating products to PDF and File of class to manage product numbering
35
 */
36
37
/**
38
 * Class template for classes of numbering product
39
 */
40
abstract class ModeleProductCode extends CommonNumRefGenerator
41
{
42
    /**
43
     *  Renvoi la liste des modeles de numérotation
44
     *
45
     * @param DoliDB $dbs Database handler
46
     * @param integer $maxfilenamelength Max length of value to show
47
     * @return array|int                   List of numbers
48
     */
49
    public static function liste_modeles($dbs, $maxfilenamelength = 0)
50
    {
51
        // phpcs:enable
52
        $list = array();
53
        $sql = "";
54
55
        $resql = $dbs->query($sql);
56
        if ($resql) {
57
            $num = $dbs->num_rows($resql);
58
            $i = 0;
59
            while ($i < $num) {
60
                $row = $dbs->fetch_row($resql);
61
                $list[$row[0]] = $row[1];
62
                $i++;
63
            }
64
        } else {
65
            return -1;
66
        }
67
        return $list;
68
    }
69
70
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
71
72
    /**
73
     *  Return description of module parameters
74
     *
75
     * @param Translate $langs Output language
76
     * @param Product $product Product object
77
     * @param int $type -1=Nothing, 0=Customer, 1=Supplier
78
     * @return string                  HTML translated description
79
     */
80
    public function getToolTip($langs, $product, $type)
81
    {
82
        global $conf;
83
84
        $langs->loadLangs(array("admin", "companies"));
85
86
        $strikestart = '';
87
        $strikeend = '';
88
        if (getDolGlobalString('MAIN_COMPANY_CODE_ALWAYS_REQUIRED') && !empty($this->code_null)) {
89
            $strikestart = '<strike>';
90
            $strikeend = '</strike> ' . yn(1, 1, 2) . ' (' . $langs->trans("ForcedToByAModule", $langs->transnoentities("yes")) . ')';
91
        }
92
        $s = '';
93
        if ($type == -1) {
94
            $s .= $langs->trans("Name") . ': <b>' . $this->getName($langs) . '</b><br>';
95
            $s .= $langs->trans("Version") . ': <b>' . $this->getVersion() . '</b><br>';
96
        } elseif ($type == 0) {
97
            $s .= $langs->trans("ProductCodeDesc") . '<br>';
98
        } elseif ($type == 1) {
99
            $s .= $langs->trans("ServiceCodeDesc") . '<br>';
100
        }
101
        if ($type != -1) {
102
            $s .= $langs->trans("ValidityControledByModule") . ': <b>' . $this->getName($langs) . '</b><br>';
103
        }
104
        $s .= '<br>';
105
        $s .= '<u>' . $langs->trans("ThisIsModuleRules") . ':</u><br>';
106
        if ($type == 0) {
107
            $s .= $langs->trans("RequiredIfProduct") . ': ' . $strikestart;
108
            $s .= yn(!$this->code_null, 1, 2) . $strikeend;
109
            $s .= '<br>';
110
        } elseif ($type == 1) {
111
            $s .= $langs->trans("RequiredIfService") . ': ' . $strikestart;
112
            $s .= yn(!$this->code_null, 1, 2) . $strikeend;
113
            $s .= '<br>';
114
        } elseif ($type == -1) {
115
            $s .= $langs->trans("Required") . ': ' . $strikestart;
116
            $s .= yn(!$this->code_null, 1, 2) . $strikeend;
117
            $s .= '<br>';
118
        }
119
        $s .= $langs->trans("CanBeModifiedIfOk") . ': ';
120
        $s .= yn($this->code_modifiable, 1, 2);
121
        $s .= '<br>';
122
        $s .= $langs->trans("CanBeModifiedIfKo") . ': ' . yn($this->code_modifiable_invalide, 1, 2) . '<br>';
123
        $s .= $langs->trans("AutomaticCode") . ': ' . yn($this->code_auto, 1, 2) . '<br>';
124
        $s .= '<br>';
125
        if ($type == 0 || $type == -1) {
126
            $nextval = $this->getNextValue($product, 0);
127
            if (empty($nextval)) {
128
                $nextval = $langs->trans("Undefined");
129
            }
130
            $s .= $langs->trans("NextValue") . ($type == -1 ? ' (' . $langs->trans("Product") . ')' : '') . ': <b>' . $nextval . '</b><br>';
131
        }
132
        if ($type == 1 || $type == -1) {
133
            $nextval = $this->getNextValue($product, 1);
134
            if (empty($nextval)) {
135
                $nextval = $langs->trans("Undefined");
136
            }
137
            $s .= $langs->trans("NextValue") . ($type == -1 ? ' (' . $langs->trans("Service") . ')' : '') . ': <b>' . $nextval . '</b>';
138
        }
139
        return $s;
140
    }
141
142
    /**
143
     *  Return next value available
144
     *
145
     * @param Product|string $objproduct Object product
146
     * @param int $type Type
147
     * @return string                      Value
148
     */
149
    public function getNextValue($objproduct = '', $type = -1)
150
    {
151
        global $langs;
152
        return $langs->trans("Function_getNextValue_InModuleNotWorking");
153
    }
154
155
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
156
157
    /**
158
     *   Check if mask/numbering use prefix
159
     *
160
     * @return    int     0=no, 1=yes
161
     */
162
    public function verif_prefixIsUsed()
163
    {
164
        // phpcs:enable
165
        return 0;
166
    }
167
}
168