Completed
Push — master ( 0a6dbe...603188 )
by Laurent
12:39
created

check.php ➔ echo_block()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 3
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 76 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
require_once dirname(__FILE__).'/SymfonyRequirements.php';
4
5
$lineSize = 70;
6
$symfonyRequirements = new SymfonyRequirements();
7
$iniPath = $symfonyRequirements->getPhpIniConfigPath();
8
9
echo_title('Symfony Requirements Checker');
10
11
echo '> PHP is using the following php.ini file:'.PHP_EOL;
12
if ($iniPath) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $iniPath of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
13
    echo_style('green', '  '.$iniPath);
14
} else {
15
    echo_style('yellow', '  WARNING: No configuration file (php.ini) used by PHP!');
16
}
17
18
echo PHP_EOL.PHP_EOL;
19
20
echo '> Checking Symfony requirements:'.PHP_EOL.'  ';
21
22
$messages = array();
23
foreach ($symfonyRequirements->getRequirements() as $req) {
24 View Code Duplication
    if ($helpText = get_error_message($req, $lineSize)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
25
        echo_style('red', 'E');
26
        $messages['error'][] = $helpText;
27
    } else {
28
        echo_style('green', '.');
29
    }
30
}
31
32
$checkPassed = empty($messages['error']);
33
34
foreach ($symfonyRequirements->getRecommendations() as $req) {
35 View Code Duplication
    if ($helpText = get_error_message($req, $lineSize)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
36
        echo_style('yellow', 'W');
37
        $messages['warning'][] = $helpText;
38
    } else {
39
        echo_style('green', '.');
40
    }
41
}
42
43
if ($checkPassed) {
44
    echo_block('success', 'OK', 'Your system is ready to run Symfony projects');
45
} else {
46
    echo_block('error', 'ERROR', 'Your system is not ready to run Symfony projects');
47
48
    echo_title('Fix the following mandatory requirements', 'red');
49
50
    foreach ($messages['error'] as $helpText) {
51
        echo ' * '.$helpText.PHP_EOL;
52
    }
53
}
54
55
if (!empty($messages['warning'])) {
56
    echo_title('Optional recommendations to improve your setup', 'yellow');
57
58
    foreach ($messages['warning'] as $helpText) {
59
        echo ' * '.$helpText.PHP_EOL;
60
    }
61
}
62
63
echo PHP_EOL;
64
echo_style('title', 'Note');
65
echo '  The command console could use a different php.ini file'.PHP_EOL;
66
echo_style('title', '~~~~');
67
echo '  than the one used with your web server. To be on the'.PHP_EOL;
68
echo '      safe side, please check the requirements from your web'.PHP_EOL;
69
echo '      server using the ';
70
echo_style('yellow', 'web/config.php');
71
echo ' script.'.PHP_EOL;
72
echo PHP_EOL;
73
74
exit($checkPassed ? 0 : 1);
75
76
function get_error_message(Requirement $requirement, $lineSize)
0 ignored issues
show
Coding Style introduced by
function get_error_message() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
77
{
78
    if ($requirement->isFulfilled()) {
79
        return;
80
    }
81
82
    $errorMessage = wordwrap($requirement->getTestMessage(), $lineSize - 3, PHP_EOL.'   ').PHP_EOL;
83
    $errorMessage .= '   > '.wordwrap($requirement->getHelpText(), $lineSize - 5, PHP_EOL.'   > ').PHP_EOL;
84
85
    return $errorMessage;
86
}
87
88
function echo_title($title, $style = null)
0 ignored issues
show
Coding Style introduced by
function echo_title() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
89
{
90
    $style = $style ?: 'title';
91
92
    echo PHP_EOL;
93
    echo_style($style, $title.PHP_EOL);
94
    echo_style($style, str_repeat('~', strlen($title)).PHP_EOL);
95
    echo PHP_EOL;
96
}
97
98
function echo_style($style, $message)
0 ignored issues
show
Coding Style introduced by
function echo_style() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
99
{
100
    // ANSI color codes
101
    $styles = array(
102
        'reset' => "\033[0m",
103
        'red' => "\033[31m",
104
        'green' => "\033[32m",
105
        'yellow' => "\033[33m",
106
        'error' => "\033[37;41m",
107
        'success' => "\033[37;42m",
108
        'title' => "\033[34m",
109
    );
110
    $supports = has_color_support();
111
112
    echo($supports ? $styles[$style] : '').$message.($supports ? $styles['reset'] : '');
113
}
114
115
function echo_block($style, $title, $message)
0 ignored issues
show
Coding Style introduced by
function echo_block() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
116
{
117
    $message = ' '.trim($message).' ';
118
    $width = strlen($message);
119
120
    echo PHP_EOL.PHP_EOL;
121
122
    echo_style($style, str_repeat(' ', $width));
123
    echo PHP_EOL;
124
    echo_style($style, str_pad(' ['.$title.']', $width, ' ', STR_PAD_RIGHT));
125
    echo PHP_EOL;
126
    echo_style($style, $message);
127
    echo PHP_EOL;
128
    echo_style($style, str_repeat(' ', $width));
129
    echo PHP_EOL;
130
}
131
132
function has_color_support()
0 ignored issues
show
Coding Style introduced by
function has_color_support() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
133
{
134
    static $support;
135
136
    if (null === $support) {
137
        if (DIRECTORY_SEPARATOR == '\\') {
138
            $support = false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI');
139
        } else {
140
            $support = function_exists('posix_isatty') && @posix_isatty(STDOUT);
141
        }
142
    }
143
144
    return $support;
145
}
146