|
| 1 | +<documentation title="File Header"> |
| 2 | + <standard> |
| 3 | + <![CDATA[ |
| 4 | + Ensures that the PHP file header is properly formatted. |
| 5 | + ]]> |
| 6 | + </standard> |
| 7 | + <code_comparison> |
| 8 | + <code title="Valid: The file header is the first content in the file."> |
| 9 | + <![CDATA[ |
| 10 | +<?php |
| 11 | +
|
| 12 | +/** |
| 13 | + * This is a file comment. |
| 14 | + */ |
| 15 | +
|
| 16 | +// Remainder of the code in the file. |
| 17 | + ]]> |
| 18 | + </code> |
| 19 | + <code title="Invalid: The file header is not the first content in the file."> |
| 20 | + <![CDATA[ |
| 21 | +<em><?php echo 'Some content'; ?></em> |
| 22 | +<?php |
| 23 | +
|
| 24 | +/** |
| 25 | + * The header is not the first thing |
| 26 | + * in the file. |
| 27 | + */ |
| 28 | +
|
| 29 | +// Remainder of the code in the file. |
| 30 | + ]]> |
| 31 | + </code> |
| 32 | + </code_comparison> |
| 33 | + <code_comparison> |
| 34 | + <code title="Valid: If the header blocks are present, they are separated by a single blank line and don't contain blank lines."> |
| 35 | + <![CDATA[ |
| 36 | +<?php |
| 37 | +
|
| 38 | +/** |
| 39 | + * This is a file comment. |
| 40 | + */ |
| 41 | +
|
| 42 | +declare(strict_types=1); |
| 43 | +
|
| 44 | +namespace Vendor\Package; |
| 45 | +
|
| 46 | +use Vendor\Package\SomeNamespace\ClassD as D; |
| 47 | +use Vendor\Package\SomeNamespace\{ |
| 48 | + SubnamespaceOne\ClassA, |
| 49 | + SubnamespaceOne\ClassB, |
| 50 | + SubnamespaceTwo\ClassY, |
| 51 | + ClassZ, |
| 52 | +}; |
| 53 | +
|
| 54 | +use function Vendor\Package\{funcA}; |
| 55 | +use function Another\Vendor\funcD; |
| 56 | +
|
| 57 | +use const Vendor\Package\{ |
| 58 | + CONST_A, CONST_B |
| 59 | +}; |
| 60 | +use const Another\Vendor\CONST_D; |
| 61 | +
|
| 62 | +// Remainder of the code in the file. |
| 63 | + ]]> |
| 64 | + </code> |
| 65 | + <code title="Invalid: The header blocks are not separated by a single blank line or contain blank lines between blocks."> |
| 66 | + <![CDATA[ |
| 67 | +<?php |
| 68 | +
|
| 69 | +/** |
| 70 | + * This is a file comment. |
| 71 | + */<em></em> |
| 72 | +declare(strict_types=1); |
| 73 | +
|
| 74 | +namespace Vendor\Package;<em></em> |
| 75 | +use Vendor\Package\{ClassA as A, ClassB}; |
| 76 | +<em></em> |
| 77 | +<em></em> |
| 78 | +use function Vendor\Package\funcA; |
| 79 | +// Blank line between the function imports. |
| 80 | +<em></em> |
| 81 | +use function Another\Vendor\funcD; |
| 82 | +
|
| 83 | +// Remainder of the code in the file. |
| 84 | + ]]> |
| 85 | + </code> |
| 86 | + </code_comparison> |
| 87 | + <code_comparison> |
| 88 | + <code title="Valid: If the header blocks are present, they are ordered correctly as shown below."> |
| 89 | + <![CDATA[ |
| 90 | +<?php |
| 91 | +
|
| 92 | +/** |
| 93 | + * This is a file-level docblock. |
| 94 | + * |
| 95 | + * Only thing before it is the |
| 96 | + * opening <?php tag. |
| 97 | + */ |
| 98 | +
|
| 99 | +// One or more declare statements. |
| 100 | +declare(strict_types=1); |
| 101 | +
|
| 102 | +// Namespace declaration of the file. |
| 103 | +namespace Vendor\Package; |
| 104 | +
|
| 105 | +// Class-based use import statements. |
| 106 | +use Vendor\Package\{ClassA as A, ClassB}; |
| 107 | +use Vendor\Package\SomeNamespace\ClassD as D; |
| 108 | +use Vendor\Package\SomeNamespace\{ |
| 109 | + SubnamespaceOne\ClassA, |
| 110 | + ClassZ, |
| 111 | +}; |
| 112 | +
|
| 113 | +// Function-based use import statements. |
| 114 | +use function Vendor\Package\{funcA}; |
| 115 | +use function Another\Vendor\funcD; |
| 116 | +
|
| 117 | +// Constant-based use import statements. |
| 118 | +use const Vendor\Package\{ |
| 119 | + CONST_A, CONST_B |
| 120 | +}; |
| 121 | +use const Another\Vendor\CONST_D; |
| 122 | +
|
| 123 | +// Remainder of the code in the file. |
| 124 | + ]]> |
| 125 | + </code> |
| 126 | + <code title="Invalid: The header blocks are not in the correct order."> |
| 127 | + <![CDATA[ |
| 128 | +<?php |
| 129 | +
|
| 130 | +/** |
| 131 | + * Incorrect order of the imports. |
| 132 | + */ |
| 133 | +
|
| 134 | +declare(strict_types=1); |
| 135 | +
|
| 136 | +use Vendor\Package\{ClassA as A, ClassB}; |
| 137 | +use Vendor\Package\SomeNamespace\ClassD as D; |
| 138 | +
|
| 139 | +// Namespace declaration |
| 140 | +// after the class-based use import statements. |
| 141 | +namespace Vendor\Package; |
| 142 | +
|
| 143 | +use Vendor\Package\AnotherNamespace\ClassE as E; |
| 144 | +
|
| 145 | +// Constant-based use imports statements |
| 146 | +// before the function-based ones. |
| 147 | +<em>use const Vendor\Package\{CONST_A, CONST_B}; |
| 148 | +use const Another\Vendor\CONST_D;</em> |
| 149 | +
|
| 150 | +use function Vendor\Package\{funcA, funcB}; |
| 151 | +use function Another\Vendor\funcD; |
| 152 | +
|
| 153 | +// Remainder of the code in the file. |
| 154 | + ]]> |
| 155 | + </code> |
| 156 | + </code_comparison> |
| 157 | +</documentation> |
0 commit comments