filter() public static method

public static filter ( $traversable, callable $predicate ) : array
$traversable
$predicate callable
return array
Example #1
0
 /**
  * Return implementations of `type` that include `fieldName` as a valid field.
  *
  * @param Schema $schema
  * @param AbstractType $type
  * @param $fieldName
  * @return array
  */
 static function getImplementationsIncludingField(Schema $schema, AbstractType $type, $fieldName)
 {
     $types = $schema->getPossibleTypes($type);
     $types = Utils::filter($types, function ($t) use($fieldName) {
         return isset($t->getFields()[$fieldName]);
     });
     $types = Utils::map($types, function ($t) {
         return $t->name;
     });
     sort($types);
     return $types;
 }
 public function __invoke(ValidationContext $context)
 {
     $operationCount = 0;
     return [NodeKind::DOCUMENT => function (DocumentNode $node) use(&$operationCount) {
         $tmp = Utils::filter($node->definitions, function ($definition) {
             return $definition->kind === NodeKind::OPERATION_DEFINITION;
         });
         $operationCount = count($tmp);
     }, NodeKind::OPERATION_DEFINITION => function (OperationDefinitionNode $node) use(&$operationCount, $context) {
         if (!$node->name && $operationCount > 1) {
             $context->reportError(new Error(self::anonOperationNotAloneMessage(), [$node]));
         }
     }];
 }