Skip to content

[Php81] Allow not readonly property on API Platform api resource #6531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Rector\Tests\Php81\Rector\Property\ReadOnlyPropertyRector\Fixture;

use ApiPlatform\Metadata\ApiResource;

#[ApiResource]
class SkipApiResource
{
private int $amount;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\Php81\Rector\Property\ReadOnlyPropertyRector\Fixture;

use ApiPlatform\Core\Annotation\ApiResource;

/**
* @ApiResource()
*/
class SkipApiResource
{
private int $amount;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\Php81\Rector\Property\ReadOnlyPropertyRector\Fixture;

use ApiPlatform\Metadata\ApiResource;

/**
* @ApiResource()
*/
class SkipApiResource
{
private int $amount;
}
8 changes: 5 additions & 3 deletions src/NodeManipulator/PropertyManipulator.php
Original file line number Diff line number Diff line change
@@ -39,7 +39,9 @@
/**
* @var string[]|class-string<Table>[]
*/
private const DOCTRINE_PROPERTY_ANNOTATIONS = [
private const ALLOWED_NOT_READONLY_CLASS_ANNOTATIONS = [
'ApiPlatform\Core\Annotation\ApiResource',
'ApiPlatform\Metadata\ApiResource',
'Doctrine\ORM\Mapping\Entity',
'Doctrine\ORM\Mapping\Table',
'Doctrine\ORM\Mapping\MappedSuperclass',
@@ -184,10 +186,10 @@ private function isChangeableContext(PropertyFetch | StaticPropertyFetch $proper

private function hasAllowedNotReadonlyAnnotationOrAttribute(PhpDocInfo $phpDocInfo, Class_ $class): bool
{
if ($phpDocInfo->hasByAnnotationClasses(self::DOCTRINE_PROPERTY_ANNOTATIONS)) {
if ($phpDocInfo->hasByAnnotationClasses(self::ALLOWED_NOT_READONLY_CLASS_ANNOTATIONS)) {
return true;
}

return $this->phpAttributeAnalyzer->hasPhpAttributes($class, self::DOCTRINE_PROPERTY_ANNOTATIONS);
return $this->phpAttributeAnalyzer->hasPhpAttributes($class, self::ALLOWED_NOT_READONLY_CLASS_ANNOTATIONS);
}
}