Skip to content

Commit 13e7c9b

Browse files
committed
fixed the email parsing in examples
1 parent 4b1e721 commit 13e7c9b

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

src/Extractor/Extractor.php

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public static function buildDefinitionProperty($name, $type, $description, $path
107107

108108
if (null !== $arrayof) {
109109
$property['items'] = ['type' => $arrayof];
110-
} else if ('array' === $type && 'payment_options' === $name) {
110+
} elseif ('array' === $type && 'payment_options' === $name) {
111111
$property['items'] = [
112112
'type' => 'string',
113113
'enum' => [
@@ -399,6 +399,8 @@ public static function buildPath($url, $path, $method, $node, $title)
399399
{
400400
$description = [];
401401
$parentNode = $node->ancestors()->filter('.highlighter-rouge')->first();
402+
$summary = '';
403+
$summaryId = '';
402404

403405
foreach ($parentNode->previousAll() as $previous) {
404406
if ('h2' === $previous->tagName) {
@@ -442,6 +444,7 @@ public static function buildPath($url, $path, $method, $node, $title)
442444
}
443445

444446
if ('figure' === $next->tagName) {
447+
$next = self::decodeEmailAddresses($next);
445448
$example = $next->textContent;
446449
break;
447450
}
@@ -526,7 +529,7 @@ public static function buildRequestBody($method, $path, $explicitParameters, $ex
526529

527530
if ('required' === $required) {
528531
$requiredProperties[] = $parameter;
529-
} else if (!\in_array($required, ['optional', 'required'])) {
532+
} elseif (!\in_array($required, ['optional', 'required'], true)) {
530533
$description = $required;
531534
}
532535
}
@@ -801,7 +804,7 @@ public static function guessPathResponseSchema($summary, $title)
801804

802805
public static function guessPathResponseStatus($method, $summary)
803806
{
804-
if (0 === strpos($summary, 'Create a')) {
807+
if (str_starts_with($summary, 'Create a')) {
805808
return 201;
806809
}
807810

@@ -870,7 +873,7 @@ private function printOperationsIdList()
870873
echo " * $family\n";
871874

872875
foreach ($familyOperations as $operation) {
873-
echo " * $operation\n";
876+
echo " * `$operation()`\n";
874877
}
875878
}
876879
}
@@ -912,14 +915,51 @@ private static function cleanupSummary($summary)
912915
return isset($summaries[$summary]) ? $summaries[$summary] : $summary;
913916
}
914917

918+
private static function getPower(string $email, int $position): int
919+
{
920+
$char = substr($email, $position, 2);
921+
922+
return \intval($char, 16);
923+
}
924+
925+
private static function decodeEmailAddress(string $email): string
926+
{
927+
$output = '';
928+
$power = self::getPower($email, 0);
929+
$i = 2;
930+
931+
while ($i < \strlen($email)) {
932+
$char = self::getPower($email, $i) ^ $power;
933+
$output .= \chr($char);
934+
$i += 2;
935+
}
936+
937+
return $output;
938+
}
939+
940+
private static function decodeEmailAddresses(\DOMElement $next)
941+
{
942+
foreach ($next->childNodes as $child) {
943+
if ($child instanceof \DOMElement) {
944+
if ('a' === $child->tagName && $child->hasAttribute('data-cfemail')) {
945+
$child->textContent = self::decodeEmailAddress($child->getAttribute('data-cfemail'));
946+
}
947+
948+
$child = self::decodeEmailAddresses($child);
949+
}
950+
}
951+
952+
return $next;
953+
}
954+
915955
private function buildItemsTypes()
916956
{
917957
foreach ($this->definitions as $definitionName => $definition) {
918958
foreach ($definition['properties'] as $propertyName => $property) {
919959
if (isset($property['items']) && isset($property['items']['type'])) {
920960
if (isset($this->definitions[$property['items']['type']])) {
921961
$this->definitions[$definitionName]['properties'][$propertyName]['items'] = ['$ref' => '#/components/schemas/'.$property['items']['type']];
922-
} else if (!\in_array($property['items']['type'], self::BASE_TYPES, true)) {
962+
} elseif (!\in_array($property['items']['type'], self::BASE_TYPES, true)) {
923963
echo $property['items']['type']."\n";
924964
}
925965
}

0 commit comments

Comments
 (0)