Skip to content

Commit

Permalink
Fixing remaining phpstan warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
apathak18 committed Jul 25, 2024
1 parent bf6444f commit d665aec
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 31 deletions.
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ parameters:
- identifier: missingType.iterableValue
# new static() is a best practice in Drupal, so we cannot fix that.
- "#^Unsafe usage of new static\\(\\)\\.$#"
# Soft deprecated by phpunit10 and removed in phpunit 12.
- "#^Call to deprecated method getMockForAbstractClass\\(\\)\\.$#"
# We forgot to use return type hints on some interfaces, cannot be changed
# in stable 4.0.
# @todo use return type hints everywhere for 5.0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,13 @@ public function resolve(FileInterface $entity = NULL, $style, RefinableCacheable
$metadata->addCacheableDependency($access);
if ($access->isAllowed() && $image_style = ImageStyle::load($style)) {

// @phpstan-ignore-next-line
$width = $entity->width;

Check failure on line 102 in src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php

View workflow job for this annotation

GitHub Actions / Drupal 10.3.x (PHP 8.3)

No error to ignore is reported on line 102.
// @phpstan-ignore-next-line
$height = $entity->height;

Check failure on line 104 in src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php

View workflow job for this annotation

GitHub Actions / Drupal 10.3.x (PHP 8.3)

No error to ignore is reported on line 104.
if (!isset($width) || !isset($height)) {

// @phpstan-ignore-next-line
if (empty($width) || empty($height)) {

Check failure on line 107 in src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php

View workflow job for this annotation

GitHub Actions / Drupal 11.0.x (PHP 8.3)

No error to ignore is reported on line 107.
/** @var \Drupal\Core\Image\ImageInterface $image */
$image = \Drupal::service('image.factory')->get($entity->getFileUri());
if ($image->isValid()) {
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/AlterableSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected function mockSchema($id, $schema, array $extensions = []): void {
$this->container->get('event_dispatcher'),
])
->onlyMethods(['getSchemaDefinition', 'getResolverRegistry'])
->getMockForAbstractClass();
->getMock();

$this->schema->expects(static::any())
->method('getSchemaDefinition')
Expand Down
25 changes: 1 addition & 24 deletions tests/src/Kernel/DataProducer/EntityReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,8 @@
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\graphql\Kernel\GraphQLTestBase;
use Drupal\Tests\field\Traits\EntityReferenceFieldCreationTrait;

// @todo Drupal 10.1 compatibility: use the deprecated trait for Drupal 10.1.
if (strpos(\Drupal::VERSION, '10.1') === 0) {

/**
* Helper trait for compatibility with Drupal 9.
*
* @phpcs:disable Drupal.Classes.ClassFileName.NoMatch
*/
trait EntityReferenceFieldCreationTrait {
// @phpstan-ignore-next-line
use \Drupal\Tests\field\Traits\EntityReferenceTestTrait;

}
}
else {

/**
* Helper trait for compatibility with Drupal 10.
*/
trait EntityReferenceFieldCreationTrait {
use \Drupal\Tests\field\Traits\EntityReferenceFieldCreationTrait;

}
}

/**
* Tests the entity_reference data producers.
Expand Down
10 changes: 5 additions & 5 deletions tests/src/Traits/MockingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ trait MockingTrait {
* The return callback promise.
*/
protected function toPromise($value) {
return $this->returnCallback(is_callable($value) ? $value : function () use ($value) {
return $this->willReturnCallback(is_callable($value) ? $value : function () use ($value) {
yield $value;
});
}
Expand Down Expand Up @@ -89,7 +89,7 @@ protected function setUpSchema($schema, $id = 'test', array $values = []): void

$this->schemaPluginManager->method('createInstance')
->with($this->equalTo($id))
->will($this->returnValue($this->schema));
->willReturn($this->schema);

$this->container->set('plugin.manager.graphql.schema', $this->schemaPluginManager);
}
Expand Down Expand Up @@ -145,7 +145,7 @@ protected function mockSchema($id, $schema, array $extensions = []): void {
['development' => FALSE],
])
->onlyMethods(['getSchemaDefinition', 'getResolverRegistry'])
->getMockForAbstractClass();
->getMock();

$this->schema->expects(static::any())
->method('getSchemaDefinition')
Expand All @@ -169,14 +169,14 @@ protected function mockSchemaPluginManager($id): void {

$this->schemaPluginManager->expects($this->any())
->method('getDefinitions')
->will($this->returnValue([
->willReturn([
$id => [
'id' => $id,
'name' => 'Test schema',
'provider' => 'graphql',
'class' => '\Drupal\graphql\Plugin\GraphQL\Schema\SdlSchemaPluginBase',
],
]));
]);
}

/**
Expand Down

0 comments on commit d665aec

Please sign in to comment.