From 180ac1b629c750f1d34292252803ff93cd28489d Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Fri, 22 Apr 2022 15:18:21 +1200 Subject: [PATCH] ENH PHP 8.1 compatibility --- src/Auth/BasicAuthAuthenticator.php | 2 +- src/Controller.php | 10 +++---- src/FieldCreator.php | 2 +- src/InterfaceTypeCreator.php | 2 +- src/Manager.php | 26 +++++++++---------- src/Middleware/CSRFMiddleware.php | 6 ++--- src/Middleware/HTTPMethodMiddleware.php | 2 +- src/Pagination/Connection.php | 2 +- src/Pagination/SortInputTypeCreator.php | 4 +-- src/PersistedQuery/FileProvider.php | 6 ++--- src/PersistedQuery/GuzzleHTTPClient.php | 2 +- src/PersistedQuery/HTTPProvider.php | 4 +-- src/PersistedQuery/JSONStringProvider.php | 4 +-- src/QueryFilter/DataObjectQueryFilter.php | 18 ++++++------- src/QueryFilter/FieldFilterRegistry.php | 2 +- src/Scaffolding/Scaffolders/CRUD/Create.php | 4 +-- src/Scaffolding/Scaffolders/CRUD/Delete.php | 4 +-- src/Scaffolding/Scaffolders/CRUD/Read.php | 6 ++--- src/Scaffolding/Scaffolders/CRUD/ReadOne.php | 4 +-- src/Scaffolding/Scaffolders/CRUD/Update.php | 4 +-- .../Scaffolders/DataObjectScaffolder.php | 6 ++--- .../Scaffolders/InheritanceScaffolder.php | 6 ++--- .../Scaffolders/OperationScaffolder.php | 6 ++--- .../Scaffolders/SchemaScaffolder.php | 2 +- .../Scaffolders/UnionScaffolder.php | 4 +-- src/Scaffolding/StaticSchema.php | 22 ++++++++-------- .../Traits/DataObjectTypeTrait.php | 2 +- src/Scaffolding/Util/OperationList.php | 2 +- src/Scaffolding/Util/StringTypeParser.php | 6 ++--- src/TypeCreator.php | 6 ++--- src/Util/CaseInsensitiveFieldAccessor.php | 6 ++--- tests/ControllerTest.php | 12 ++++----- tests/Fake/FakeFieldAccessor.php | 4 +-- .../Scaffolders/CRUD/CreateTest.php | 2 +- .../Scaffolders/CRUD/DeleteTest.php | 2 +- .../Scaffolders/CRUD/ReadOneTest.php | 2 +- .../Scaffolders/CRUD/UpdateTest.php | 2 +- .../Scaffolders/DataObjectScaffolderTest.php | 2 +- .../Scaffolders/InheritanceScaffolderTest.php | 2 +- .../Scaffolders/OperationScaffolderTest.php | 4 +-- .../Scaffolders/SchemaScaffolderTest.php | 10 +++---- tests/TypeCreatorTest.php | 4 +-- 42 files changed, 114 insertions(+), 114 deletions(-) diff --git a/src/Auth/BasicAuthAuthenticator.php b/src/Auth/BasicAuthAuthenticator.php index de86879f4..80b65976f 100644 --- a/src/Auth/BasicAuthAuthenticator.php +++ b/src/Auth/BasicAuthAuthenticator.php @@ -44,6 +44,6 @@ public function isApplicable(HTTPRequest $request) */ protected function hasAuthHandler($servervar) { - return isset($_SERVER[$servervar]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$servervar]); + return isset($_SERVER[$servervar]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$servervar] ?? ''); } } diff --git a/src/Controller.php b/src/Controller.php index 7abf0d25e..e6dd664b1 100644 --- a/src/Controller.php +++ b/src/Controller.php @@ -298,7 +298,7 @@ protected function validateOrigin($origin, $allowedOrigins) if ($allowedOrigin === '*') { return true; } - if (strcasecmp($allowedOrigin, $origin) === 0) { + if (strcasecmp($allowedOrigin ?? '', $origin ?? '') === 0) { return true; } } @@ -347,7 +347,7 @@ protected function getRequestOrigin(HTTPRequest $request) $referer = $request->getHeader('Referer'); if ($referer) { // Extract protocol, hostname, and port - $refererParts = parse_url($referer); + $refererParts = parse_url($referer ?? ''); if (!$refererParts) { return null; } @@ -394,7 +394,7 @@ protected function handleOptions(HTTPRequest $request) protected function getRequestQueryVariables(HTTPRequest $request) { $contentType = $request->getHeader('content-type'); - $isJson = preg_match('#^application/json\b#', $contentType); + $isJson = preg_match('#^application/json\b#', $contentType ?? ''); if ($isJson) { $rawBody = $request->getBody(); $data = json_decode($rawBody ?: '', true); @@ -404,7 +404,7 @@ protected function getRequestQueryVariables(HTTPRequest $request) } else { $query = $request->requestVar('query'); $id = $request->requestVar('id'); - $variables = json_decode($request->requestVar('variables'), true); + $variables = json_decode($request->requestVar('variables') ?? '', true); } if ($id) { @@ -515,7 +515,7 @@ public static function flush() $routes = Director::config()->get('rules'); foreach ($routes as $pattern => $controllerInfo) { $routeClass = (is_string($controllerInfo)) ? $controllerInfo : $controllerInfo['Controller']; - if (stristr($routeClass, Controller::class) !== false) { + if (stristr($routeClass ?? '', Controller::class) !== false) { try { $inst = Injector::inst()->convertServiceProperty($routeClass); if ($inst instanceof Controller) { diff --git a/src/FieldCreator.php b/src/FieldCreator.php index c0aaa6f87..ad2de7da4 100644 --- a/src/FieldCreator.php +++ b/src/FieldCreator.php @@ -147,7 +147,7 @@ protected function getResolver() return function () use ($resolver) { $args = func_get_args(); - $result = call_user_func_array($resolver, $args); + $result = call_user_func_array($resolver, $args ?? []); return $result; }; diff --git a/src/InterfaceTypeCreator.php b/src/InterfaceTypeCreator.php index e6bf750df..6849fcffa 100644 --- a/src/InterfaceTypeCreator.php +++ b/src/InterfaceTypeCreator.php @@ -26,7 +26,7 @@ protected function getTypeResolver() return function () use ($resolver) { $args = func_get_args(); - return call_user_func_array($resolver, $args); + return call_user_func_array($resolver, $args ?? []); }; } diff --git a/src/Manager.php b/src/Manager.php index 3cbf645e6..90f157d33 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -134,7 +134,7 @@ protected function callMiddleware(Schema $schema, $query, $context, $params, cal // Reverse middlewares $next = $last; // Filter out any middlewares that are set to `false`, e.g. via config - $middlewares = array_reverse(array_filter($this->getMiddlewares())); + $middlewares = array_reverse(array_filter($this->getMiddlewares() ?? [])); /** @var QueryMiddleware $middleware */ foreach ($middlewares as $middleware) { $next = function ($schema, $query, $context, $params) use ($middleware, $next) { @@ -205,20 +205,20 @@ public function applyConfig(array $config) $this->extend('updateConfig', $config); // Bootstrap schema class mapping from config - if (array_key_exists('typeNames', $config)) { + if (array_key_exists('typeNames', $config ?? [])) { StaticSchema::inst()->setTypeNames($config['typeNames']); } - if (array_key_exists('fieldFormatter', $config)) { + if (array_key_exists('fieldFormatter', $config ?? [])) { StaticSchema::inst()->setFieldFormatter($config['fieldFormatter']); } - if (array_key_exists('fieldAccessor', $config)) { + if (array_key_exists('fieldAccessor', $config ?? [])) { StaticSchema::inst()->setFieldAccessor(Injector::inst()->get($config['fieldAccessor'])); } else { StaticSchema::inst()->setFieldAccessor(Injector::inst()->get(NaiveFieldAccessor::class)); } // Types (incl. Interfaces and InputTypes) - if (array_key_exists('types', $config)) { + if (array_key_exists('types', $config ?? [])) { foreach ($config['types'] as $name => $typeCreatorClass) { $typeCreator = Injector::inst()->create($typeCreatorClass, $this); if (!($typeCreator instanceof TypeCreator)) { @@ -234,7 +234,7 @@ public function applyConfig(array $config) } // Queries - if ($config && array_key_exists('queries', $config)) { + if ($config && array_key_exists('queries', $config ?? [])) { foreach ($config['queries'] as $name => $queryCreatorClass) { $queryCreator = Injector::inst()->create($queryCreatorClass, $this); if (!($queryCreator instanceof QueryCreator)) { @@ -251,7 +251,7 @@ public function applyConfig(array $config) } // Mutations - if ($config && array_key_exists('mutations', $config)) { + if ($config && array_key_exists('mutations', $config ?? [])) { foreach ($config['mutations'] as $name => $mutationCreatorClass) { $mutationCreator = Injector::inst()->create($mutationCreatorClass, $this); if (!($mutationCreator instanceof MutationCreator)) { @@ -274,7 +274,7 @@ public function applyConfig(array $config) } if (isset($config['scaffolding_providers'])) { foreach ($config['scaffolding_providers'] as $provider) { - if (!class_exists($provider)) { + if (!class_exists($provider ?? '')) { throw new InvalidArgumentException(sprintf( 'Scaffolding provider %s does not exist.', $provider @@ -315,7 +315,7 @@ public function schema() 'fields' => function () { return array_map(function ($query) { return is_callable($query) ? $query() : $query; - }, $this->queries); + }, $this->queries ?? []); }, ]); } else { @@ -330,7 +330,7 @@ public function schema() 'fields' => function () { return array_map(function ($mutation) { return is_callable($mutation) ? $mutation() : $mutation; - }, $this->mutations); + }, $this->mutations ?? []); }, ]); } @@ -491,7 +491,7 @@ public function setSchemaKey($schemaKey) __CLASS__ )); } - if (preg_match('/[^A-Za-z0-9_-]/', $schemaKey)) { + if (preg_match('/[^A-Za-z0-9_-]/', $schemaKey ?? '')) { throw new InvalidArgumentException(sprintf( '%s schemaKey may only contain alphanumeric characters, dashes, and underscores', __CLASS__ @@ -519,7 +519,7 @@ public static function formatError(Error $exception) if (!empty($locations)) { $error['locations'] = array_map(function (SourceLocation $loc) { return $loc->toArray(); - }, $locations); + }, $locations ?? []); } $previous = $exception->getPrevious(); @@ -619,7 +619,7 @@ public function serialiseResult($executionResult) if (!empty($executionResult->errors)) { return [ 'data' => $executionResult->data, - 'errors' => array_map($this->errorFormatter, $executionResult->errors), + 'errors' => array_map($this->errorFormatter, $executionResult->errors ?? []), ]; } else { return [ diff --git a/src/Middleware/CSRFMiddleware.php b/src/Middleware/CSRFMiddleware.php index fb4af9e01..fa29237f2 100644 --- a/src/Middleware/CSRFMiddleware.php +++ b/src/Middleware/CSRFMiddleware.php @@ -35,12 +35,12 @@ public function process(Schema $schema, $query, $context, $params, callable $nex protected function isMutation($query) { // Simple string matching as a first check to prevent unnecessary static analysis - if (stristr($query, Manager::MUTATION_ROOT) === false) { + if (stristr($query ?? '', Manager::MUTATION_ROOT ?? '') === false) { return false; } // If "mutation" is the first expression in the query, then it's a mutation. - if (preg_match('/^\s*'.preg_quote(Manager::MUTATION_ROOT, '/').'/', $query)) { + if (preg_match('/^\s*'.preg_quote(Manager::MUTATION_ROOT ?? '', '/').'/', $query ?? '')) { return true; } @@ -52,7 +52,7 @@ protected function isMutation($query) NodeKind::OPERATION_DEFINITION, NodeKind::OPERATION_TYPE_DEFINITION ]; - if (!in_array($statement->kind, $options, true)) { + if (!in_array($statement->kind, $options ?? [], true)) { continue; } if ($statement->operation === Manager::MUTATION_ROOT) { diff --git a/src/Middleware/HTTPMethodMiddleware.php b/src/Middleware/HTTPMethodMiddleware.php index 5050cfb52..c960f4a5d 100644 --- a/src/Middleware/HTTPMethodMiddleware.php +++ b/src/Middleware/HTTPMethodMiddleware.php @@ -21,7 +21,7 @@ public function process(Schema $schema, $query, $context, $params, callable $nex throw new Exception('Request method must be POST or GET'); } - if (preg_match('/^\s*mutation/', $query)) { + if (preg_match('/^\s*mutation/', $query ?? '')) { if (!$isPOST) { throw new Exception('Mutations must use the POST request method'); } diff --git a/src/Pagination/Connection.php b/src/Pagination/Connection.php index fe15f06b8..6ab57ae5e 100644 --- a/src/Pagination/Connection.php +++ b/src/Pagination/Connection.php @@ -458,7 +458,7 @@ protected function applySort($list, $sortBy) foreach ($sortBy as $sortInput) { if (isset($sortInput['field'])) { $direction = isset($sortInput['direction']) ? $sortInput['direction'] : 'ASC'; - if (!array_key_exists($sortInput['field'], $sortableFields)) { + if (!array_key_exists($sortInput['field'], $sortableFields ?? [])) { throw new InvalidArgumentException(sprintf( '"%s" is not a valid sort column', $sortInput['field'] diff --git a/src/Pagination/SortInputTypeCreator.php b/src/Pagination/SortInputTypeCreator.php index 4385b0a75..8bf4d6213 100644 --- a/src/Pagination/SortInputTypeCreator.php +++ b/src/Pagination/SortInputTypeCreator.php @@ -80,7 +80,7 @@ public function getAttributes() public function attributes() { return [ - 'name' => ucfirst($this->inputName) .'SortInputType', + 'name' => ucfirst($this->inputName ?? '') .'SortInputType', 'description' => 'Define the sorting', ]; } @@ -95,7 +95,7 @@ public function fields() } $sortableField = new EnumType([ - 'name' => ucfirst($this->inputName) . 'SortFieldType', + 'name' => ucfirst($this->inputName ?? '') . 'SortFieldType', 'description' => 'Field name to sort by.', 'values' => $values, ]); diff --git a/src/PersistedQuery/FileProvider.php b/src/PersistedQuery/FileProvider.php index d15eac1c9..b9433ab44 100644 --- a/src/PersistedQuery/FileProvider.php +++ b/src/PersistedQuery/FileProvider.php @@ -48,9 +48,9 @@ public function getQueryMapping($schemaKey = 'default') return []; } - $path = trim($pathWithKey[$schemaKey]); - $contents = trim(file_get_contents($path)); - $result = json_decode($contents, true); + $path = trim($pathWithKey[$schemaKey] ?? ''); + $contents = trim(file_get_contents($path ?? '') ?? ''); + $result = json_decode($contents ?? '', true); if (!is_array($result)) { return []; } diff --git a/src/PersistedQuery/GuzzleHTTPClient.php b/src/PersistedQuery/GuzzleHTTPClient.php index 7a6d0a193..e3837f9e0 100644 --- a/src/PersistedQuery/GuzzleHTTPClient.php +++ b/src/PersistedQuery/GuzzleHTTPClient.php @@ -21,7 +21,7 @@ public function getURL($url, $timeout = 5) try { $response = $client->send($request, ['timeout' => $timeout]); - $contents = trim($response->getBody()->getContents()); + $contents = trim($response->getBody()->getContents() ?? ''); } catch (RuntimeException $e) { user_error($e->getMessage(), E_USER_WARNING); return null; diff --git a/src/PersistedQuery/HTTPProvider.php b/src/PersistedQuery/HTTPProvider.php index 58a72e7e3..364348c88 100644 --- a/src/PersistedQuery/HTTPProvider.php +++ b/src/PersistedQuery/HTTPProvider.php @@ -85,11 +85,11 @@ public function getQueryMapping($schemaKey = 'default') return []; } - $url = trim($urlWithKey[$schemaKey]); + $url = trim($urlWithKey[$schemaKey] ?? ''); $map = null; try { $contents = $this->getClient()->getURL($url, $this->config()->get('timeout')); - $map = json_decode($contents, true); + $map = json_decode($contents ?? '', true); } catch (Exception $e) { user_error($e->getMessage(), E_USER_WARNING); $map = []; diff --git a/src/PersistedQuery/JSONStringProvider.php b/src/PersistedQuery/JSONStringProvider.php index 8c75eb3ae..76d446cc3 100644 --- a/src/PersistedQuery/JSONStringProvider.php +++ b/src/PersistedQuery/JSONStringProvider.php @@ -53,7 +53,7 @@ public function getQueryMapping($schemaKey = 'default') } $mapping = $mappingWithKey[$schemaKey]; - $result = json_decode($mapping, true); + $result = json_decode($mapping ?? '', true); if (!is_array($result)) { return []; } @@ -87,7 +87,7 @@ public function setSchemaMapping(array $mapping) 'setSchemaMapping accepts an array of schema keys to JSON strings' ); } - if (json_decode($queryMap) === null) { + if (json_decode($queryMap ?? '') === null) { throw new InvalidArgumentException( 'setSchemaMapping passed an invalid string of JSON. Got error: ' . json_last_error() ); diff --git a/src/QueryFilter/DataObjectQueryFilter.php b/src/QueryFilter/DataObjectQueryFilter.php index 9cc1a84c4..aa947acce 100644 --- a/src/QueryFilter/DataObjectQueryFilter.php +++ b/src/QueryFilter/DataObjectQueryFilter.php @@ -180,7 +180,7 @@ public function addDefaultFilters($field) */ public function addAllFilters() { - $fields = array_keys($this->getDataObjectInstance()->searchableFields()); + $fields = array_keys($this->getDataObjectInstance()->searchableFields() ?? []); foreach ($fields as $fieldName) { $this->addDefaultFilters($fieldName); } @@ -289,7 +289,7 @@ public function getFiltersForField($fieldName) */ public function getFilterIdentifiersForField($fieldName) { - return array_keys($this->getFiltersForField($fieldName)); + return array_keys($this->getFiltersForField($fieldName) ?? []); } @@ -316,7 +316,7 @@ public function isFieldFiltered($fieldName) public function fieldHasFilter($fieldName, $id) { if ($this->isFieldFiltered($fieldName)) { - return in_array($id, $this->getFilterIdentifiersForField($fieldName)); + return in_array($id, $this->getFilterIdentifiersForField($fieldName) ?? []); } return false; @@ -379,7 +379,7 @@ public function applyConfig(array $config) protected function getFieldFilters(array $filters) { foreach ($filters as $key => $val) { - $pos = strrpos($key, self::SEPARATOR); + $pos = strrpos($key ?? '', self::SEPARATOR ?? ''); // falsy is okay here because a leading __ is invalid. if (!$pos) { throw new InvalidArgumentException(sprintf( @@ -388,12 +388,12 @@ protected function getFieldFilters(array $filters) self::SEPARATOR )); } - $parts = explode(self::SEPARATOR, $key); + $parts = explode(self::SEPARATOR ?? '', $key ?? ''); $filterIdentifier = array_pop($parts); // If the field segment contained __, that implies relationship (dot notation) $field = implode('.', $parts); // The Field key is written with self::SEPARATOR - $fieldName = implode(self::SEPARATOR, $parts); + $fieldName = implode(self::SEPARATOR ?? '', $parts); $filter = $this->getFieldFilterByIdentifier($fieldName, $filterIdentifier); if (!$filter instanceof FieldFilterInterface) { $filter = $this->getFilterRegistry()->getFilterByIdentifier($filterIdentifier); @@ -417,11 +417,11 @@ protected function getFieldFilters(array $filters) protected function getDBField($field) { $dbField = null; - if (stristr($field, self::SEPARATOR) !== false) { - $relationNames = explode(self::SEPARATOR, $field); + if (stristr($field ?? '', self::SEPARATOR ?? '') !== false) { + $relationNames = explode(self::SEPARATOR ?? '', $field ?? ''); $relationField = array_pop($relationNames); // reverse array so we can use the faster array_pop - $relationNames = array_reverse($relationNames); + $relationNames = array_reverse($relationNames ?? []); // initialize current class $class = get_class($this->getDataObjectInstance()); do { diff --git a/src/QueryFilter/FieldFilterRegistry.php b/src/QueryFilter/FieldFilterRegistry.php index b561bf02e..1b4ddf579 100644 --- a/src/QueryFilter/FieldFilterRegistry.php +++ b/src/QueryFilter/FieldFilterRegistry.php @@ -39,7 +39,7 @@ public function addFilter(FieldFilterInterface $filter, $identifier = null) )); } $id = $identifier ?: $filter->getIdentifier(); - if (!preg_match('/^[A-Za-z0-9_]+$/', $id)) { + if (!preg_match('/^[A-Za-z0-9_]+$/', $id ?? '')) { throw new InvalidArgumentException(sprintf( 'Filter %s has an invalid identifier. Only alphanumeric characters and underscores allowed.', get_class($filter) diff --git a/src/Scaffolding/Scaffolders/CRUD/Create.php b/src/Scaffolding/Scaffolders/CRUD/Create.php index f15326b68..2fedd6d27 100644 --- a/src/Scaffolding/Scaffolders/CRUD/Create.php +++ b/src/Scaffolding/Scaffolders/CRUD/Create.php @@ -42,7 +42,7 @@ public function getName() return $name; } - return 'create' . ucfirst($this->getTypeName()); + return 'create' . ucfirst($this->getTypeName() ?? ''); } /** @@ -126,7 +126,7 @@ public function resolve($object, array $args, $context, ResolveInfo $info) // Extension points that return false should kill the create $results = $this->extend('augmentMutation', $newObject, $args, $context, $info); - if (in_array(false, $results, true)) { + if (in_array(false, $results ?? [], true)) { return null; } diff --git a/src/Scaffolding/Scaffolders/CRUD/Delete.php b/src/Scaffolding/Scaffolders/CRUD/Delete.php index b8330853b..080804914 100644 --- a/src/Scaffolding/Scaffolders/CRUD/Delete.php +++ b/src/Scaffolding/Scaffolders/CRUD/Delete.php @@ -40,7 +40,7 @@ public function getName() return $name; } - return 'delete' . ucfirst($this->getTypeName()); + return 'delete' . ucfirst($this->getTypeName() ?? ''); } /** @@ -75,7 +75,7 @@ public function resolve($object, array $args, $context, ResolveInfo $info) $extensionResults = $this->extend('augmentMutation', $results, $args, $context, $info); // Extension points that return false should kill the deletion - if (in_array(false, $extensionResults, true)) { + if (in_array(false, $extensionResults ?? [], true)) { return; } diff --git a/src/Scaffolding/Scaffolders/CRUD/Read.php b/src/Scaffolding/Scaffolders/CRUD/Read.php index a068db4f3..39ae2b500 100644 --- a/src/Scaffolding/Scaffolders/CRUD/Read.php +++ b/src/Scaffolding/Scaffolders/CRUD/Read.php @@ -87,7 +87,7 @@ public function getName() } $typePlural = $this->pluralise($this->getTypeName()); - return 'read' . ucfirst($typePlural); + return 'read' . ucfirst($typePlural ?? ''); } /** @@ -114,8 +114,8 @@ public function resolve($object, array $args, $context, ResolveInfo $info) protected function pluralise($typeName) { // Ported from DataObject::plural_name() - if (preg_match('/[^aeiou]y$/i', $typeName)) { - $typeName = substr($typeName, 0, -1) . 'ie'; + if (preg_match('/[^aeiou]y$/i', $typeName ?? '')) { + $typeName = substr($typeName ?? '', 0, -1) . 'ie'; } $typeName .= 's'; return $typeName; diff --git a/src/Scaffolding/Scaffolders/CRUD/ReadOne.php b/src/Scaffolding/Scaffolders/CRUD/ReadOne.php index a191119d6..66dbb81af 100644 --- a/src/Scaffolding/Scaffolders/CRUD/ReadOne.php +++ b/src/Scaffolding/Scaffolders/CRUD/ReadOne.php @@ -48,7 +48,7 @@ public function getName() return $name; } - return 'readOne' . ucfirst($this->getTypeName()); + return 'readOne' . ucfirst($this->getTypeName() ?? ''); } /** @@ -153,7 +153,7 @@ public function applyConfig(array $config) protected function checkForQueryFilterCompatibility(array $args): void { // Skip implementation if query filter is compatible - if (!array_key_exists('filter', $args)) { + if (!array_key_exists('filter', $args ?? [])) { return; } diff --git a/src/Scaffolding/Scaffolders/CRUD/Update.php b/src/Scaffolding/Scaffolders/CRUD/Update.php index 410ea3eb2..395ed047f 100644 --- a/src/Scaffolding/Scaffolders/CRUD/Update.php +++ b/src/Scaffolding/Scaffolders/CRUD/Update.php @@ -43,7 +43,7 @@ public function getName() return $name; } - return 'update' . ucfirst($this->getTypeName()); + return 'update' . ucfirst($this->getTypeName() ?? ''); } /** @@ -150,7 +150,7 @@ public function resolve($object, array $args, $context, ResolveInfo $info) // Extension points that return false should kill the write operation $results = $this->extend('augmentMutation', $obj, $args, $context, $info); - if (in_array(false, $results, true)) { + if (in_array(false, $results ?? [], true)) { return $obj; } diff --git a/src/Scaffolding/Scaffolders/DataObjectScaffolder.php b/src/Scaffolding/Scaffolders/DataObjectScaffolder.php index f4b9cd0ce..f2110d06f 100644 --- a/src/Scaffolding/Scaffolders/DataObjectScaffolder.php +++ b/src/Scaffolding/Scaffolders/DataObjectScaffolder.php @@ -153,7 +153,7 @@ public function addAllFieldsExcept($exclusions, $includeHasOne = false) $exclusions = [$exclusions]; } $fields = $this->allFieldsFromDataObject($includeHasOne); - $filteredFields = array_diff($fields, $exclusions); + $filteredFields = array_diff($fields ?? [], $exclusions); return $this->addFields($filteredFields); } @@ -379,8 +379,8 @@ function ($obj) use ($fieldName) { public function getDependentClasses() { return array_merge( - array_values($this->nestedDataObjectClasses()), - array_values($this->nestedConnections()) + array_values($this->nestedDataObjectClasses() ?? []), + array_values($this->nestedConnections() ?? []) ); } diff --git a/src/Scaffolding/Scaffolders/InheritanceScaffolder.php b/src/Scaffolding/Scaffolders/InheritanceScaffolder.php index 6b86ea4e7..f7bdf59dc 100644 --- a/src/Scaffolding/Scaffolders/InheritanceScaffolder.php +++ b/src/Scaffolding/Scaffolders/InheritanceScaffolder.php @@ -62,7 +62,7 @@ public function getRootClass() */ public function setRootClass($rootClass) { - if (!class_exists($rootClass)) { + if (!class_exists($rootClass ?? '')) { throw new InvalidArgumentException(sprintf( 'Class %s does not exist.', $rootClass @@ -115,7 +115,7 @@ public function getTypes() return array_map(function ($class) use ($tree, $schema) { return $schema->typeNameForDataObject($class); - }, $tree); + }, $tree ?? []); } /** @@ -124,7 +124,7 @@ public function getTypes() public function addToManager(Manager $manager) { $types = $this->getTypes(); - if (sizeof($types) === 1) { + if (sizeof($types ?? []) === 1) { return; } diff --git a/src/Scaffolding/Scaffolders/OperationScaffolder.php b/src/Scaffolding/Scaffolders/OperationScaffolder.php index 06e7db9ac..d74a925dd 100644 --- a/src/Scaffolding/Scaffolders/OperationScaffolder.php +++ b/src/Scaffolding/Scaffolders/OperationScaffolder.php @@ -91,7 +91,7 @@ public static function getIdentifier($instOrClass) { $class = ($instOrClass instanceof OperationScaffolder) ? get_class($instOrClass) : $instOrClass; $operations = static::getOperations(); - $operations = array_flip($operations); + $operations = array_flip($operations ?? []); return isset($operations[$class]) ? $operations[$class] : null; } @@ -449,10 +449,10 @@ protected function createResolverFunction() return function () use ($resolver) { $args = func_get_args(); if (is_callable($resolver)) { - return call_user_func_array($resolver, $args); + return call_user_func_array($resolver, $args ?? []); } else { if ($resolver instanceof OperationResolver) { - return call_user_func_array([$resolver, 'resolve'], $args); + return call_user_func_array([$resolver, 'resolve'], $args ?? []); } else { throw new \Exception(sprintf( '%s resolver must be a closure or implement %s', diff --git a/src/Scaffolding/Scaffolders/SchemaScaffolder.php b/src/Scaffolding/Scaffolders/SchemaScaffolder.php index 89e6fe358..f28f976f5 100644 --- a/src/Scaffolding/Scaffolders/SchemaScaffolder.php +++ b/src/Scaffolding/Scaffolders/SchemaScaffolder.php @@ -129,7 +129,7 @@ public function __construct() public function type($class) { // Remove leading backslash. All namespaces are assumed absolute in YAML - $class = ltrim($class, '\\'); + $class = ltrim($class ?? '', '\\'); foreach ($this->types as $scaffold) { if ($scaffold->getDataObjectClass() === $class) { diff --git a/src/Scaffolding/Scaffolders/UnionScaffolder.php b/src/Scaffolding/Scaffolders/UnionScaffolder.php index 133ec459d..6267fe27f 100644 --- a/src/Scaffolding/Scaffolders/UnionScaffolder.php +++ b/src/Scaffolding/Scaffolders/UnionScaffolder.php @@ -83,7 +83,7 @@ public function scaffold(Manager $manager) 'types' => function () use ($manager, $types) { return array_map(function ($item) use ($manager) { return $manager->getType($item); - }, $types); + }, $types ?? []); }, 'resolveType' => function ($obj) use ($manager) { if (!$obj instanceof DataObject) { @@ -98,7 +98,7 @@ public function scaffold(Manager $manager) if ($manager->hasType($typeName)) { return $manager->getType($typeName); } - $class = get_parent_class($class); + $class = get_parent_class($class ?? ''); } throw new Exception(sprintf( 'There is no type defined for %s, and none of its ancestors are defined.', diff --git a/src/Scaffolding/StaticSchema.php b/src/Scaffolding/StaticSchema.php index d0e2dc18d..a38b5a2ad 100644 --- a/src/Scaffolding/StaticSchema.php +++ b/src/Scaffolding/StaticSchema.php @@ -111,8 +111,8 @@ public function typeNameForDataObject($class) return $customTypeName; } - $parts = explode('\\', $class); - $typeName = sizeof($parts) > 1 ? $parts[0] . end($parts) : $parts[0]; + $parts = explode('\\', $class ?? ''); + $typeName = sizeof($parts ?? []) > 1 ? $parts[0] . end($parts) : $parts[0]; return $this->typeName($typeName); } @@ -144,7 +144,7 @@ public function inheritanceTypeNameForType($typeName) */ public function typeName($str) { - return preg_replace('/[^A-Za-z0-9_]/', '_', str_replace(' ', '', $str)); + return preg_replace('/[^A-Za-z0-9_]/', '_', str_replace(' ', '', $str ?? '') ?? ''); } /** @@ -178,11 +178,11 @@ public function setTypeNames($typesMap) static::class )); } - $allTypes = array_values($typesMap); + $allTypes = array_values($typesMap ?? []); $diff = array_unique( array_diff_assoc( - $allTypes, - array_unique($allTypes) + $allTypes ?? [], + array_unique($allTypes ?? []) ) ); @@ -211,7 +211,7 @@ public function setTypeNames($typesMap) public function getAncestry($dataObjectClass) { $classes = []; - $ancestry = array_reverse(ClassInfo::ancestry($dataObjectClass)); + $ancestry = array_reverse(ClassInfo::ancestry($dataObjectClass) ?? []); foreach ($ancestry as $class) { if ($class === $dataObjectClass) { @@ -244,7 +244,7 @@ public function getDescendants($dataObjectClass) $descendants = ClassInfo::subclassesFor($dataObjectClass); array_shift($descendants); - return array_values($descendants); + return array_values($descendants ?? []); } /** @@ -309,7 +309,7 @@ public function introspectTypes(Manager $manager) if (isset($fragments['errors'])) { $messages = array_map(function ($error) { return $error['message']; - }, $fragments['errors']); + }, $fragments['errors'] ?? []); throw new Exception(sprintf( 'There were some errors with the introspection query: %s', @@ -346,7 +346,7 @@ public function formatFields(array $fields): array return array_map(function ($field) { return $this->formatField($field); - }, $fields); + }, $fields ?? []); } /** @@ -383,7 +383,7 @@ public function extractKeys(array $keys, array $arr, $graceful = true): array return array_map(function ($key) use ($graceful, $arr) { $formatted = $this->formatField($key); return $graceful ? ($arr[$formatted] ?? null) : $arr[$formatted]; - }, $keys); + }, $keys ?? []); } /** diff --git a/src/Scaffolding/Traits/DataObjectTypeTrait.php b/src/Scaffolding/Traits/DataObjectTypeTrait.php index ebd55e151..3c2072f92 100644 --- a/src/Scaffolding/Traits/DataObjectTypeTrait.php +++ b/src/Scaffolding/Traits/DataObjectTypeTrait.php @@ -68,7 +68,7 @@ public function setDataObjectClass($class) throw new InvalidArgumentException("Missing class provided"); } - if (!class_exists($class)) { + if (!class_exists($class ?? '')) { throw new InvalidArgumentException("Non-existent classname \"{$class}\""); } diff --git a/src/Scaffolding/Util/OperationList.php b/src/Scaffolding/Util/OperationList.php index 15eb68d73..d0eab8448 100644 --- a/src/Scaffolding/Util/OperationList.php +++ b/src/Scaffolding/Util/OperationList.php @@ -107,7 +107,7 @@ public function removeItemByCallback($callback) } if ($renumberKeys) { - $this->items = array_values($this->items); + $this->items = array_values($this->items ?? []); } } diff --git a/src/Scaffolding/Util/StringTypeParser.php b/src/Scaffolding/Util/StringTypeParser.php index 1413dec1b..73edcd180 100644 --- a/src/Scaffolding/Util/StringTypeParser.php +++ b/src/Scaffolding/Util/StringTypeParser.php @@ -42,9 +42,9 @@ class StringTypeParser implements TypeParserInterface */ public static function isInternalType($type) { - $types = array_keys(Type::getStandardTypes()); + $types = array_keys(Type::getStandardTypes() ?? []); - return in_array($type, $types); + return in_array($type, $types ?? []); } /** @@ -63,7 +63,7 @@ public function __construct($rawArg) ); } - if (!preg_match('/^([A-Za-z]+)(!?)(?:\s*\(\s*(.*)\))?/', $rawArg, $matches)) { + if (!preg_match('/^([A-Za-z]+)(!?)(?:\s*\(\s*(.*)\))?/', $rawArg ?? '', $matches)) { throw new InvalidArgumentException( "Invalid argument: $rawArg" ); diff --git a/src/TypeCreator.php b/src/TypeCreator.php index df3c996d1..9fac3105a 100644 --- a/src/TypeCreator.php +++ b/src/TypeCreator.php @@ -173,11 +173,11 @@ protected function getFieldResolver($name, $field) return $field['resolve']; } $candidateMethods = [ - 'resolve'.ucfirst($name).'Field', + 'resolve'.ucfirst($name ?? '').'Field', 'resolveField', ]; foreach ($candidateMethods as $resolveMethod) { - if (!method_exists($this, $resolveMethod)) { + if (!method_exists($this, $resolveMethod ?? '')) { continue; } @@ -186,7 +186,7 @@ protected function getFieldResolver($name, $field) return function () use ($resolver) { $args = func_get_args(); // See 'resolveType' on https://github.com/webonyx/graphql-php - return call_user_func_array($resolver, $args); + return call_user_func_array($resolver, $args ?? []); }; } diff --git a/src/Util/CaseInsensitiveFieldAccessor.php b/src/Util/CaseInsensitiveFieldAccessor.php index 2fb2e070a..29943bdf1 100644 --- a/src/Util/CaseInsensitiveFieldAccessor.php +++ b/src/Util/CaseInsensitiveFieldAccessor.php @@ -131,7 +131,7 @@ public function getObjectFieldName(ViewableData $object, $fieldName, $opts = []) ], $opts); $optFn = function ($type) use (&$opts) { - return (in_array($type, $opts) && $opts[$type] === true); + return (in_array($type, $opts ?? []) && $opts[$type] === true); }; // Correct case (and getters) @@ -145,7 +145,7 @@ public function getObjectFieldName(ViewableData $object, $fieldName, $opts = []) foreach ($parents as $parent) { $fields = DataObject::getSchema()->databaseFields($parent); foreach ($fields as $objectFieldName => $fieldClass) { - if (strcasecmp($objectFieldName, $fieldName) === 0) { + if (strcasecmp($objectFieldName ?? '', $fieldName ?? '') === 0) { return $objectFieldName; } } @@ -154,7 +154,7 @@ public function getObjectFieldName(ViewableData $object, $fieldName, $opts = []) // Setters // TODO Support for Object::$extra_methods (case sensitive array key check) - $setterName = "set" . ucfirst($fieldName); + $setterName = "set" . ucfirst($fieldName ?? ''); if ($optFn(self::HAS_SETTER) && $object->hasMethod($setterName)) { return $setterName; } diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php index 881f5f813..edbf09cf6 100644 --- a/tests/ControllerTest.php +++ b/tests/ControllerTest.php @@ -95,7 +95,7 @@ public function testIndexWithException() $controller = new Controller($managerMock); $response = $controller->index(new HTTPRequest('GET', '')); $this->assertFalse($response->isError()); - $responseObj = json_decode($response->getBody(), true); + $responseObj = json_decode($response->getBody() ?? '', true); $this->assertNotNull($responseObj); $this->assertArrayHasKey('errors', $responseObj); $this->assertEquals('Failed', $responseObj['errors'][0]['message']); @@ -115,7 +115,7 @@ public function testIndexWithExceptionIncludesTraceInDevMode() $controller = new Controller($managerMock); $response = $controller->index(new HTTPRequest('GET', '')); $this->assertFalse($response->isError()); - $responseObj = json_decode($response->getBody(), true); + $responseObj = json_decode($response->getBody() ?? '', true); $this->assertNotNull($responseObj); $this->assertArrayHasKey('errors', $responseObj); $this->assertEquals('Failed', $responseObj['errors'][0]['message']); @@ -406,7 +406,7 @@ public function testTypeCaching() // Static cache should now exist $this->assertFileExists($expectedSchemaPath, 'Schema is cached'); - $this->assertEquals('{"uncle":"cheese"}', file_get_contents($expectedSchemaPath)); + $this->assertEquals('{"uncle":"cheese"}', file_get_contents($expectedSchemaPath ?? '')); Config::modify()->set(Controller::class, 'cache_types_in_filesystem', false); Controller::create(new Manager('testSchema'))->processTypeCaching(); @@ -561,7 +561,7 @@ protected function createGraphqlRequest($graphql, $method = 'POST') protected function assertQueryError(Controller $controller, HTTPRequest $request, $regExp) { - $data = json_decode($controller->handleRequest($request)->getBody(), true); + $data = json_decode($controller->handleRequest($request)->getBody() ?? '', true); $this->assertArrayHasKey('errors', $data); $this->assertCount(1, $data['errors']); $this->assertMatchesRegularExpression($regExp, $data['errors'][0]['message']); @@ -570,7 +570,7 @@ protected function assertQueryError(Controller $controller, HTTPRequest $request protected function assertQuerySuccess(Controller $controller, HTTPRequest $request, $operation) { $controller->setRequest($request); - $data = json_decode($controller->handleRequest($request)->getBody(), true); + $data = json_decode($controller->handleRequest($request)->getBody() ?? '', true); $this->assertArrayNotHasKey('errors', $data); $this->assertArrayHasKey('data', $data); $this->assertArrayHasKey($operation, $data['data']); @@ -645,7 +645,7 @@ public function testGetQueryWithQueryAndID() 'variables' => json_encode($expectedVariables) ]); $result = $controller->index($request)->getBody(); - $this->assertArrayHasKey('errors', json_decode($result, true)); + $this->assertArrayHasKey('errors', json_decode($result ?? '', true)); } protected function getType(Manager $manager) diff --git a/tests/Fake/FakeFieldAccessor.php b/tests/Fake/FakeFieldAccessor.php index 94401fc0d..b4c246afd 100644 --- a/tests/Fake/FakeFieldAccessor.php +++ b/tests/Fake/FakeFieldAccessor.php @@ -10,7 +10,7 @@ class FakeFieldAccessor implements FieldAccessorInterface { public function getObjectFieldName(ViewableData $object, $fieldName, $opts = []) { - $field = strrev($fieldName); + $field = strrev($fieldName ?? ''); return $object->hasField($field) ? $field : null; } @@ -20,7 +20,7 @@ public function getValue(ViewableData $object, $fieldName, $opts = [], $asObject if ($object->hasField($fieldName)) { return $object->obj($fieldName); } - $field = strrev($fieldName); + $field = strrev($fieldName ?? ''); return $asObject ? $object->obj($field): $object->$field; } diff --git a/tests/Scaffolding/Scaffolders/CRUD/CreateTest.php b/tests/Scaffolding/Scaffolders/CRUD/CreateTest.php index cf9efeb95..5d5e00ef7 100644 --- a/tests/Scaffolding/Scaffolders/CRUD/CreateTest.php +++ b/tests/Scaffolding/Scaffolders/CRUD/CreateTest.php @@ -101,7 +101,7 @@ public function testCreateOperationInputType() // Test args $args = $scaffold['args']; - $this->assertEquals(['Input', 'MyField'], array_keys($args)); + $this->assertEquals(['Input', 'MyField'], array_keys($args ?? [])); // Custom field $this->assertArrayHasKey('MyField', $args); diff --git a/tests/Scaffolding/Scaffolders/CRUD/DeleteTest.php b/tests/Scaffolding/Scaffolders/CRUD/DeleteTest.php index d003405ce..7601612b4 100644 --- a/tests/Scaffolding/Scaffolders/CRUD/DeleteTest.php +++ b/tests/Scaffolding/Scaffolders/CRUD/DeleteTest.php @@ -98,7 +98,7 @@ public function testDeleteOperationArgs() // Test args $args = $scaffold['args']; - $this->assertEquals(['IDs', 'MyField'], array_keys($args)); + $this->assertEquals(['IDs', 'MyField'], array_keys($args ?? [])); /** @var NonNull $idType */ $idType = $args['IDs']['type']; diff --git a/tests/Scaffolding/Scaffolders/CRUD/ReadOneTest.php b/tests/Scaffolding/Scaffolders/CRUD/ReadOneTest.php index b9bfebdd3..5bd42d87f 100644 --- a/tests/Scaffolding/Scaffolders/CRUD/ReadOneTest.php +++ b/tests/Scaffolding/Scaffolders/CRUD/ReadOneTest.php @@ -69,7 +69,7 @@ public function testReadOneOperationArgs() // Check all args $args = $scaffold['args']; - $this->assertEquals(['ID', 'MyField'], array_keys($args)); + $this->assertEquals(['ID', 'MyField'], array_keys($args ?? [])); /** @var NonNull $idType */ $idType = $args['ID']['type']; diff --git a/tests/Scaffolding/Scaffolders/CRUD/UpdateTest.php b/tests/Scaffolding/Scaffolders/CRUD/UpdateTest.php index 21d57e969..68b4ca4ad 100644 --- a/tests/Scaffolding/Scaffolders/CRUD/UpdateTest.php +++ b/tests/Scaffolding/Scaffolders/CRUD/UpdateTest.php @@ -97,7 +97,7 @@ public function testUpdateOperationInputType() // Test args $args = $scaffold['args']; - $this->assertEquals(['Input', 'MyField'], array_keys($args)); + $this->assertEquals(['Input', 'MyField'], array_keys($args ?? [])); /** @var NonNull $inputType */ $inputType = $args['Input']['type']; diff --git a/tests/Scaffolding/Scaffolders/DataObjectScaffolderTest.php b/tests/Scaffolding/Scaffolders/DataObjectScaffolderTest.php index fdc6c9a78..dd25fa1e5 100644 --- a/tests/Scaffolding/Scaffolders/DataObjectScaffolderTest.php +++ b/tests/Scaffolding/Scaffolders/DataObjectScaffolderTest.php @@ -370,7 +370,7 @@ public function testDataObjectScaffolderScaffold() $config = $objectType->config; $this->assertEquals($scaffolder->getTypeName(), $config['name']); - $this->assertEquals(['MyField', 'Author', 'Files'], array_keys($config['fields']())); + $this->assertEquals(['MyField', 'Author', 'Files'], array_keys($config['fields']() ?? [])); } public function testDataObjectScaffolderScaffoldFieldException() diff --git a/tests/Scaffolding/Scaffolders/InheritanceScaffolderTest.php b/tests/Scaffolding/Scaffolders/InheritanceScaffolderTest.php index e84376839..be09979e3 100644 --- a/tests/Scaffolding/Scaffolders/InheritanceScaffolderTest.php +++ b/tests/Scaffolding/Scaffolders/InheritanceScaffolderTest.php @@ -63,7 +63,7 @@ public function testScaffolding() $nestedTypes = array_map(function ($type) { return $type->config['name']; - }, $scaffold->getTypes()); + }, $scaffold->getTypes() ?? []); $this->assertContains( StaticSchema::inst()->typeNameForDataObject(FakeSiteTree::class), diff --git a/tests/Scaffolding/Scaffolders/OperationScaffolderTest.php b/tests/Scaffolding/Scaffolders/OperationScaffolderTest.php index dc4201bf9..3ae2d4fa2 100644 --- a/tests/Scaffolding/Scaffolders/OperationScaffolderTest.php +++ b/tests/Scaffolding/Scaffolders/OperationScaffolderTest.php @@ -71,7 +71,7 @@ public function testOperationScaffolderArgs() ); $this->assertEquals([], array_diff( - $scaffolder->getArgs()->column('argName'), + $scaffolder->getArgs()->column('argName') ?? [], ['One', 'Two'] )); @@ -192,7 +192,7 @@ public function testOperationScaffolderAppliesConfig() ]); $this->assertEquals([], array_diff( - $scaffolder->getArgs()->column('argName'), + $scaffolder->getArgs()->column('argName') ?? [], ['One', 'Two'] )); diff --git a/tests/Scaffolding/Scaffolders/SchemaScaffolderTest.php b/tests/Scaffolding/Scaffolders/SchemaScaffolderTest.php index a1c2b0f67..7c283a110 100644 --- a/tests/Scaffolding/Scaffolders/SchemaScaffolderTest.php +++ b/tests/Scaffolding/Scaffolders/SchemaScaffolderTest.php @@ -59,7 +59,7 @@ public function testSchemaScaffolderTypes() $mutation->Test = true; $mutation2 = $scaffolder->mutation('testMutation', DataObjectFake::class); - $this->assertEquals(1, count($scaffolder->getTypes())); + $this->assertEquals(1, count($scaffolder->getTypes() ?? [])); $this->assertTrue($type2->Test); $this->assertEquals(1, $scaffolder->getQueries()->count()); @@ -107,7 +107,7 @@ public function testSchemaScaffolderAddToManager() $classNames = array_map(function (DataObjectScaffolder $scaffold) { return $scaffold->getDataObjectClass(); - }, $types); + }, $types ?? []); $expectedTypes = []; $explicitTypes = [ @@ -318,7 +318,7 @@ public function testUnionInheritanceForTypes() $this->assertTrue($manager->hasType($inheritanceTypeName)); /* @var UnionType $type */ $type = $manager->getType($inheritanceTypeName); - $numDescendants = count(StaticSchema::inst()->getDescendants($ancestor)); + $numDescendants = count(StaticSchema::inst()->getDescendants($ancestor) ?? []); $this->assertCount($numDescendants + 1, $type->getTypes()); $this->assertTrue($manager->hasType($normalTypeName)); /* @var ObjectType $type */ @@ -353,7 +353,7 @@ public function testUnionInheritanceForFields() /* @var UnionType $union */ $union = $manager->getType($inheritanceTypeName); $descendants = StaticSchema::inst()->getDescendants(Member::class); - $this->assertCount(count($descendants) + 1, $union->getTypes()); + $this->assertCount(count($descendants ?? []) + 1, $union->getTypes()); $inheritanceTypeName = StaticSchema::inst() ->inheritanceTypeNameForDataObject(File::class); $normalTypeName = StaticSchema::inst() @@ -364,6 +364,6 @@ public function testUnionInheritanceForFields() $union = $manager->getType($inheritanceTypeName); $descendants = StaticSchema::inst()->getDescendants(File::class); - $this->assertCount(count($descendants) + 1, $union->getTypes()); + $this->assertCount(count($descendants ?? []) + 1, $union->getTypes()); } } diff --git a/tests/TypeCreatorTest.php b/tests/TypeCreatorTest.php index ea295229b..2091a4141 100644 --- a/tests/TypeCreatorTest.php +++ b/tests/TypeCreatorTest.php @@ -134,7 +134,7 @@ protected function getTypeCreatorMock($extraMethods = []) ->setMethods(array_unique(array_merge(['fields', 'attributes'], $extraMethods))) ->getMock(); - if (!in_array('fields', $extraMethods)) { + if (!in_array('fields', $extraMethods ?? [])) { $mock->method('fields')->willReturn([ 'ID' => [ 'type' => Type::nonNull(Type::id()), @@ -142,7 +142,7 @@ protected function getTypeCreatorMock($extraMethods = []) ]); } - if (!in_array('attributes', $extraMethods)) { + if (!in_array('attributes', $extraMethods ?? [])) { $mock->method('attributes') ->willReturn(['name' => 'myType']); }