/
3.DeclareNamespaceAndImport.php
100 lines (89 loc) · 3.24 KB
/
3.DeclareNamespaceAndImport.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
declare(strict_types=1);
namespace LaminasCodingStandardTest \ fixed;
use \DateInterval;
use \DateTimeZone;
use Bar\Baz;
use DateTimeImmutable;
use function strrev;
/**
* FooBar is an example class.
*/
class DeclareNamespaceAndImport
{
public function testFilesFileHeader(): void
{
// The header of a PHP file may consist of a number of different
// blocks. If present, each of the blocks below MUST be separated
// by a single blank line, and MUST NOT contain a blank line. Each
// block MUST be in the order listed below, although blocks that
// are not relevant may be omitted.
//
// Opening php tag.
// File-level docblock.
// One or more declare statements.
// The namespace declaration of the file.
// One or more class-based use import statements.
// One or more function-based use import statements.
// One or more constant-based use import statements.
// The remainder of the code in the file.
}
public function testNamespaceSpacing(): void
{
// There MUST be a single space after the namespace keyword.
//
// There MAY NOT be a space around a namespace separator.
}
public function testImportStatements(): void
{
// Import statements MUST never begin with a leading backslash as they
// must always be fully qualified.
//
// Compound namespaces with a depth of more than two MUST NOT be used.
// Import statements must be alphabetically sorted.
//
// Functions and const keywords must be lowercase in import statements.
//
// Unused import statements are not allowed.
//
// Superfluous leading backslash in import statements MUST be removed.
//
// Fancy group import statements are not allowed.
//
// Each import statements MUST be on its own line.
//
// Import statements must be grouped (classes, functions, constants)
// and MUST be separated by empty lines.
//
// Import statements aliases for classes, traits, functions and
// constants MUST be useful.
//
// Classes, traits, interfaces, constants and functions MUST be imported.
//
// Internal functions MUST be imported.
//
// Internal constants MUST be imported.
strrev(
(new DateTimeImmutable('@' . time(), new DateTimeZone('UTC')))
->sub(new DateInterval('P1D'))
->format(DATE_RFC3339)
);
new Baz();
}
public function testDeclareStatement(): void
{
// When wishing to declare strict types in files containing markup
// outside PHP opening and closing tags, the declaration MUST be on the
// first line of the file and include an opening PHP tag, the strict
// types declaration and closing tag.
//
// Declare statements MUST contain no spaces and MUST be exactly
// declare(strict_types=1) (with an optional semi-colon terminator).
//
// Block declare statements are allowed and MUST be formatted as below.
declare(ticks=1)
{
// some code
}
}
}