Issues (197)

.php-cs-fixer.dist.php (1 issue)

Labels
Severity
1
<?php
2
3
use PhpCsFixer\Config;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Config. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
4
use PhpCsFixer\Finder;
5
6
$rules = [
7
    '@PSR12' => true,
8
        // Concatenation should be used with at least one whitespace around.
9
        'concat_space' => ['spacing' => 'one'],
10
        // Unused use statements must be removed.
11
        'ordered_imports' => true,
12
        // Removes extra empty lines.
13
        'no_extra_blank_lines' => true,
14
        // An empty line feed should precede a return statement.
15
        'blank_line_before_statement' => true,
16
        // Unused use statements must be removed.
17
        'no_unused_imports' => true,
18
        // Remove trailing whitespace at the end of blank lines.
19
        'no_whitespace_in_blank_line' => true,
20
        // There MUST be one blank line after the namespace declaration.
21
        'blank_line_after_namespace' => true,
22
        // There should be exactly one blank line before a namespace declaration.
23
        'single_blank_line_before_namespace' => true,
24
        // Each namespace use MUST go on its own line and there MUST be one blank line after the use statements block.
25
        'single_line_after_imports' => true,
26
        // Ensure there is no code on the same line as the PHP open tag and it is followed by a blankline.
27
        'blank_line_after_opening_tag' => true,
28
        // Remove duplicated semicolons.
29
        'no_empty_statement' => true,
30
        // PHP multi-line arrays should have a trailing comma.
31
        'trailing_comma_in_multiline' => true,
32
        // There should be no empty lines after class opening brace.
33
        'no_blank_lines_after_class_opening' => true,
34
        // There should not be blank lines between docblock and the documented element.
35
        'no_blank_lines_after_phpdoc' => true,
36
        // Phpdocs should start and end with content, excluding the very first and last line of the docblocks.
37
        'phpdoc_trim' => true,
38
];
39
40
$finder = Finder::create()
41
    ->in(__DIR__)
42
    ->exclude([
43
        'vendor',
44
        'tests/Commands/__snapshots__',
45
    ])
46
    ->ignoreDotFiles(true)
47
    ->ignoreVCS(true);
48
49
return (new Config())
50
    ->setFinder($finder)
51
    ->setRules($rules)
52
    ->setRiskyAllowed(true)
53
    ->setUsingCache(true);