FlexformSelection   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 3
c 4
b 0
f 0
lcom 0
cbo 2
dl 0
loc 30
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A addReleations() 0 20 3
1
<?php
2
3
/**
4
 * Flexform selection
5
 */
6
7
namespace HDNET\Tagger\Service;
8
9
use TYPO3\CMS\Backend\Utility\IconUtility;
10
use TYPO3\CMS\Core\Database\DatabaseConnection;
11
12
/**
13
 * Flexform selection
14
 */
15
class FlexformSelection
16
{
17
18
    /**
19
     * Add the possible relation to the flexform selection of the tagger plugin
20
     *
21
     * @param array $config
22
     * @param object $obj
23
     */
24
    public function addReleations(&$config, &$obj)
0 ignored issues
show
Unused Code introduced by
The parameter $obj is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
    {
26
        /** @var DatabaseConnection $databaseConnection */
27
        $databaseConnection = $GLOBALS['TYPO3_DB'];
28
        $rows = $databaseConnection->exec_SELECTgetRows(
29
            'tablenames',
30
            'tx_tagger_tag_mm',
31
            '1=1',
32
            'tablenames',
33
            'tablenames DESC'
34
        );
35
        foreach ($rows as $row) {
0 ignored issues
show
Bug introduced by
The expression $rows of type null|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
36
            $table = $row['tablenames'];
37
            $icon = IconUtility::getSpriteIconForRecord($table, []);
0 ignored issues
show
Deprecated Code introduced by
The method TYPO3\CMS\Backend\Utilit...etSpriteIconForRecord() has been deprecated with message: since TYPO3 CMS 7, will be removed with TYPO3 CMS 8

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
38
            if (substr($icon, 0, 4) == 'gfx/') {
39
                $icon = str_replace('gfx/', '', $icon);
40
            }
41
            $config['items'][] = [$table, $table, $icon];
42
        }
43
    }
44
}
45