Skip to content

I get PropertyNotSetInConstructor when extending the symfony Response class #290

Open
@loevgaard

Description

@loevgaard

Hi

I have this class:

<?php

declare(strict_types=1);

namespace Setono\SyliusGiftCardPlugin\Renderer;

use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Component\HttpFoundation\Response;

final class PdfResponse extends Response
{
    public function __construct(string $content, string $filename = 'gift_card.pdf')
    {
        parent::__construct($content);

        $disposition = HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $filename);
        $this->headers->set('Content-Type', 'application/pdf');
        $this->headers->set('Content-Disposition', $disposition);
    }
}

I am using v4.0.0 of this Psalm plugin and I get the following errors:

ERROR: PropertyNotSetInConstructor - src/Renderer/PdfResponse.php:11:13 - Property Setono\SyliusGiftCardPlugin\Renderer\PdfResponse::$headers is not defined in constructor of Setono\SyliusGiftCardPlugin\Renderer\PdfResponse or in any private or final methods called in the constructor (see https://psalm.dev/074)
final class PdfResponse extends Response


ERROR: PropertyNotSetInConstructor - src/Renderer/PdfResponse.php:11:13 - Property Setono\SyliusGiftCardPlugin\Renderer\PdfResponse::$content is not defined in constructor of Setono\SyliusGiftCardPlugin\Renderer\PdfResponse or in any private or final methods called in the constructor (see https://psalm.dev/074)
final class PdfResponse extends Response


ERROR: PropertyNotSetInConstructor - src/Renderer/PdfResponse.php:11:13 - Property Setono\SyliusGiftCardPlugin\Renderer\PdfResponse::$version is not defined in constructor of Setono\SyliusGiftCardPlugin\Renderer\PdfResponse or in any private or final methods called in the constructor (see https://psalm.dev/074)
final class PdfResponse extends Response


ERROR: PropertyNotSetInConstructor - src/Renderer/PdfResponse.php:11:13 - Property Setono\SyliusGiftCardPlugin\Renderer\PdfResponse::$statusCode is not defined in constructor of Setono\SyliusGiftCardPlugin\Renderer\PdfResponse or in any private or final methods called in the constructor (see https://psalm.dev/074)
final class PdfResponse extends Response


ERROR: PropertyNotSetInConstructor - src/Renderer/PdfResponse.php:11:13 - Property Setono\SyliusGiftCardPlugin\Renderer\PdfResponse::$statusText is not defined in constructor of Setono\SyliusGiftCardPlugin\Renderer\PdfResponse or in any private or final methods called in the constructor (see https://psalm.dev/074)
final class PdfResponse extends Response


ERROR: PropertyNotSetInConstructor - src/Renderer/PdfResponse.php:11:13 - Property Setono\SyliusGiftCardPlugin\Renderer\PdfResponse::$charset is not defined in constructor of Setono\SyliusGiftCardPlugin\Renderer\PdfResponse or in any private or final methods called in the constructor (see https://psalm.dev/074)
final class PdfResponse extends Response


ERROR: UninitializedProperty - src/Renderer/PdfResponse.php:22:9 - Cannot use uninitialized property $this->headers (see https://psalm.dev/186)
        $this->headers->set('Content-Type', 'application/pdf');


ERROR: PossiblyNullReference - src/Renderer/PdfResponse.php:22:25 - Cannot call method set on possibly null value (see https://psalm.dev/083)
        $this->headers->set('Content-Type', 'application/pdf');


ERROR: UninitializedProperty - src/Renderer/PdfResponse.php:23:9 - Cannot use uninitialized property $this->headers (see https://psalm.dev/186)
        $this->headers->set('Content-Disposition', $disposition);


ERROR: PossiblyNullReference - src/Renderer/PdfResponse.php:23:25 - Cannot call method set on possibly null value (see https://psalm.dev/083)
        $this->headers->set('Content-Disposition', $disposition);

Am I doing something wrong or why doesn't Psalm understand that these are invalid errors?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions