Skip to content

Commit

Permalink
Use proper service
Browse files Browse the repository at this point in the history
  • Loading branch information
dbosen committed Aug 20, 2024
1 parent 8a07c23 commit c292e76
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ abstract class ThunderSearchApiProducerBase extends DataProducerPluginBase imple
/**
* The class resolver service.
*
* @var \Drupal\Core\DependencyInjection\ClassResolverInterface
* @var \Drupal\thunder_gqls\Wrappers\SearchApiResponse
*/
private ClassResolverInterface $classResolver;
private SearchApiResponse $responseWrapper;

/**
* {@inheritdoc}
Expand All @@ -59,7 +59,7 @@ public static function create(

$instance->setEntityTypeManager($container->get('entity_type.manager'));
$instance->setLanguageManager($container->get('language_manager'));
$instance->setClassResolver($container->get('class_resolver'));
$instance->setResponseWrapper($container->get('thunder_gqls.search_api_response'));

return $instance;
}
Expand All @@ -70,7 +70,7 @@ public static function create(
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
*/
public function setEntityTypeManager(EntityTypeManagerInterface $entityTypeManager): void {
private function setEntityTypeManager(EntityTypeManagerInterface $entityTypeManager): void {

Check warning on line 73 in modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApiProducerBase.php

View workflow job for this annotation

GitHub Actions / drupal-coder (drupal practice)

[drupal-coder (drupal practice)] modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApiProducerBase.php#L73 <DrupalPractice.Objects.UnusedPrivateMethod.UnusedMethod>

Unused private method setEntityTypeManager()
Raw output
/github/workspace/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApiProducerBase.php:73:11: warning: Unused private method setEntityTypeManager() (DrupalPractice.Objects.UnusedPrivateMethod.UnusedMethod)
$this->entityTypeManager = $entityTypeManager;
}

Expand All @@ -80,18 +80,18 @@ public function setEntityTypeManager(EntityTypeManagerInterface $entityTypeManag
* @param \Drupal\Core\Language\LanguageManagerInterface $languageManager
* The language manager service.
*/
public function setLanguageManager(LanguageManagerInterface $languageManager): void {
private function setLanguageManager(LanguageManagerInterface $languageManager): void {

Check warning on line 83 in modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApiProducerBase.php

View workflow job for this annotation

GitHub Actions / drupal-coder (drupal practice)

[drupal-coder (drupal practice)] modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApiProducerBase.php#L83 <DrupalPractice.Objects.UnusedPrivateMethod.UnusedMethod>

Unused private method setLanguageManager()
Raw output
/github/workspace/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApiProducerBase.php:83:11: warning: Unused private method setLanguageManager() (DrupalPractice.Objects.UnusedPrivateMethod.UnusedMethod)
$this->languageManager = $languageManager;
}

/**
* Set the class resolver service.
*
* @param \Drupal\Core\DependencyInjection\ClassResolverInterface $classResolver
* @param \Drupal\thunder_gqls\Wrappers\SearchApiResponse $responseWrapper
* The class resolver service.
*/
public function setClassResolver(ClassResolverInterface $classResolver): void {
$this->classResolver = $classResolver;
private function setResponseWrapper(SearchApiResponse $responseWrapper): void {

Check warning on line 93 in modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApiProducerBase.php

View workflow job for this annotation

GitHub Actions / drupal-coder (drupal practice)

[drupal-coder (drupal practice)] modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApiProducerBase.php#L93 <DrupalPractice.Objects.UnusedPrivateMethod.UnusedMethod>

Unused private method setResponseWrapper()
Raw output
/github/workspace/modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderSearchApiProducerBase.php:93:11: warning: Unused private method setResponseWrapper() (DrupalPractice.Objects.UnusedPrivateMethod.UnusedMethod)
$this->responseWrapper = $responseWrapper;
}

/**
Expand Down Expand Up @@ -178,9 +178,7 @@ protected function buildBaseQuery(
* The search api response.
*/
protected function searchApiResponse(QueryInterface $query): SearchApiResponse {
return $this->classResolver
->getInstanceFromDefinition(SearchApiResponse::class)
->setQuery($query);
return $this->responseWrapper->setQuery($query);
}

}
3 changes: 2 additions & 1 deletion modules/thunder_gqls/src/Wrappers/EntityListResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class EntityListResponse implements EntityListResponseInterface, ContainerInject
*
* @var \Drupal\Core\Entity\Query\QueryInterface
*/
protected QueryInterface $query;
private QueryInterface $query;

/**
* The entity buffer.
Expand All @@ -34,6 +34,7 @@ class EntityListResponse implements EntityListResponseInterface, ContainerInject
*/
public function __construct(QueryInterface|EntityBuffer $parameter) {
if ($parameter instanceof QueryInterface) {
@trigger_error('Calling the constructor with the query parameter is deprecated. Use service injection instead of directly instantiating and then use ::setQuery() instead.', E_USER_DEPRECATED);

Check failure on line 37 in modules/thunder_gqls/src/Wrappers/EntityListResponse.php

View workflow job for this annotation

GitHub Actions / drupal-coder (drupal)

[drupal-coder (drupal)] modules/thunder_gqls/src/Wrappers/EntityListResponse.php#L37 <Drupal.Semantics.FunctionTriggerError.TriggerErrorTextLayoutRelaxed>

The trigger_error message 'Calling the constructor with the query parameter is deprecated. Use service injection instead of directly instantiating and then use ::setQuery() instead.' does not match the relaxed standard format: %thing% is deprecated in %deprecation-version% any free text %removal-version%. %extra-info%. See %cr-link%
Raw output
/github/workspace/modules/thunder_gqls/src/Wrappers/EntityListResponse.php:37:22: error: The trigger_error message 'Calling the constructor with the query parameter is deprecated. Use service injection instead of directly instantiating and then use ::setQuery() instead.' does not match the relaxed standard format: %thing% is deprecated in %deprecation-version% any free text %removal-version%. %extra-info%. See %cr-link% (Drupal.Semantics.FunctionTriggerError.TriggerErrorTextLayoutRelaxed)
$this->setQuery($parameter);
return;
}
Expand Down
3 changes: 1 addition & 2 deletions modules/thunder_gqls/src/Wrappers/SearchApiResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SearchApiResponse implements SearchApiResponseInterface, ContainerInjectio
*
* @var \Drupal\search_api\Query\ResultSetInterface|null
*/
protected ?ResultSetInterface $result;
protected ?ResultSetInterface $result = NULL;

/**
* Array of Facets.
Expand Down Expand Up @@ -62,7 +62,6 @@ class SearchApiResponse implements SearchApiResponseInterface, ContainerInjectio
* The entity type manager.
*/
public function __construct(protected SearchApiResultBuffer $buffer, protected EntityFieldManagerInterface $entityFieldManager) {
$this->result = NULL;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions modules/thunder_gqls/thunder_gqls.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ services:
autowire: true
thunder_gqls.buffer.search_api_result:
class: Drupal\thunder_gqls\GraphQL\Buffers\SearchApiResultBuffer
Drupal\thunder_gqls\GraphQL\Buffers\SearchApiResultBuffer: '@thunder_gqls.buffer.search_api_result'
thunder_gqls.search_api_response:
class: Drupal\thunder_gqls\Wrappers\SearchApiResponse

0 comments on commit c292e76

Please sign in to comment.