-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
4.ClassesPropertiesAndMethods.php
110 lines (85 loc) · 2.86 KB
/
4.ClassesPropertiesAndMethods.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
101
102
103
104
105
106
107
108
109
110
<?php
declare(strict_types=1);
namespace LaminasCodingStandardTest\fixed;
use ArrayObject;
use DateTime;
use Foo;
use PHP_CodeSniffer\Config;
use stdClass;
use Vendor\FooException;
use Vendor\FooInterface;
use Vendor\FooTrait;
use function get_class;
abstract class AbstractFoo
{
}
class ClassesPropertiesAndMethods extends AbstractFoo implements FooInterface
{
use FooTrait;
public function __construct()
{
}
public function testDuplicateClassNames(): void
{
// There MAY NOT be duplicate class names.
}
public function testConstructor(): void
{
// PHP 4 style constructors SHOULD NOT be used.
}
public function testClassPrefixAndSuffix(): void
{
// Abstract classes MUST have a `Abstract` prefix.
// Exception classes MUST have a `Exception` suffix.
// Interface classes MUST have a `Interface` suffix.
// Trait classes MUST have a `Trait` suffix.
throw new FooException('Oops!');
}
public function testClassClosingBrace(): void
{
// Any closing brace MUST NOT be followed by any comment or statement on
// the same line.
//
// NOTE: Fixers are not available for this sniff as it is likely that
// comments would be found more than anything else, and simply moving
// them to the next line is probably not the right fix. More likely,
// the comment should be removed, which only the developer should do.
}
public function testClassInstantiation(): void
{
// When instantiating a new class, parentheses MUST always be present
// even when there are no arguments passed to the constructor.
new Foo();
}
public function testCorrectClassNames(): void
{
// The correct class names MUST be used.
new DateTime();
new ArrayObject();
new ArrayObject();
DateTime::createFromFormat('Y');
}
public function testClassNameResolution(): iterable
{
// For self-reference a class lower-case `self::` MUST be used without
// spaces around the scope resolution operator.
//
// Class name resolution via `::class` MUST be used instead of
// `__CLASS__`, `get_class()`, `get_class($this)`,
// `get_called_class()` and `get_parent_class()`.
yield self::class;
yield self::class;
yield static::class;
yield get_class(new stdClass());
yield parent::class;
yield static::class;
$class = Config::class;
}
public function testThereMayNotBeAnyWhitespaceAroundTheDoubleColon(): void
{
// There MAY NOT be any whitespace around the double colon operator.
DateTime::createFromFormat('Y-m-d', '2016-01-01');
DateTime::createFromFormat('Y-m-d', '2016-01-01');
DateTime::createFromFormat('Y-m-d', '2016-01-01');
}
}