Skip to content

Commit 465fc59

Browse files
authored
Polish (#21)
1 parent 5524edc commit 465fc59

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/App/Helper/TypeGuesser.php

+22-8
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,12 @@ private function isAbstractType(TypeDoc $doc) : bool
116116
private function guessPrimaryTypeFromConstraint(Constraint $constraint) : ?TypeDoc
117117
{
118118
// Try to guess primary types
119-
if (null !== $this->getMatchingClassNameIn($constraint, self::STRING_CONSTRAINT_CLASS_LIST)) {
120-
return new StringDoc();
121-
} elseif (null !== $this->getMatchingClassNameIn($constraint, self::BOOLEAN_CONSTRAINT_CLASS_LIST)) {
122-
return new BooleanDoc();
119+
if (null !== ($type = $this->guessSimplePrimaryTypeFromConstraint($constraint))) {
120+
return $type;
123121
} elseif ($constraint instanceof Assert\DateTime) {
124122
return $this->guessDateTimeType($constraint);
125123
} elseif ($constraint instanceof Assert\Collection) {
126124
return $this->guestCollectionType($constraint);
127-
} elseif ($constraint instanceof Assert\Regex) {
128-
return new ScalarDoc();
129-
} elseif ($this->isArrayConstraint($constraint)) {
130-
return new ArrayDoc();
131125
}
132126

133127
return null;
@@ -175,4 +169,24 @@ private function isArrayConstraint(Constraint $constraint): bool
175169
&& true === $constraint->multiple // << expect an array multiple choices
176170
);
177171
}
172+
173+
/**
174+
* @param Constraint $constraint
175+
*
176+
* @return TypeDoc|null
177+
*/
178+
private function guessSimplePrimaryTypeFromConstraint(Constraint $constraint) : ?TypeDoc
179+
{
180+
if (null !== $this->getMatchingClassNameIn($constraint, self::STRING_CONSTRAINT_CLASS_LIST)) {
181+
return new StringDoc();
182+
} elseif (null !== $this->getMatchingClassNameIn($constraint, self::BOOLEAN_CONSTRAINT_CLASS_LIST)) {
183+
return new BooleanDoc();
184+
} elseif ($constraint instanceof Assert\Regex) {
185+
return new ScalarDoc();
186+
} elseif ($this->isArrayConstraint($constraint)) {
187+
return new ArrayDoc();
188+
}
189+
190+
return null;
191+
}
178192
}

0 commit comments

Comments
 (0)