Completed
Push — master ( a0585d...d359fd )
by Daniel
04:25
created

MySQLiAdvancedOutput::setViewModernDelete()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 3
eloc 11
nc 3
nop 2
1
<?php
2
3
/**
4
 *
5
 * The MIT License (MIT)
6
 *
7
 * Copyright (c) 2015 Daniel Popiniuc
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a copy
10
 * of this software and associated documentation files (the "Software"), to deal
11
 * in the Software without restriction, including without limitation the rights
12
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 * copies of the Software, and to permit persons to whom the Software is
14
 * furnished to do so, subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included in all
17
 * copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
 * SOFTWARE.
26
 *
27
 */
28
29
namespace danielgp\common_lib;
30
31
/**
32
 * usefull functions to get quick results
33
 *
34
 * @author Daniel Popiniuc
35
 */
36
trait MySQLiAdvancedOutput
37
{
38
39
    use DomComponentsByDanielGP;
40
41
    protected $advCache = null;
42
43
    /**
44
     * Establish Database and Table intended to work with
45
     * (in case the DB is ommited get the default one)
46
     *
47
     * @param string $tblSrc
48
     */
49
    private function establishDatabaseAndTable($tblSrc)
50
    {
51
        if (strpos($tblSrc, '.') === false) {
52
            if (!defined('MYSQL_DATABASE')) {
53
                define('MYSQL_DATABASE', 'information_schema');
54
            }
55
            return [$tblSrc, MYSQL_DATABASE];
56
        }
57
        return explode('.', str_replace('`', '', $tblSrc));
58
    }
59
60
    private function establishDefaultEnumSet($fldType)
61
    {
62
        $dfltArray = [
63
            'enum' => ['additional' => ['size' => 1], 'suffix' => ''],
64
            'set'  => ['additional' => ['size' => 5, 'multiselect'], 'suffix' => '[]'],
65
        ];
66
        return $dfltArray[$fldType];
67
    }
68
69
    private function getFieldCompletionType($details)
70
    {
71
        $inputFeatures = ['display' => '***', 'ftrs' => ['title' => 'Mandatory', 'class' => 'inputMandatory']];
72
        if ($details['IS_NULLABLE'] == 'YES') {
73
            $inputFeatures = ['display' => '~', 'ftrs' => ['title' => 'Optional', 'class' => 'inputOptional']];
74
        }
75
        return $this->setStringIntoTag($inputFeatures['display'], 'span', $inputFeatures['ftrs']);
76
    }
77
78
    /**
79
     * Returns the name of a field for displaying
80
     *
81
     * @param array $details
82
     * @return string
83
     */
84
    private function getFieldNameForDisplay($details)
85
    {
86
        $tableUniqueId = $details['TABLE_SCHEMA'] . '.' . $details['TABLE_NAME'];
87
        if ($details['COLUMN_COMMENT'] != '') {
88
            return $details['COLUMN_COMMENT'];
89
        } elseif (isset($this->advCache['tableStructureLocales'][$tableUniqueId][$details['COLUMN_NAME']])) {
90
            return $this->advCache['tableStructureLocales'][$tableUniqueId][$details['COLUMN_NAME']];
91
        }
92
        return $details['COLUMN_NAME'];
93
    }
94
95
    /**
96
     * Returns a Enum or Set field to use in form
97
     *
98
     * @param string $tblSrc
99
     * @param string $fldType
100
     * @param array $val
101
     * @param array $iar
102
     * @return string
103
     */
104
    private function getFieldOutputEnumSet($tblSrc, $fldType, $val, $iar = [])
105
    {
106
        $adnlThings = $this->establishDefaultEnumSet($fldType);
107
        if (array_key_exists('readonly', $val)) {
108
            return $this->getFieldOutputEnumSetReadOnly($val, $adnlThings);
109
        }
110
        $inAdtnl = $adnlThings['additional'];
111
        if ($iar !== []) {
112
            $inAdtnl = array_merge($inAdtnl, $iar);
113
        }
114
        $vlSlct    = explode(',', $this->getFieldValue($val));
115
        $slctOptns = $this->getSetOrEnum2Array($tblSrc, $val['COLUMN_NAME']);
116
        return $this->setArrayToSelect($slctOptns, $vlSlct, $val['COLUMN_NAME'] . $adnlThings['suffix'], $inAdtnl);
117
    }
118
119
    private function getFieldOutputEnumSetReadOnly($val, $adnlThings)
120
    {
121
        $inputFeatures = [
122
            'name'     => $val['COLUMN_NAME'] . $adnlThings['suffix'],
123
            'id'       => $val['COLUMN_NAME'],
124
            'readonly' => 'readonly',
125
            'class'    => 'input_readonly',
126
            'size'     => 50,
127
            'value'    => $this->getFieldValue($val),
128
        ];
129
        return $this->setStringIntoShortTag('input', $inputFeatures);
130
    }
131
132
    /**
133
     * Returns a Numeric field 2 use in a form
134
     *
135
     * @param string $tblSrc
136
     * @param array $value
137
     * @param array $features
0 ignored issues
show
Bug introduced by
There is no parameter named $features. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
138
     * @param array $iar
139
     * @return string
140
     */
141
    private function getFieldOutputNumeric($tblSrc, $value, $iar = [])
142
    {
143
        if ($value['EXTRA'] == 'auto_increment') {
144
            if ($this->getFieldValue($value) == '') {
145
                return $this->setStringIntoTag('auto-numar', 'span', [
146
                            'id'    => $value['COLUMN_NAME'],
147
                            'style' => 'font-style:italic;',
148
                ]);
149
            }
150
            $inAdtnl = [
151
                'type'  => 'hidden',
152
                'name'  => $value['COLUMN_NAME'],
153
                'id'    => $value['COLUMN_NAME'],
154
                'value' => $this->getFieldValue($value),
155
            ];
156
            if ($iar !== []) {
157
                $inAdtnl = array_merge($inAdtnl, $iar);
158
            }
159
            return $this->setStringIntoTag($this->getFieldValue($value), 'b')
160
                    . $this->setStringIntoShortTag('input', $inAdtnl);
161
        }
162
        $database = $this->advCache['workingDatabase'];
163
        $fkArray  = $this->getForeignKeysToArray($database, $tblSrc, $value['COLUMN_NAME']);
164
        if (is_null($fkArray)) {
165
            $fldNos  = $this->setFieldNumbers($value);
0 ignored issues
show
Bug introduced by
It seems like setFieldNumbers() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
166
            $inAdtnl = [
167
                'type'      => 'text',
168
                'name'      => $value['COLUMN_NAME'],
169
                'id'        => $value['COLUMN_NAME'],
170
                'value'     => $this->getFieldValue($value),
171
                'size'      => min(50, $fldNos['l']),
172
                'maxlength' => min(50, $fldNos['l'])
173
            ];
174
            if ($iar !== []) {
175
                $inAdtnl = array_merge($inAdtnl, $iar);
176
            }
177
            return $this->setStringIntoShortTag('input', $inAdtnl);
178
        }
179
        $query         = $this->sQueryGenericSelectKeyValue([
0 ignored issues
show
Bug introduced by
It seems like sQueryGenericSelectKeyValue() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
180
            $fkArray[$value['COLUMN_NAME']][1],
181
            $fkArray[$value['COLUMN_NAME']][2],
182
            $fkArray[$value['COLUMN_NAME']][0]
183
        ]);
184
        $selectOptions = $this->setMySQLquery2Server($query, 'array_key_value')['result'];
0 ignored issues
show
Bug introduced by
It seems like setMySQLquery2Server() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
185
        $selectValue   = $this->getFieldValue($value);
186
        $inAdtnl       = ['size' => 1];
187
        if ($value['IS_NULLABLE'] == 'YES') {
188
            $inAdtnl = array_merge($inAdtnl, ['include_null']);
189
        }
190
        if ($iar !== []) {
191
            $inAdtnl = array_merge($inAdtnl, $iar);
192
        }
193
        return $this->setArrayToSelect($selectOptions, $selectValue, $value['COLUMN_NAME'], $inAdtnl);
194
    }
195
196
    /**
197
     * Returns a Char field 2 use in a form
198
     *
199
     * @param string $tbl
200
     * @param string $fieldType
201
     * @param array $value
202
     * @param array $features
0 ignored issues
show
Bug introduced by
There is no parameter named $features. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
203
     * @param array $iar
204
     * @return string
205
     */
206
    private function getFieldOutputText($tbl, $fieldType, $value, $iar = [])
207
    {
208
        if (!in_array($fieldType, ['char', 'tinytext', 'varchar'])) {
209
            return '';
210
        }
211
        $database = $this->advCache['workingDatabase'];
212
        if (strpos($tbl, '`.`')) {
213
            $database = substr($tbl, 0, strpos($tbl, '`.`'));
214
        }
215
        if (($tbl != 'user_rights') && ($value['COLUMN_NAME'] != 'eid')) {
216
            $foreignKeysArray = $this->getForeignKeysToArray($database, $tbl, $value['COLUMN_NAME']);
217
            if (is_null($foreignKeysArray)) {
218
                unset($foreignKeysArray);
219
            }
220
        }
221
        if (isset($foreignKeysArray)) {
222
            $query   = $this->storedQuery('generic_select_key_value', [
0 ignored issues
show
Bug introduced by
It seems like storedQuery() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
223
                $foreignKeysArray[$value['COLUMN_NAME']][1],
224
                $foreignKeysArray[$value['COLUMN_NAME']][2],
225
                $foreignKeysArray[$value['COLUMN_NAME']][0]
226
            ]);
227
            $inAdtnl = ['size' => 1];
228
            if ($value['IS_NULLABLE'] == 'YES') {
229
                $inAdtnl = array_merge($inAdtnl, ['include_null']);
230
            }
231
            if ($iar !== []) {
232
                $inAdtnl = array_merge($inAdtnl, $iar);
233
            }
234
            $slct = [
235
                'Options' => $this->setQuery2Server($query, 'array_key_value'),
0 ignored issues
show
Bug introduced by
It seems like setQuery2Server() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
236
                'Value'   => $this->getFieldValue($value),
237
            ];
238
            return $this->setArrayToSelect($slct['Options'], $slct['Value'], $value['COLUMN_NAME'], $inAdtnl);
239
        }
240
        $fldNos  = $this->setFieldNumbers($value);
0 ignored issues
show
Bug introduced by
It seems like setFieldNumbers() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
241
        $inAdtnl = [
242
            'type'      => ($value['COLUMN_NAME'] == 'password' ? 'password' : 'text'),
243
            'name'      => $value['COLUMN_NAME'],
244
            'id'        => $value['COLUMN_NAME'],
245
            'size'      => min(30, $fldNos['l']),
246
            'maxlength' => min(255, $fldNos['l']),
247
            'value'     => $this->getFieldValue($value),
248
        ];
249
        if ($iar !== []) {
250
            $inAdtnl = array_merge($inAdtnl, $iar);
251
        }
252
        return $this->setStringIntoShortTag('input', $inAdtnl);
253
    }
254
255
    /**
256
     * Returns a Text field 2 use in a form
257
     *
258
     * @param string $table_source
0 ignored issues
show
Bug introduced by
There is no parameter named $table_source. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
259
     * @param string $fieldType
260
     * @param array $value
261
     * @param array $features
0 ignored issues
show
Bug introduced by
There is no parameter named $features. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
262
     * @param array $iar
263
     * @return string
264
     */
265 View Code Duplication
    private function getFieldOutputTextLarge($fieldType, $value, $iar = [])
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...
266
    {
267
        if (!in_array($fieldType, ['blob', 'text'])) {
268
            return '';
269
        }
270
        $inAdtnl = [
271
            'name' => $value['COLUMN_NAME'],
272
            'id'   => $value['COLUMN_NAME'],
273
            'rows' => 4,
274
            'cols' => 55,
275
        ];
276
        if ($iar !== []) {
277
            $inAdtnl = array_merge($inAdtnl, $iar);
278
        }
279
        return $this->setStringIntoTag($this->getFieldValue($value), 'textarea', $inAdtnl);
280
    }
281
282
    /**
283
     * Returns a Time field 2 use in a form
284
     *
285
     * @param array $value
286
     * @param array $iar
287
     * @return string
288
     */
289 View Code Duplication
    private function getFieldOutputTime($value, $iar = [])
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...
290
    {
291
        $inAdtnl = [
292
            'type'      => 'text',
293
            'size'      => 9,
294
            'maxlength' => 9,
295
            'name'      => $value['COLUMN_NAME'],
296
            'id'        => $value['COLUMN_NAME'],
297
            'value'     => $this->getFieldValue($value),
298
        ];
299
        if ($iar !== []) {
300
            $inAdtnl = array_merge($inAdtnl, $iar);
301
        }
302
        return $this->setStringIntoShortTag('input', $inAdtnl);
303
    }
304
305
    /**
306
     * Returns a Timestamp field 2 use in a form
307
     *
308
     * @param array $value
309
     * @param array $iar
310
     * @return string
311
     */
312
    private function getFieldOutputTimestamp($value, $iar = [])
313
    {
314
        $inAdtnl = [
315
            'type'      => 'text',
316
            'size'      => 19,
317
            'maxlength' => 19,
318
            'name'      => $value['COLUMN_NAME'],
319
            'id'        => $value['COLUMN_NAME'],
320
            'value'     => $this->getFieldValue($value),
321
        ];
322
        if ($iar !== []) {
323
            $inAdtnl = array_merge($inAdtnl, $iar);
324
        }
325
        $input = $this->setStringIntoShortTag('input', $inAdtnl);
326
        if (!array_key_exists('readonly', $iar)) {
327
            $input .= $this->setCalendarControlWithTime($value['COLUMN_NAME']);
328
        }
329
        return $input;
330
    }
331
332
    /**
333
     * Returns a Year field 2 use in a form
334
     *
335
     * @param array $details
336
     * @param array $iar
337
     * @return string
338
     */
339
    private function getFieldOutputYear($details, $iar)
340
    {
341
        for ($c = 1901; $c <= 2155; $c++) {
342
            $listOfValues[$c] = $c;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$listOfValues was never initialized. Although not strictly required by PHP, it is generally a good practice to add $listOfValues = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
343
        }
344
        if ($iar == []) {
345
            $slDflt = $this->getFieldValue($details);
346
            return $this->setArrayToSelect($listOfValues, $slDflt, $details['COLUMN_NAME'], ['size' => 1]);
0 ignored issues
show
Bug introduced by
The variable $listOfValues does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
347
        }
348
        return $this->getFieldOutputText('varchar', $details, $iar);
0 ignored issues
show
Documentation introduced by
$details is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
349
    }
350
351
    /**
352
     * Returns given value for a field from $_REQUEST
353
     *
354
     * @param array $details
355
     * @return string
356
     */
357
    private function getFieldValue($details)
358
    {
359
        $this->initializeSprGlbAndSession();
360
        $rqCN = $this->tCmnRequest->request->get($details['COLUMN_NAME']);
361
        if (!is_null($rqCN)) {
362
            if (($details['IS_NULLABLE'] == 'YES') && ($rqCN == '')) {
363
                return 'NULL';
364
            }
365
            return $rqCN;
366
        }
367
        return $this->getFieldValueWithoutUserInput($details);
368
    }
369
370
    /**
371
     * Handles field value ignoring any input from the user
372
     *
373
     * @param array $details
374
     * @return string
375
     */
376
    private function getFieldValueWithoutUserInput($details)
377
    {
378
        if ($details['COLUMN_DEFAULT'] === null) {
379
            if ($details['IS_NULLABLE'] == 'YES') {
380
                return 'NULL';
381
            }
382
            return '';
383
        }
384
        return $details['COLUMN_DEFAULT'];
385
    }
386
387
    /**
388
     * Returns an array with fields referenced by a Foreign key
389
     *
390
     * @param object $db
0 ignored issues
show
Bug introduced by
There is no parameter named $db. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
391
     * @param string $database
392
     * @param string $tblName
393
     * @param string $onlyCols
0 ignored issues
show
Documentation introduced by
There is no parameter named $onlyCols. Did you maybe mean $onlyCol?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
394
     * @return array
395
     */
396
    private function getForeignKeysToArray($database, $tblName, $onlyCol = '')
397
    {
398
        if (strpos($tblName, '.`')) {
399
            $tblName = substr($tblName, strpos($tblName, '.`') + 2, 64);
400
        }
401
        $this->setTableForeginKeyCache($database, $tblName);
402
        $array2return = null;
403
        if (isset($this->advCache['tableFKs'][$database][$tblName])) {
404
            foreach ($this->advCache['tableFKs'][$database][$tblName] as $value) {
405
                if ($value['COLUMN_NAME'] == $onlyCol) {
406
                    $query                  = $this->sQueryMySqlColumns([
0 ignored issues
show
Bug introduced by
It seems like sQueryMySqlColumns() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
407
                        'TABLE_SCHEMA' => $value['REFERENCED_TABLE_SCHEMA'],
408
                        'TABLE_NAME'   => $value['REFERENCED_TABLE_NAME'],
409
                        'DATA_TYPE'    => [
410
                            'char',
411
                            'varchar',
412
                            'text',
413
                        ],
414
                    ]);
415
                    $targetTblTxtFlds       = $this->setMySQLquery2Server($query, 'full_array_key_numbered')['result'];
0 ignored issues
show
Bug introduced by
It seems like setMySQLquery2Server() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
416
                    $significance           = $targetTblTxtFlds[0]['COLUMN_NAME'];
417
                    unset($targetTblTxtFlds);
418
                    $array2return[$onlyCol] = [
419
                        '`' . implode('`.`', [
420
                            $value['REFERENCED_TABLE_SCHEMA'],
421
                            $value['REFERENCED_TABLE_NAME'],
422
                        ]) . '`',
423
                        $value['REFERENCED_COLUMN_NAME'],
424
                        '`' . $significance . '`',
425
                    ];
426
                }
427
            }
428
        }
429
        return $array2return;
430
    }
431
432
    private function getLabel($details)
433
    {
434
        return $this->setStringIntoTag($this->getFieldNameForDisplay($details), 'span', ['class' => 'fake_label']);
435
    }
436
437
    /**
438
     * Returns an array with possible values of a SET or ENUM column
439
     *
440
     * @param string $refTbl
441
     * @param string $refCol
442
     * @return array
443
     */
444
    protected function getSetOrEnum2Array($refTbl, $refCol)
445
    {
446
        if ((strpos($refTbl, '`') !== false) && (substr($refTbl, 0, 1) != '`')) {
447
            $refTbl = '`' . $refTbl . '`';
448
        }
449
        $dat = $this->establishDatabaseAndTable($refTbl);
450
        foreach ($this->advCache['tableStructureCache'][$dat[0]][$dat[1]] as $value) {
451
            if ($value['COLUMN_NAME'] == $refCol) {
452
                $clndVls = explode(',', str_replace([$value['DATA_TYPE'], '(', "'", ')'], '', $value['COLUMN_TYPE']));
453
                $enmVls  = array_combine($clndVls, $clndVls);
454
                if ($value['IS_NULLABLE'] == 'YES') {
455
                    $enmVls['NULL'] = '';
456
                }
457
            }
458
        }
459
        ksort($enmVls);
460
        return $enmVls;
461
    }
462
463
    /**
464
     * Returns a timestamp field value
465
     *
466
     * @param $details
467
     * @return unknown_type
468
     */
469
    private function getTimestamping($details)
470
    {
471
        $label = $this->getLabel($details);
472
        if (in_array($this->getFieldValue($details), ['', 'CURRENT_TIMESTAMP', 'NULL'])) {
473
            switch ($details['COLUMN_NAME']) {
474
                case 'InsertDateTime':
475
                    $input = $this->setStringIntoTag('data/timpul ad. informatiei', 'span', [
476
                        'style' => 'font-style:italic;'
477
                    ]);
478
                    break;
479
                case 'modification_datetime':
480
                case 'ModificationDateTime':
481
                    $input = $this->setStringIntoTag('data/timpul modificarii inf.', 'span', [
482
                        'style' => 'font-style:italic;'
483
                    ]);
484
                    break;
485
            }
486
        } else {
487
            $input = $this->setStringIntoTag($this->getFieldValue($details), 'span');
488
        }
489
        return ['label' => $label, 'input' => $input];
0 ignored issues
show
Bug introduced by
The variable $input does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
490
    }
491
492
    /**
493
     * Manages features flag
494
     *
495
     * @param string $fieldName
496
     * @param array $features
497
     * @return string
498
     */
499
    private function handleFeatures($fieldName, $features)
500
    {
501
        $rOly  = $this->handleFeaturesSingle($fieldName, $features, 'readonly');
502
        $rDbld = $this->handleFeaturesSingle($fieldName, $features, 'disabled');
503
        $rNl   = [];
504
        if (isset($features['include_null']) && in_array($fieldName, $features['include_null'])) {
505
            $rNl = ['include_null'];
506
        }
507
        return array_merge([], $rOly, $rDbld, $rNl);
508
    }
509
510
    private function handleFeaturesSingle($fieldName, $features, $featureKey)
511
    {
512
        $fMap    = [
513
            'readonly' => ['readonly', 'class', 'input_readonly'],
514
            'disabled' => ['disabled']
515
        ];
516
        $aReturn = [];
517
        if (array_key_exists($featureKey, $features)) {
518
            if (array_key_exists($fieldName, $features[$featureKey])) {
519
                $aReturn[$featureKey][$fMap[$featureKey][0]] = $fMap[$featureKey][0];
520
                if (count($fMap[$featureKey]) > 1) {
521
                    $aReturn[$featureKey][$fMap[$featureKey][1]] = $fMap[$featureKey][2];
522
                }
523
            }
524
        }
525
        return $aReturn;
526
    }
527
528
    /**
529
     * Returns a generic form based on a given table
530
     *
531
     * @param string $tblSrc Table Source
532
     * @param array $feat
533
     * @param string/array $hiddenInfo List of hidden fields
0 ignored issues
show
Documentation introduced by
The doc-type string/array could not be parsed: Unknown type name "string/array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
534
     *
535
     * @return string Form to add/modify detail for a single row within a table
536
     */
537
    protected function setFormGenericSingleRecord($tblSrc, $feat, $hiddenInfo = '')
538
    {
539
        echo $this->setStringIntoTag('', 'div', [
540
            'id' => 'loading'
541
        ]); // Ajax container
542
        if (strpos($tblSrc, '.') !== false) {
543
            $tblSrc = explode('.', str_replace('`', '', $tblSrc))[1];
544
        }
545
        $this->setTableCache($tblSrc); // will populate $this->advCache['tableStructureCache'][$dt[0]][$dt[1]]
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
546
        if (count($this->advCache['tableStructureCache'][$this->advCache['workingDatabase']][$tblSrc]) != 0) {
547
            foreach ($this->advCache['tableStructureCache'][$this->advCache['workingDatabase']][$tblSrc] as $value) {
548
                $sReturn[] = $this->setNeededField($tblSrc, $value, $feat);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$sReturn was never initialized. Although not strictly required by PHP, it is generally a good practice to add $sReturn = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
549
            }
550
        }
551
        $btn[]                = $this->setStringIntoShortTag('input', [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$btn was never initialized. Although not strictly required by PHP, it is generally a good practice to add $btn = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
552
            'type'  => 'submit',
553
            'id'    => 'submit',
554
            'style' => 'margin-left:220px;',
555
            'value' => $this->lclMsgCmn('i18n_Form_ButtonSave'),
556
        ]);
557
        $adtnlScriptAfterForm = $this->setJavascriptContent(implode('', [
558
            '$(document).ready(function(){',
559
            '$("form#' . $feat['id'] . '").submit(function(){',
560
            '$("input").attr("readonly", true);',
561
            '$("input[type=submit]").attr("disabled", "disabled");',
562
            '$("input[type=submit]").attr("value", "' . $this->lclMsgCmn('i18n_Form_ButtonSaving') . '");',
563
            '});',
564
            '});',
565
        ]));
566
        if (isset($feat['insertAndUpdate'])) {
567
            $btn[] = $this->setStringIntoShortTag('input', [
568
                'type'  => 'hidden',
569
                'id'    => 'insertAndUpdate',
570
                'name'  => 'insertAndUpdate',
571
                'value' => 'insertAndUpdate'
572
            ]);
573
        }
574
        $sReturn[] = $this->setStringIntoTag(implode('', $btn), 'div');
0 ignored issues
show
Bug introduced by
The variable $sReturn does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
575
        if (isset($hiddenInfo)) {
576
            if (is_array($hiddenInfo)) {
577
                foreach ($hiddenInfo as $key => $value) {
578
                    $hiddenInput = $this->setStringIntoShortTag('input', [
579
                        'type'  => 'hidden',
580
                        'name'  => $key,
581
                        'id'    => $key,
582
                        'value' => $value,
583
                    ]);
584
                    $sReturn[]   = $this->setStringIntoTag($hiddenInput, 'div');
585
                }
586
            }
587
        }
588
        return $this->setStringIntoTag(implode('', $sReturn), 'form', [
589
                    'id'     => $feat['id'],
590
                    'action' => $feat['action'],
591
                    'method' => $feat['method']
592
                ])
593
                . $adtnlScriptAfterForm;
594
    }
595
596
    protected function setTableLocaleFields($localizationStrings)
597
    {
598
        $this->advCache['tableStructureLocales'] = $localizationStrings;
599
    }
600
601
    /**
602
     * Analyse the field and returns the proper line 2 use in forms
603
     *
604
     * @param string $tableSource
605
     * @param array $details
606
     * @param array $features
607
     * @return string|array
608
     */
609
    private function setNeededField($tableSource, $details, $features)
0 ignored issues
show
Coding Style introduced by
setNeededField uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
setNeededField uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
610
    {
611
        if (isset($features['hidden'])) {
612
            if (in_array($details['COLUMN_NAME'], $features['hidden'])) {
613
                return null;
614
            }
615
        }
616
        $fieldLabel = $this->getFieldNameForDisplay($details);
617
        if ($fieldLabel == 'hidden') {
618
            return null;
619
        }
620
        switch ($details['COLUMN_NAME']) {
621
            case 'host':
622
                $sReturn['label'] = $this->setStringIntoTag('Numele calculatorului', 'label', [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$sReturn was never initialized. Although not strictly required by PHP, it is generally a good practice to add $sReturn = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
623
                    'for' => $details['COLUMN_NAME']
624
                ]);
625
                $sReturn['input'] = $this->setStringIntoShortTag('input', [
626
                    'type'     => 'input',
627
                    'size'     => 15,
628
                    'readonly' => 'readonly',
629
                    'value'    => gethostbyaddr($_SERVER['REMOTE_ADDR'])
630
                ]);
631
                break;
632
            case 'InsertDateTime':
633
            case 'modification_datetime':
634
            case 'ModificationDateTime':
635
                $sReturn          = call_user_func_array([$this, 'getTimestamping'], [$details]);
636
                break;
637
            default:
638
                $aLabel           = [
639
                    'for' => $details['COLUMN_NAME'],
640
                    'id'  => $details['COLUMN_NAME'] . '_label'
641
                ];
642
                if (isset($features['disabled'])) {
643
                    if (in_array($details['COLUMN_NAME'], $features['disabled'])) {
644
                        $aLabel = array_merge($aLabel, ['style' => 'color: grey;']);
645
                    }
646
                }
647
                $sReturn['label'] = $this->setStringIntoTag($fieldLabel, 'label', $aLabel);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$sReturn was never initialized. Although not strictly required by PHP, it is generally a good practice to add $sReturn = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
648
                $result           = $this->setNeededFieldByType($tableSource, $details, $features);
649
                if ($details['COLUMN_NAME'] == 'ChoiceId') {
650
                    $result = $this->setStringIntoShortTag('input', [
651
                        'type'  => 'text',
652
                        'name'  => $details['COLUMN_NAME'],
653
                        'value' => $_REQUEST[$details['COLUMN_NAME']]
654
                    ]);
655
                }
656
                $sReturn['input'] = $result;
657
                break;
658
        }
659
        $finalReturn[] = $sReturn['label'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$finalReturn was never initialized. Although not strictly required by PHP, it is generally a good practice to add $finalReturn = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
660
        $finalReturn[] = $this->setStringIntoTag($sReturn['input'], 'span', ['class' => 'labell']);
661
        $wrkDb         = $this->advCache['workingDatabase'];
662
        if (isset($this->tableFKsCache[$wrkDb][$tableSource])) {
0 ignored issues
show
Bug introduced by
The property tableFKsCache does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
663
            if (in_array($details['COLUMN_NAME'], $this->advCache['FKcol'][$wrkDb][$tableSource])) {
664
                $finalReturn[] = $this->getFieldLength($details);
0 ignored issues
show
Bug introduced by
It seems like getFieldLength() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
665
            }
666
        }
667
        return $this->setStringIntoTag(implode('', $finalReturn), 'div');
668
    }
669
670
    /**
671
     * Analyse the field type and returns the proper lines 2 use in forms
672
     *
673
     * @param string $tblName
674
     * @param array $details
675
     * @param array $features
676
     * @return string|array
677
     */
678
    private function setNeededFieldByType($tblName, $details, $features)
679
    {
680
        $sReturn = null;
681
        if (isset($features['special']) && isset($features['special'][$details['COLUMN_NAME']])) {
682
            $slctOpt = $this->setQuery2Server($features['special'][$details['COLUMN_NAME']], 'array_key_value');
0 ignored issues
show
Bug introduced by
It seems like setQuery2Server() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
683
            $sReturn = $this->setArrayToSelect($slctOpt, $this->getFieldValue($details), $details['COLUMN_NAME'], [
684
                'size' => 1
685
            ]);
686
        } else {
687
            $iar = $this->handleFeatures($details['COLUMN_NAME'], $features);
688
            switch ($details['DATA_TYPE']) {
689
                case 'bigint':
690
                case 'int':
691
                case 'mediumint':
692
                case 'smallint':
693
                case 'tinyint':
694
                case 'float':
695
                case 'double':
696
                case 'decimal':
697
                case 'numeric':
698
                    $sReturn = $this->getFieldOutputNumeric($tblName, $details, $iar);
699
                    break;
700
                case 'char':
701
                case 'tinytext':
702
                case 'varchar':
703
                    $sReturn = $this->getFieldOutputText($tblName, $details['DATA_TYPE'], $details, $iar);
704
                    break;
705
                case 'date':
706
                    $sReturn = $this->getFieldOutputDate($details['DATA_TYPE'], $details, $iar);
0 ignored issues
show
Bug introduced by
It seems like getFieldOutputDate() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
707
                    break;
708
                case 'datetime':
709
                case 'timestamp':
710
                    $sReturn = $this->getFieldOutputTimestamp($details, $iar);
711
                    break;
712
                case 'enum':
713
                case 'set':
714
                    $sReturn = $this->getFieldOutputEnumSet($tblName, $details['DATA_TYPE'], $details, $iar);
715
                    break;
716
                case 'text':
717
                case 'blob':
718
                    $sReturn = $this->getFieldOutputTextLarge($details['DATA_TYPE'], $details, $iar);
719
                    break;
720
                case 'time':
721
                    $sReturn = $this->getFieldOutputTime($details, $iar);
722
                    break;
723
                case 'year':
724
                    $sReturn = $this->getFieldOutputYear($details, $iar);
725
                    break;
726
            }
727
        }
728
        return $this->getFieldCompletionType($details) . $sReturn;
729
    }
730
731
    /**
732
     * create a Cache for given table to use it in many places
733
     *
734
     * @param type $tblSrc
735
     */
736
    private function setTableCache($tblSrc)
737
    {
738
        $dat = $this->establishDatabaseAndTable($tblSrc);
739
        if (!isset($this->advCache['tableStructureCache'][$dat[0]][$dat[1]])) {
740
            switch ($dat[1]) {
741
                case 'user_rights':
742
                    $this->advCache['workingDatabase'] = 'usefull_security';
743
                    break;
744
                default:
745
                    $this->advCache['workingDatabase'] = $dat[0];
746
                    break;
747
            }
748
            $this->advCache['tableStructureCache'][$dat[0]][$dat[1]] = $this->getMySQLlistColumns([
0 ignored issues
show
Bug introduced by
It seems like getMySQLlistColumns() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
749
                'TABLE_SCHEMA' => $dat[0],
750
                'TABLE_NAME'   => $dat[1],
751
            ]);
752
            $this->setTableForeginKeyCache($dat[0], $dat[1]);
753
        }
754
    }
755
756
    private function setTableForeginKeyCache($dbName, $tblName)
757
    {
758
        $frgnKs = $this->getMySQLlistIndexes([
0 ignored issues
show
Bug introduced by
It seems like getMySQLlistIndexes() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
759
            'TABLE_SCHEMA'          => $dbName,
760
            'TABLE_NAME'            => $tblName,
761
            'REFERENCED_TABLE_NAME' => 'NOT NULL',
762
        ]);
763
        if (!is_null($frgnKs)) {
764
            $this->advCache['tableFKs'][$dbName][$tblName] = $frgnKs;
765
            $this->advCache['FKcol'][$dbName][$tblName]    = array_column($frgnKs, 'COLUMN_NAME', 'CONSTRAINT_NAME');
766
        }
767
    }
768
769
    private function setViewDeleteFeedbacks()
770
    {
771
        return [
772
            'Confirmation' => $this->lclMsgCmn('i18n_Action_Confirmation'),
773
            'Failed'       => $this->lclMsgCmn('i18n_ActionDelete_Failed'),
774
            'Impossible'   => $this->lclMsgCmn('i18n_ActionDelete_Impossible'),
775
            'Success'      => $this->lclMsgCmn('i18n_ActionDelete_Success'),
776
        ];
777
    }
778
779
    private function setViewDeletePackedFinal($sReturn)
780
    {
781
        $finalJavascript = $this->setJavascriptContent(implode('', [
782
            '$("#DeleteFeedback").fadeOut(4000, function() {',
783
            '$(this).remove();',
784
            '});',
785
        ]));
786
        return '<div id="DeleteFeedback">' . $sReturn . '</div>' . $finalJavascript;
787
    }
788
789
    /**
790
     * Automatic handler for Record deletion
791
     *
792
     * @param string $tbl
793
     * @param string $idn
794
     * @return string
795
     */
796
    protected function setViewModernDelete($tbl, $idn)
0 ignored issues
show
Coding Style introduced by
setViewModernDelete uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
797
    {
798
        $tMsg = $this->setViewDeleteFeedbacks();
799
        if ($tbl == '') {
800
            $sReturn = $this->setFeedbackModern('error', $tMsg['Confirmation'], $tMsg['Impossible']);
801
        } else {
802
            $this->setMySQLquery2Server($this->sQueryToDeleteSingleIdentifier([$tbl, $idn, $_REQUEST[$idn]]));
0 ignored issues
show
Bug introduced by
It seems like sQueryToDeleteSingleIdentifier() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Bug introduced by
It seems like setMySQLquery2Server() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
803
            $sReturn = $this->setFeedbackModern('error', $tMsg['Confirmation'], $tMsg['Failed'])
804
                    . '(' . $this->mySQLconnection->error . ')';
0 ignored issues
show
Bug introduced by
The property mySQLconnection does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
805
            if ($this->mySQLconnection->affected_rows > 0) {
806
                $sReturn = $this->setFeedbackModern('check', $tMsg['Confirmation'], $tMsg['Success']);
807
            }
808
        }
809
        return $this->setViewDeletePackedFinal($sReturn);
810
    }
811
}
812