Skip to content

Commit 99792d1

Browse files
committed
Fix uncovered code errors from Travis
1 parent b31c7bf commit 99792d1

File tree

6 files changed

+26
-28
lines changed

6 files changed

+26
-28
lines changed

src/ExpressionLanguage/ExpressionLanguage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@ public static function unprefixExpression(string $expression)
9090
{
9191
$string = \substr($expression, \strlen(self::EXPRESSION_TRIGGER));
9292

93-
return $string ?: $expression;
93+
return '' !== $string ? $string : $expression;
9494
}
9595
}

src/Generator/TypeBuilder.php

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected function wrapTypeRecursive($typeNode)
136136
$type = Literal::new("Type::listOf($innerType)");
137137
$this->file->addUse(Type::class);
138138
break;
139-
case NodeKind::NAMED_TYPE:
139+
default:
140140
if (\in_array($typeNode->name->value, self::BUILT_IN_TYPES)) {
141141
$name = \strtolower($typeNode->name->value);
142142
$type = Literal::new("Type::$name()");
@@ -146,7 +146,6 @@ protected function wrapTypeRecursive($typeNode)
146146
$type = "$this->globalVars->get('typeResolver')->resolve('$name')";
147147
}
148148
break;
149-
default: throw new RuntimeException('Unrecognized node kind.');
150149
}
151150

152151
return $type;
@@ -325,8 +324,6 @@ protected function buildValidator(Closure $closure, array $mapping, bool $inject
325324

326325
if (!empty($mapping['properties'])) {
327326
$validator->addArgument($this->buildProperties($mapping['properties']));
328-
} else {
329-
$validator->addArgument([]);
330327
}
331328

332329
if (!empty($mapping['class'])) {
@@ -450,10 +447,6 @@ protected function buildConstraints(array $constraints = [])
450447
*/
451448
protected function buildCascade(array $cascade)
452449
{
453-
if (empty($cascade)) {
454-
return null;
455-
}
456-
457450
/**
458451
* @var string $referenceType
459452
* @var array $groups
@@ -605,24 +598,34 @@ protected function buildComplexity($complexity)
605598
;
606599
}
607600

608-
return ArrowFunction::new()
609-
->addArgument('childrenComplexity')
610-
->setExpression(Literal::new($expression));
601+
$arrow = ArrowFunction::new(\is_string($expression) ? new Literal($expression) : $expression);
602+
603+
if (ExpressionLanguage::expressionContainsVar('childrenComplexity', $complexity)) {
604+
$arrow->addArgument('childrenComplexity');
605+
}
606+
607+
return $arrow;
611608
}
612609

613-
return $complexity;
610+
return new ArrowFunction(0);
614611
}
615612

616613
protected function buildPublic($public)
617614
{
618615
if ($this->expressionConverter->check($public)) {
619616
$expression = $this->expressionConverter->convert($public);
617+
$arrow = ArrowFunction::new(Literal::new($expression));
620618

621-
return ArrowFunction::new()
622-
->addArgument('fieldName')
623-
->addArgument('typeName', '', new Literal('self::NAME'))
624-
->setExpression(Literal::new($expression))
625-
;
619+
if (ExpressionLanguage::expressionContainsVar('fieldName', $public)) {
620+
$arrow->addArgument('fieldName');
621+
}
622+
623+
if (ExpressionLanguage::expressionContainsVar('typeName', $public)) {
624+
$arrow->addArgument('fieldName');
625+
$arrow->addArgument('typeName', '', new Literal('self::NAME'));
626+
}
627+
628+
return $arrow;
626629
}
627630

628631
return $public;

src/Validator/InputValidator.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,6 @@ protected function buildValidationTree(ValidationNode $rootObject, array $proper
149149
$this->restructureShortForm($params);
150150

151151
foreach ($params ?? [] as $key => $value) {
152-
if (null === $value) {
153-
continue;
154-
}
155-
156152
switch ($key) {
157153
case 'link':
158154
[$fqcn, $property, $type] = $value;
@@ -233,10 +229,6 @@ private function applyClassConstraints(ObjectMetadata $metadata, array $rules):
233229
$this->restructureShortForm($rules);
234230

235231
foreach ($rules as $key => $value) {
236-
if (null === $value) {
237-
continue;
238-
}
239-
240232
switch ($key) {
241233
case 'link':
242234
$linkedMetadata = $this->validator->getMetadataFor($value);

tests/Functional/App/Mutation/InputValidatorMutation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class InputValidatorMutation implements MutationInterface
2323
public function mutationMock(Argument $args, ?InputValidator $validator = null): bool
2424
{
2525
if (null !== $validator) {
26-
$validator->validate($args['groups']);
26+
$validator($args['groups']);
2727
}
2828

2929
return true;

tests/Functional/App/config/customScalar/mapping/Query.types.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ DateTime:
44
description: "The DateTime type"
55
serialize: ['Overblog\GraphQLBundle\Tests\Functional\Type\DateTimeType', "serialize"]
66
parseValue: ['Overblog\GraphQLBundle\Tests\Functional\Type\DateTimeType', "parseValue"]
7-
parseLiteral: ['Overblog\GraphQLBundle\Tests\Functional\Type\DateTimeType', "parseLiteral"]
7+
parseLiteral: 'Overblog\GraphQLBundle\Tests\Functional\Type\DateTimeType::parseLiteral'
88

99
Query:
1010
type: object

tests/Functional/App/config/validator/mapping/Mutation.types.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ Mutation:
33
config:
44
fields:
55
noValidation:
6+
complexity: 1
7+
public: true
68
type: Boolean
79
resolve: "@=mut('no_validation')"
810
args:
911
username:
1012
type: String!
13+
defaultValue: 'Frank'
1114
validation: ~
1215

1316
simpleValidation:

0 commit comments

Comments
 (0)