Skip to content

Commit

Permalink
Add the documentation for the PSR12 File Header sniff
Browse files Browse the repository at this point in the history
  • Loading branch information
dingo-d committed Jan 5, 2024
1 parent 269098e commit a22d0c6
Showing 1 changed file with 207 additions and 0 deletions.
207 changes: 207 additions & 0 deletions src/Standards/PSR12/Docs/Files/FileHeaderStandard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
<documentation title="File Header">
<standard>
<![CDATA[
Ensures that the PHP file header is properly formatted.
]]>
</standard>
<code_comparison>
<code title="Valid: File header is the first content in the file.">
<![CDATA[
<?php
/**
* This is a file comment.
*/
declare(strict_types=1);
namespace Vendor\Package;
use Vendor\Package\{ClassA as A, ClassB};
use const Another\Vendor\CONST_D;
/**
* FooBar is an example class.
*/
class FooBar
{
// ... additional PHP code ...
}
]]>
</code>
<code title="Invalid: File header is not the first content in the file.">
<![CDATA[
<em><?php echo 'Some content'; ?></em>
<?php
/**
* The header is not the first thing
* in the file.
*/
declare(strict_types=1);
namespace Vendor\Package;
use Vendor\Package\{ClassA as A, ClassB};
use const Another\Vendor\CONST_D;
/**
* FooBar is an example class.
*/
class FooBar
{
// ... additional PHP code ...
}
]]>
</code>
</code_comparison>
<code_comparison>
<code title="Valid: If header blocks are present, they are separated by a single blank line and don't contain blank lines.">
<![CDATA[
<?php
/**
* This is a file comment.
*/
declare(strict_types=1);
namespace Vendor\Package;
use Vendor\Package\SomeNamespace\ClassD as D;
use Vendor\Package\SomeNamespace\{
SubnamespaceOne\ClassA,
SubnamespaceOne\ClassB,
SubnamespaceTwo\ClassY,
ClassZ,
};
use function Vendor\Package\{funcA};
use function Another\Vendor\funcD;
use const Vendor\Package\{
CONST_A, CONST_B
};
use const Another\Vendor\CONST_D;
/**
* FooBar is an example class.
*/
class FooBar
{
// ... additional PHP code ...
}
]]>
</code>
<code title="Invalid: Header blocks are not separated by a single blank line, or contain blank lines between blocks.">
<![CDATA[
<?php
/**
* This is a file comment.
*/<em></em>
declare(strict_types=1);
namespace Vendor\Package;<em></em>
use Vendor\Package\{ClassA as A, ClassB};
<em></em>
<em></em>
use function Vendor\Package\funcA;
// Blank line between the function imports.
<em></em>
use function Another\Vendor\funcD;
/**
* FooBar is an example class.
*/
class FooBar
{
// ... additional PHP code ...
}
]]>
</code>
</code_comparison>
<code_comparison>
<code title="Valid: If header blocks are present, they are ordered correctly as showed below.">
<![CDATA[
<?php
/**
* This is a file-level docblock.
*
* Only thing before it is the
* opening <?php tag.
*/
// One or more declare statements.
declare(strict_types=1);
// Namespace declaration of the file.
namespace Vendor\Package;
// Class-based use import statements.
use Vendor\Package\{ClassA as A, ClassB};
use Vendor\Package\SomeNamespace\ClassD as D;
use Vendor\Package\SomeNamespace\{
SubnamespaceOne\ClassA,
ClassZ,
};
// Function-based use import statements.
use function Vendor\Package\{funcA};
use function Another\Vendor\funcD;
// Constant-based use import statements.
use const Vendor\Package\{
CONST_A, CONST_B
};
use const Another\Vendor\CONST_D;
// Remainder of the code in the file.
/**
* FooBar is an example class.
*/
class FooBar
{
// ... additional PHP code ...
}
]]>
</code>
<code title="Invalid: Header blocks are not in a correct order.">
<![CDATA[
<?php
/**
* Incorrect order of the imports.
*/
declare(strict_types=1);
namespace Vendor\Package;
use Vendor\Package\{ClassA as A, ClassB};
use Vendor\Package\SomeNamespace\ClassD as D;
use Vendor\Package\AnotherNamespace\ClassE as E;
// Constant-based use imports statements
// before the function ones.
<em>use const Vendor\Package\{CONST_A, CONST_B};
use const Another\Vendor\CONST_D;</em>
use function Vendor\Package\{funcA, funcB};
use function Another\Vendor\funcD;
/**
* FooBar is an example class.
*/
class FooBar
{
// ... additional PHP code ...
}
]]>
</code>
</code_comparison>
</documentation>

0 comments on commit a22d0c6

Please sign in to comment.