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.

FormatterHelper   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 62
Duplicated Lines 9.68 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 6
loc 62
rs 10
c 0
b 0
f 0
wmc 11
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A formatSection() 0 4 1
D formatBlock() 6 28 9
A getName() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Symfony\Component\Console\Helper;
13
14
use Symfony\Component\Console\Formatter\OutputFormatter;
15
16
/**
17
 * The Formatter class provides helpers to format messages.
18
 *
19
 * @author Fabien Potencier <[email protected]>
20
 */
21
class FormatterHelper extends Helper
22
{
23
    /**
24
     * Formats a message within a section.
25
     *
26
     * @param string $section The section name
27
     * @param string $message The message
28
     * @param string $style   The style to apply to the section
29
     *
30
     * @return string The format section
31
     */
32
    public function formatSection($section, $message, $style = 'info')
33
    {
34
        return sprintf('<%s>[%s]</%s> %s', $style, $section, $style, $message);
35
    }
36
37
    /**
38
     * Formats a message as a block of text.
39
     *
40
     * @param string|array $messages The message to write in the block
41
     * @param string       $style    The style to apply to the whole block
42
     * @param bool         $large    Whether to return a large block
43
     *
44
     * @return string The formatter message
45
     */
46
    public function formatBlock($messages, $style, $large = false)
47
    {
48
        if (!is_array($messages)) {
49
            $messages = array($messages);
50
        }
51
52
        $len = 0;
53
        $lines = array();
54
        foreach ($messages as $message) {
55
            $message = OutputFormatter::escape($message);
56
            $lines[] = sprintf($large ? '  %s  ' : ' %s ', $message);
57
            $len = max($this->strlen($message) + ($large ? 4 : 2), $len);
58
        }
59
60
        $messages = $large ? array(str_repeat(' ', $len)) : array();
61 View Code Duplication
        for ($i = 0; isset($lines[$i]); ++$i) {
62
            $messages[] = $lines[$i].str_repeat(' ', $len - $this->strlen($lines[$i]));
63
        }
64
        if ($large) {
65
            $messages[] = str_repeat(' ', $len);
66
        }
67
68 View Code Duplication
        for ($i = 0; isset($messages[$i]); ++$i) {
69
            $messages[$i] = sprintf('<%s>%s</%s>', $style, $messages[$i], $style);
70
        }
71
72
        return implode("\n", $messages);
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function getName()
79
    {
80
        return 'formatter';
81
    }
82
}
83