for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Youshido\Tests\Issues\Issue109;
use Youshido\GraphQL\Config\Schema\SchemaConfig;
use Youshido\GraphQL\Execution\ResolveInfo;
use Youshido\GraphQL\Schema\AbstractSchema;
use Youshido\GraphQL\Type\ListType\ListType;
use Youshido\GraphQL\Type\Object\ObjectType;
use Youshido\GraphQL\Type\Scalar\IntType;
class Issue109Schema extends AbstractSchema
{
public function build(SchemaConfig $config)
$config->setQuery(
new ObjectType([
'name' => 'RootQueryType',
'fields' => [
'latestPost' => [
'type' => new ObjectType([
'name' => 'Post',
'id' => [
'type' => new IntType(),
'args' => [
'comment_id' => new IntType()
]
],
'comments' => [
'type' => new ListType(new ObjectType([
'name' => 'Comment',
])),
]),
'resolve' => function ($source, array $args, ResolveInfo $info) {
$internalArgs = [
'comment_id' => 200
];
if ($field = $info->getFieldAST('comments')->hasArguments()) {
$field
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
$myVar = 'Value'; $higher = false; if (rand(1, 6) > 3) { $higher = true; } else { $higher = false; }
Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.
$myVar
$higher
$internalArgs['comment_id'] = $info->getFieldAST('comments')->getArgumentValue('comment_id');
}
return [
"id" => 1,
"title" => "New approach in API has been revealed",
"summary" => "In two words - GraphQL Rocks!",
"comments" => [
[
"comment_id" => $internalArgs['comment_id']
},
'id' => new IntType()
])
);
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.