GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ConsoleOutputTable::getCellFromPlaceholder()   C
last analyzed

Complexity

Conditions 17
Paths 17

Size

Total Lines 23
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 5.2603
c 0
b 0
f 0
cc 17
eloc 20
nc 17
nop 2

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
namespace Selim;
4
5
use Console_Table;
6
7
class ConsoleOutputTable extends Output implements IOutput
8
{
9
    private static function getCellFromPlaceholder($placeholder, SilverstripePage $sspage = null)
10
    {
11
        switch ($placeholder) {
12
            case '%s':
13
                return $sspage ? $sspage->getName() : "Site";
14
            case '%v':
15
                return $sspage ? $sspage->getVersion() : "Version";
16
            case '%da':
17
                return $sspage ? self::DefaultAdminText($sspage) : "DefaultAdmin";
18
            case '%el':
19
                return $sspage ? self::EmailLoggingText($sspage) : "EmailLogging";
20
            case '%et':
21
                return $sspage ? $sspage->getEnvironmentType() : "EnvironmentType";
22
            case '%m':
23
                return $sspage ? self::ModuleText($sspage) : "Modules";
24
            case '%cfgp':
25
                return $sspage ? $sspage->getConfigPhpPath() : "_config.php";
26
            case '%cfgy':
27
                return $sspage ? $sspage->getConfigYmlPath() : "_config/config.yml";
28
            default:
29
                return "";
30
        }
31
    }
32
33
    private static function getRowFromColumns($columns, SilverstripePage $sspage = null)
34
    {
35
        $matches = array();
36
        preg_match_all("/(?<pl>%s|%v|%da|%el|%et|%m|%cfgp|%cfgy)/", $columns, $matches);
37
        $row = array();
38
39
        foreach ($matches["pl"] as $m) {
40
            $c = self::getCellFromPlaceholder($m, $sspage);
41
            if ($c) {
42
                array_push($row, $c);
43
            }
44
        }
45
46
        return $row;
47
    }
48
49
    private static function getHeadFromColumns($columns)
50
    {
51
        return self::getRowFromColumns($columns);
52
    }
53
54
    public function write($columns = "%s%v%da%el%et%m")
55
    {
56
        $table = new Console_Table();
57
58
        $table->setHeaders(self::getHeadFromColumns($columns));
59
60
        foreach ($this->pages as $p) {
61
            $table->addRow(self::getRowFromColumns($columns, $p));
62
        }
63
64
        echo $table->getTable();
65
    }
66
}
67