Skip to content

Commit d241291

Browse files
committed
Adjusting phpstan warning for D11 only.
1 parent 8803a2c commit d241291

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

.github/workflows/testing.yml

-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ jobs:
2222
drupal-core: '10.2.x'
2323
phpstan: '0'
2424
# We only need to run PHPStan once on the latest PHP version.
25-
- php-versions: '8.3'
26-
drupal-core: '10.3.x'
27-
phpstan: '1'
2825
- php-versions: '8.3'
2926
drupal-core: '11.0.x'
3027
phpstan: '1'

src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,18 @@ public function resolve(FileInterface $entity = NULL, $style, RefinableCacheable
9898
$metadata->addCacheableDependency($access);
9999
if ($access->isAllowed() && $image_style = ImageStyle::load($style)) {
100100

101-
/** @var \Drupal\Core\Image\ImageInterface $image */
102-
$image = \Drupal::service('image.factory')->get($entity->getFileUri());
103-
if ($image->isValid()) {
104-
$width = $image->getWidth();
105-
$height = $image->getHeight();
101+
// @phpstan-ignore-next-line
102+
$width = $entity->width;
103+
// @phpstan-ignore-next-line
104+
$height = $entity->height;
105+
106+
if (!isset($width) || !isset($height)) {
107+
/** @var \Drupal\Core\Image\ImageInterface $image */
108+
$image = \Drupal::service('image.factory')->get($entity->getFileUri());
109+
if ($image->isValid()) {
110+
$width = $image->getWidth();
111+
$height = $image->getHeight();
112+
}
106113
}
107114

108115
// Determine the dimensions of the styled image.

src/Routing/QueryRouteEnhancer.php

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ protected function assertValidPostRequestHeaders(Request $request) : void {
9292
return;
9393
}
9494

95+
// @phpstan-ignore-next-line
9596
$content_format = method_exists($request, 'getContentTypeFormat') ? $request->getContentTypeFormat() : $request->getContentType();
9697
if ($content_format === NULL) {
9798
// Symfony before 5.4 does not detect "multipart/form-data", check for it

tests/src/Kernel/DataProducer/Entity/Fields/Image/ImageDerivativeTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public function setUp(): void {
6262

6363
$this->file->method('getFileUri')->willReturn($this->fileUri);
6464
$this->file->method('access')->willReturn((new AccessResultAllowed())->addCacheTags(['test_tag']));
65+
// @todo Remove hard-coded properties and only rely on image factory.
66+
// @phpstan-ignore-next-line
67+
@$this->file->width = 600;
68+
// @phpstan-ignore-next-line
69+
@$this->file->height = 400;
6570

6671
$this->style = ImageStyle::create(['name' => 'test_style']);
6772
$effect = [

0 commit comments

Comments
 (0)