forked from doctrine/coding-standard
/
example-class.php
77 lines (60 loc) · 1.66 KB
/
example-class.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
<?php
declare(strict_types=1);
namespace Example;
use ArrayIterator;
use Doctrine\Sniffs\Spacing\ControlStructureSniff;
use Fancy\TestCase;
use InvalidArgumentException;
use IteratorAggregate;
use function assert;
use function strlen as stringLength;
use function substr;
use const PHP_MINOR_VERSION;
use const PHP_RELEASE_VERSION as PHP_PATCH_VERSION;
use const PHP_VERSION;
/**
* Description
*/
class Example implements IteratorAggregate
{
private const VERSION = PHP_VERSION - (PHP_MINOR_VERSION * 100) - PHP_PATCH_VERSION;
private ControlStructureSniff|int|string|null $baxBax = null;
public function __construct(private int|null $foo = null, private array $bar = [], private bool $baz = false, $baxBax = 'unused')
{
$this->baxBax = $baxBax;
}
/**
* Description
*/
public function getFoo(): int|null
{
return $this->foo;
}
/** @return iterable */
public function getIterator(): array
{
assert($this->bar !== null);
return new ArrayIterator($this->bar);
}
public function isBaz(): bool
{
[$foo, $bar, $baz] = $this->bar;
return $this->baz;
}
/** @throws InvalidArgumentException if this example cannot baz. */
public function mangleBar(int $length): void
{
if (! $this->baz) {
throw new InvalidArgumentException();
}
$this->bar = (string) $this->baxBax ?? substr($this->bar, stringLength($this->bar - $length));
}
public static function getMinorVersion(): int
{
return self::VERSION;
}
public static function getTestCase(): TestCase
{
return new TestCase();
}
}