Skip to content

Commit d8b5811

Browse files
Merge pull request #17338 from mauriciofauth/display-parts-vo
Create the `PhpMyAdmin\Display\DisplayParts` class
2 parents 10d09f4 + dca5b1b commit d8b5811

7 files changed

Lines changed: 365 additions & 321 deletions

File tree

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Display;
6+
7+
/**
8+
* @psalm-immutable
9+
*/
10+
final class DisplayParts
11+
{
12+
public const NO_DELETE = 0;
13+
public const DELETE_ROW = 1;
14+
public const KILL_PROCESS = 2;
15+
16+
/** @var bool */
17+
public $hasEditLink;
18+
19+
/**
20+
* @var int
21+
* @psalm-var self::NO_DELETE|self::DELETE_ROW|self::KILL_PROCESS
22+
*/
23+
public $deleteLink;
24+
25+
/** @var bool */
26+
public $hasSortLink;
27+
28+
/** @var bool */
29+
public $hasNavigationBar;
30+
31+
/** @var bool */
32+
public $hasBookmarkForm;
33+
34+
/** @var bool */
35+
public $hasTextButton;
36+
37+
/** @var bool */
38+
public $hasPrintLink;
39+
40+
/**
41+
* @psalm-param self::NO_DELETE|self::DELETE_ROW|self::KILL_PROCESS $deleteLink
42+
*/
43+
private function __construct(
44+
bool $hasEditLink,
45+
int $deleteLink,
46+
bool $hasSortLink,
47+
bool $hasNavigationBar,
48+
bool $hasBookmarkForm,
49+
bool $hasTextButton,
50+
bool $hasPrintLink
51+
) {
52+
$this->hasEditLink = $hasEditLink;
53+
$this->deleteLink = $deleteLink;
54+
$this->hasSortLink = $hasSortLink;
55+
$this->hasNavigationBar = $hasNavigationBar;
56+
$this->hasBookmarkForm = $hasBookmarkForm;
57+
$this->hasTextButton = $hasTextButton;
58+
$this->hasPrintLink = $hasPrintLink;
59+
}
60+
61+
/**
62+
* @param array<string, bool|int> $parts
63+
* @psalm-param array{
64+
* hasEditLink?: bool,
65+
* deleteLink?: self::NO_DELETE|self::DELETE_ROW|self::KILL_PROCESS,
66+
* hasSortLink?: bool,
67+
* hasNavigationBar?: bool,
68+
* hasBookmarkForm?: bool,
69+
* hasTextButton?: bool,
70+
* hasPrintLink?: bool
71+
* } $parts
72+
*/
73+
public static function fromArray(array $parts): self
74+
{
75+
return new self(
76+
$parts['hasEditLink'] ?? false,
77+
$parts['deleteLink'] ?? self::NO_DELETE,
78+
$parts['hasSortLink'] ?? false,
79+
$parts['hasNavigationBar'] ?? false,
80+
$parts['hasBookmarkForm'] ?? false,
81+
$parts['hasTextButton'] ?? false,
82+
$parts['hasPrintLink'] ?? false
83+
);
84+
}
85+
86+
/**
87+
* @param array<string, bool|int> $parts
88+
* @psalm-param array{
89+
* hasEditLink?: bool,
90+
* deleteLink?: self::NO_DELETE|self::DELETE_ROW|self::KILL_PROCESS,
91+
* hasSortLink?: bool,
92+
* hasNavigationBar?: bool,
93+
* hasBookmarkForm?: bool,
94+
* hasTextButton?: bool,
95+
* hasPrintLink?: bool
96+
* } $parts
97+
*/
98+
public function with(array $parts): self
99+
{
100+
return new self(
101+
$parts['hasEditLink'] ?? $this->hasEditLink,
102+
$parts['deleteLink'] ?? $this->deleteLink,
103+
$parts['hasSortLink'] ?? $this->hasSortLink,
104+
$parts['hasNavigationBar'] ?? $this->hasNavigationBar,
105+
$parts['hasBookmarkForm'] ?? $this->hasBookmarkForm,
106+
$parts['hasTextButton'] ?? $this->hasTextButton,
107+
$parts['hasPrintLink'] ?? $this->hasPrintLink
108+
);
109+
}
110+
}

0 commit comments

Comments
 (0)