Skip to content

Commit 039ed68

Browse files
authored
fix: enum types (#466)
1 parent 7982a87 commit 039ed68

10 files changed

+18
-25
lines changed

phpdraft

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ try
9292

9393
$html = ParserFactory::getJson()->init($data);
9494
$name = 'PHPD_SORT_' . strtoupper($args->getOpt('sort', ''));
95-
$html->sorting = Sorting::${$name} ?? -1;
95+
$html->sorting = Sorting::${$name} ?? Sorting::PHPD_SORT_NONE->value;
9696

9797
$color1 = getenv('COLOR_PRIMARY') === FALSE ? NULL : getenv('COLOR_PRIMARY');
9898
$color2 = getenv('COLOR_SECONDARY') === FALSE ? NULL : getenv('COLOR_SECONDARY');

src/PHPDraft/Model/Elements/ArrayStructureElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function __toString(): string
8080
*
8181
* @return self
8282
*/
83-
protected function new_instance(): StructureElement
83+
protected function new_instance(): self
8484
{
8585
return new self();
8686
}

src/PHPDraft/Model/Elements/BasicStructureElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ abstract public function __toString(): string;
8989
*
9090
* @return self
9191
*/
92-
abstract protected function new_instance(): StructureElement;
92+
abstract protected function new_instance(): self;
9393

9494
/**
9595
* Parse common fields to give context.

src/PHPDraft/Model/Elements/EnumStructureElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function __toString(): string
9999
*
100100
* @return self
101101
*/
102-
protected function new_instance(): StructureElement
102+
protected function new_instance(): self
103103
{
104104
return new self();
105105
}

src/PHPDraft/Model/Elements/ObjectStructureElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected function parse_value_structure(object $object, array &$dependencies)
109109
*
110110
* @return ObjectStructureElement
111111
*/
112-
protected function new_instance(): StructureElement
112+
protected function new_instance(): self
113113
{
114114
return new self();
115115
}

src/PHPDraft/Model/Elements/RequestBodyElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function print_request(?string $type = 'application/x-www-form-urlencoded
6363
*
6464
* @return RequestBodyElement
6565
*/
66-
protected function new_instance(): StructureElement
66+
protected function new_instance(): self
6767
{
6868
return new self();
6969
}

src/PHPDraft/Out/Sorting.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,27 @@
1515
/**
1616
* Sorting constants.
1717
*/
18-
class Sorting
18+
enum Sorting: int
1919
{
2020
/**
2121
* Sets sorting to all parts.
22-
*
23-
* @var int
2422
*/
25-
public const PHPD_SORT_ALL = 3;
23+
case PHPD_SORT_ALL = 3;
2624

2725
/**
2826
* Sets sorting to all webservices.
29-
*
30-
* @var int
3127
*/
32-
public const PHPD_SORT_WEBSERVICES = 2;
28+
case PHPD_SORT_WEBSERVICES = 2;
3329

3430
/**
3531
* Sets sorting to all data structures.
36-
*
37-
* @var int
3832
*/
39-
public const PHPD_SORT_STRUCTURES = 1;
33+
case PHPD_SORT_STRUCTURES = 1;
4034

4135
/**
4236
* Sets sorting to no data structures.
43-
*
44-
* @var int
4537
*/
46-
public const PHPD_SORT_NONE = -1;
38+
case PHPD_SORT_NONE = -1;
4739

4840
/**
4941
* Check if structures should be sorted.
@@ -54,7 +46,7 @@ class Sorting
5446
*/
5547
public static function sortStructures(int $sort): bool
5648
{
57-
return $sort === self::PHPD_SORT_ALL || $sort === self::PHPD_SORT_STRUCTURES;
49+
return $sort === Sorting::PHPD_SORT_ALL->value || $sort === Sorting::PHPD_SORT_STRUCTURES->value;
5850
}
5951

6052
/**
@@ -66,6 +58,6 @@ public static function sortStructures(int $sort): bool
6658
*/
6759
public static function sortServices(int $sort): bool
6860
{
69-
return $sort === self::PHPD_SORT_ALL || $sort === self::PHPD_SORT_WEBSERVICES;
61+
return $sort === Sorting::PHPD_SORT_ALL->value || $sort === Sorting::PHPD_SORT_WEBSERVICES->value;
7062
}
7163
}

src/PHPDraft/Out/TemplateRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(string $template, ?string $image)
4343
$this->base_data['COLOR_1'] = $template_parts[1] ?? 'green';
4444
$this->base_data['COLOR_2'] = $template_parts[2] ?? 'light_green';
4545
$this->image = $image;
46-
$this->sorting = Sorting::PHPD_SORT_NONE;
46+
$this->sorting = Sorting::PHPD_SORT_NONE->value;
4747
}
4848

4949
/**

src/PHPDraft/Parse/BaseHtmlGenerator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414

1515
use PHPDraft\Out\BaseTemplateRenderer;
1616
use stdClass;
17+
use \Stringable;
1718

18-
abstract class BaseHtmlGenerator
19+
abstract class BaseHtmlGenerator implements Stringable
1920
{
2021
/**
2122
* Type of sorting to do.
@@ -72,5 +73,5 @@ abstract public function build_html(string $template = 'default', ?string $image
7273
*
7374
* @return string
7475
*/
75-
abstract public function __toString();
76+
abstract public function __toString(): string;
7677
}

src/PHPDraft/Parse/HtmlGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function build_html(string $template = 'default', ?string $image = null,
5656
*
5757
* @return string
5858
*/
59-
public function __toString()
59+
public function __toString(): string
6060
{
6161
return $this->html;
6262
}

0 commit comments

Comments
 (0)