Skip to content

Commit b144c27

Browse files
committed
fix: style
1 parent 3800a52 commit b144c27

3 files changed

Lines changed: 31 additions & 28 deletions

File tree

src/PHPDraft/In/CLI.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
class CLI extends BaseCLI
1414
{
15-
1615
protected function setup(Options $options): void
1716
{
1817
$options->setHelp('Usage: phpdraft [options]');
@@ -37,31 +36,30 @@ protected function setup(Options $options): void
3736
protected function main(Options $options): void
3837
{
3938
$args = $options->getOpt();
40-
if ($options->getOpt('version') !== FALSE) {
39+
if ($options->getOpt('version') !== false) {
4140
Version::version();
4241
throw new ExecutionException('', 0);
4342
}
4443

4544
stream_set_blocking(STDIN, false);
4645
/** @var false|string $stdin */
4746
$stdin = stream_get_contents(STDIN);
48-
$tmp_file_name = NULL;
49-
if ($stdin !== FALSE && $stdin !== '') {
47+
$tmp_file_name = null;
48+
if ($stdin !== false && $stdin !== '') {
5049
$tmp_file_name = tempnam(sys_get_temp_dir(), 'phpdraft');
5150
file_put_contents($tmp_file_name, $stdin);
5251
}
5352
/** @var false|string $file_name */
5453
$file_name = $options->getOpt('file');
55-
if ($tmp_file_name !== NULL && $file_name !== FALSE) {
54+
if ($tmp_file_name !== null && $file_name !== false) {
5655
throw new ExecutionException('ERROR: Passed data in both file and stdin', 2);
5756
}
5857

59-
if (!($options->getOpt('debug-json-file') === FALSE || $options->getOpt('debug-json') === FALSE || $file_name !== FALSE)) {
58+
if (!($options->getOpt('debug-json-file') === false || $options->getOpt('debug-json') === false || $file_name !== false)) {
6059
throw new ExecutionException('Missing required option: file', 1);
6160
}
6261

63-
if ($file_name === FALSE || $file_name === '')
64-
{
62+
if ($file_name === false || $file_name === '') {
6563
throw new ExecutionException('ERROR: File does not exist', 200);
6664
}
6765

@@ -95,14 +93,14 @@ protected function main(Options $options): void
9593
$name = 'PHPD_SORT_' . strtoupper($options->getOpt('sort', ''));
9694
$html->sorting = defined("Sorting::$name") ? Sorting::{$name} : Sorting::PHPD_SORT_NONE->value;
9795

98-
$color1 = getenv('COLOR_PRIMARY') === FALSE ? NULL : getenv('COLOR_PRIMARY');
99-
$color2 = getenv('COLOR_SECONDARY') === FALSE ? NULL : getenv('COLOR_SECONDARY');
96+
$color1 = getenv('COLOR_PRIMARY') === false ? null : getenv('COLOR_PRIMARY');
97+
$color2 = getenv('COLOR_SECONDARY') === false ? null : getenv('COLOR_SECONDARY');
10098
$colors = (is_null($color1) || is_null($color2)) ? '' : '__' . $color1 . '__' . $color2;
10199
$html->build_html(
102100
$options->getOpt('template', 'default') . $colors,
103-
$args['header-image'] ?? NULL,
104-
$args['css'] ?? NULL,
105-
$args['javascript'] ?? NULL,
101+
$args['header-image'] ?? null,
102+
$args['css'] ?? null,
103+
$args['javascript'] ?? null,
106104
);
107105

108106
if (isset($args['html'])) {
@@ -112,4 +110,4 @@ protected function main(Options $options): void
112110

113111
echo $html;
114112
}
115-
}
113+
}

src/PHPDraft/Out/OpenAPI/OpenApiRenderer.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class OpenApiRenderer extends BaseTemplateRenderer
1414
{
15-
const NO_DESCRIPTION_PROVIDED = 'No description provided';
15+
private const NO_DESCRIPTION_PROVIDED = 'No description provided';
1616

1717
public function init(object $json): self
1818
{
@@ -131,24 +131,26 @@ private function getPaths(): object
131131
}
132132
$cleaned_href = preg_replace('/{\?.*}/', '', $transition->href);
133133
$cleaned_href = rtrim($cleaned_href, "/");
134-
$optional_paths = array_filter($parameters, fn ($parameter) => $parameter['in'] === 'path' && $parameter['required'] === FALSE);
134+
$optional_paths = array_filter($parameters, fn ($parameter) => $parameter['in'] === 'path' && $parameter['required'] === false);
135135
if ($optional_paths === []) {
136136
$return[$cleaned_href] = (object) $transition_return;
137137
continue;
138138
}
139139

140140
$cleaned_parameters = [];
141-
$optional_href = NULL;
141+
$optional_href = null;
142142
foreach ($parameters as $key => $parameter) {
143-
if ($parameter['in'] === 'path' && $parameter['required'] === TRUE) {
143+
if ($parameter['in'] === 'path' && $parameter['required'] === true) {
144144
$cleaned_parameters[] = $parameter;
145145
continue;
146146
}
147147

148-
if ($parameter['in'] !== 'path') { continue; }
148+
if ($parameter['in'] !== 'path') {
149+
continue;
150+
}
149151

150152
$optional_href = str_replace("/{{$parameter["name"]}}", '', $cleaned_href);
151-
$parameters[$key]['required'] = TRUE;
153+
$parameters[$key]['required'] = true;
152154
}
153155

154156
//Full path
@@ -230,7 +232,7 @@ private function toOperation(HTTPRequest $request, Transition $transition, array
230232
}
231233

232234
$body = $this->toBody($request);
233-
if ($body === NULL) {
235+
if ($body === null) {
234236
return $operation;
235237
}
236238

@@ -363,7 +365,7 @@ private function toResponses(array $responses): array
363365
private function toBody(HTTPRequest $request): ?array
364366
{
365367
if (in_array($request->method, ['GET', 'DELETE'], true)) {
366-
return NULL;
368+
return null;
367369
}
368370

369371
$return = ['content' => []];
@@ -446,7 +448,8 @@ private function getComponent(BasicStructureElement $structure): array
446448
{
447449
$object = [];
448450
if ($this->isRef($structure->element) && $structure->element !== 'enum') {
449-
$object['$ref'] = '#/components/schemas/' . $this->refIdFromType($structure->element === 'member' ? $structure->type : $structure->element);;
451+
$object['$ref'] = '#/components/schemas/' . $this->refIdFromType($structure->element === 'member' ? $structure->type : $structure->element);
452+
;
450453
return $object;
451454
}
452455

@@ -471,7 +474,8 @@ private function getComponent(BasicStructureElement $structure): array
471474
case 'enum':
472475
// $object['type'] = $structure->type;;
473476
case 'array':
474-
$object['items'] = (object) $properties;;
477+
$object['items'] = (object) $properties;
478+
;
475479
break;
476480
case 'object':
477481
$object['properties'] = $properties;
@@ -544,7 +548,8 @@ private function getSchemaProperty(BasicStructureElement|ElementStructureElement
544548
return $propery_data;
545549
} elseif ($value->type === 'object') {
546550
$propery_data['type'] = $value->type;
547-
$propery_data['properties'] = $this->getComponent($value->value)['properties'] ?? new class{};
551+
$propery_data['properties'] = $this->getComponent($value->value)['properties'] ?? new class {
552+
};
548553

549554
return $propery_data;
550555
}
@@ -590,8 +595,8 @@ private function getTags(): array
590595
return $return;
591596
}
592597

593-
private function refIdFromType(string $type): string {
598+
private function refIdFromType(string $type): string
599+
{
594600
return str_replace(' ', '_', $type);
595601
}
596-
597602
}

src/PHPDraft/Out/OpenAPI/Tests/OpenApiRendererTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function testToBody(): void
117117
$result = $method->invokeArgs($this->class, [$mock]);
118118

119119
$this->assertEquals(['content' => (object)[],
120-
'description' => 'No description provided'], $result);
120+
'description' => 'No description provided'], $result);
121121
}
122122

123123
public function testToParameters(): void

0 commit comments

Comments
 (0)