Skip to content

Commit 5848b1e

Browse files
alongoszSteveb-pkonradoboza
authored
IBX-7911: Used strict getters for content tree loading code paths (#347)
For more details see https://issues.ibexa.co/browse/IBX-7911 and #347 Key changes: * Introduced dedicated strict getters and deprecated magic ones for Content, ContentInfo, Location, VersionInfo, ContentType\FieldDefinition, User\User, Security\User, and SimplifiedRequest Value Object properties. * Replaced usages of magic getters with strict ones relevant to the issue * [Tests] Added coverage for strict getters * [Tests] Aligned tests with the changes * [Tests] Introduced symfony/phpunit-bridge deprecations helper * [Tests] Added coverage for the new deprecation message * [PHPStan] Aligned baseline with the changes * [PHPStan] Updated baseline after PHPStan release --------- Co-authored-by: Paweł Niedzielski <[email protected]> Co-authored-by: Konrad Oboza <[email protected]>
1 parent 216c669 commit 5848b1e

37 files changed

+716
-317
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"ibexa/code-style": "^1.0",
7070
"phpunit/phpunit": "^8.2",
7171
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
72-
"symfony/phpunit-bridge": "^5.1",
72+
"symfony/phpunit-bridge": "^5.4",
7373
"symfony/proxy-manager-bridge": "^5.3",
7474
"symfony/runtime": "^5.3.0",
7575
"phpstan/phpstan": "^1.2",

phpstan-baseline.neon

Lines changed: 75 additions & 150 deletions
Large diffs are not rendered by default.

phpunit-integration-legacy-solr.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<env name="KERNEL_CLASS" value="Ibexa\Contracts\Solr\Test\IbexaSolrTestKernel"/>
2222
<env name="SEARCH_ENGINE" value="solr"/>
2323
<env name="DATABASE_URL" value="sqlite://:memory:" />
24+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
2425
</php>
2526
<testsuites>
2627
<!-- Search service is used all over the place, so we must run entire integration test suite -->

phpunit-integration-legacy.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<env name="DATABASE_URL" value="sqlite://:memory:" />
2020
<env name="KERNEL_CLASS" value="Ibexa\Contracts\Core\Test\IbexaTestKernel"/>
2121
<env name="SEARCH_ENGINE" value="legacy"/>
22+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
2223
</php>
2324
<testsuites>
2425
<testsuite name="integration_core">

phpunit.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
>
1212
<php>
1313
<ini name="error_reporting" value="-1" />
14-
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
14+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[total]=576&amp;verbose=0"/>
1515
</php>
1616
<testsuites>
1717
<testsuite name="unit_core">
@@ -33,4 +33,7 @@
3333
<directory>tests/bundle/LegacySearchEngineBundle</directory>
3434
</testsuite>
3535
</testsuites>
36+
<listeners>
37+
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
38+
</listeners>
3639
</phpunit>

src/contracts/Repository/Values/Content/Content.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,24 @@
1515
/**
1616
* this class represents a content object in a specific version.
1717
*
18-
* @property-read \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo convenience getter for getVersionInfo()->getContentInfo()
19-
* @property-read int $id convenience getter for retrieving the contentId: $versionInfo->contentInfo->id
18+
* @property-read \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see Content::getContentInfo()} instead.
19+
* @property-read int $id @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see Content::getId()} instead.
2020
* @property-read \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $versionInfo calls getVersionInfo()
2121
* @property-read \Ibexa\Contracts\Core\Repository\Values\Content\Field[] $fields access fields, calls getFields()
2222
* @property-read \Ibexa\Contracts\Core\Repository\Values\Content\Thumbnail|null $thumbnail calls getThumbnail()
2323
*/
2424
abstract class Content extends ValueObject
2525
{
26+
public function getId(): int
27+
{
28+
return $this->getContentInfo()->getId();
29+
}
30+
31+
public function getContentInfo(): ContentInfo
32+
{
33+
return $this->getVersionInfo()->getContentInfo();
34+
}
35+
2636
/**
2737
* Returns the VersionInfo for this version.
2838
*

src/contracts/Repository/Values/Content/ContentInfo.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
/**
1616
* This class provides all version independent information of the Content object.
1717
*
18-
* @property-read int $id @deprecated Use {@see ContentInfo::getId} instead. The unique id of the Content object
18+
* @property-read int $id @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see ContentInfo::getId()} instead.
1919
* @property-read int $contentTypeId The unique id of the content type item the Content object is an instance of
20-
* @property-read string $name the computed name (via name schema) in the main language of the Content object
20+
* @property-read string $name @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see ContentInfo::getName()} instead.
2121
* @property-read int $sectionId @deprecated 4.6.2 Use {@see ContentInfo::getSectionId} instead. The section to which the Content object is assigned
2222
* @property-read int $currentVersionNo Current Version number is the version number of the published version or the version number of a newly created draft (which is 1).
2323
* @property-read bool $published true if there exists a published version false otherwise
@@ -29,7 +29,7 @@
2929
* @property-read string $mainLanguageCode The main language code of the Content object. If the available flag is set to true the Content is shown in this language if the requested language does not exist.
3030
* @property-read int|null $mainLocationId @deprecated Use {@see ContentInfo::getMainLocationId} instead
3131
* @property-read int $status status of the Content object
32-
* @property-read bool $isHidden status of the Content object
32+
* @property-read bool $isHidden @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see ContentInfo::isHidden()} instead.
3333
*/
3434
class ContentInfo extends ValueObject
3535
{
@@ -185,6 +185,11 @@ public function isTrashed(): bool
185185
return $this->status === self::STATUS_TRASHED;
186186
}
187187

188+
public function isHidden(): bool
189+
{
190+
return $this->isHidden;
191+
}
192+
188193
public function getContentType(): ContentType
189194
{
190195
return $this->contentType;
@@ -229,6 +234,11 @@ public function getId(): int
229234
{
230235
return $this->id;
231236
}
237+
238+
public function getName(): string
239+
{
240+
return $this->name;
241+
}
232242
}
233243

234244
class_alias(ContentInfo::class, 'eZ\Publish\API\Repository\Values\Content\ContentInfo');

src/contracts/Repository/Values/Content/Location.php

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
* This class represents a location in the repository.
1717
*
1818
* @property-read \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo calls getContentInfo()
19-
* @property-read int $contentId calls getContentInfo()->id
20-
* @property-read int $id the id of the location
19+
* @property-read int $contentId @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see Location::getContentId()} instead.
20+
* @property-read int $id @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see Location::getId()} instead.
2121
* @property-read int $priority Position of the Location among its siblings when sorted using priority
22-
* @property-read bool $hidden Indicates that the Location entity is hidden (explicitly or hidden by content).
23-
* @property-read bool $invisible Indicates that the Location is not visible, being either marked as hidden itself, or implicitly hidden by its Content or an ancestor Location
22+
* @property-read bool $hidden @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see Location::isHidden()} instead.
23+
* @property-read bool $invisible @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see Location::isInvisible()} instead.
2424
* @property-read bool $explicitlyHidden Indicates that the Location entity has been explicitly marked as hidden.
2525
* @property-read string $remoteId a global unique id of the content object
2626
* @property-read int $parentLocationId the id of the parent location
27-
* @property-read string $pathString @deprecated use {@see Location::getPathString()} instead.
28-
* @property-read array $path Same as $pathString but as array, e.g. [ 1, 2, 4, 23 ]
29-
* @property-read int $depth Depth location has in the location tree
27+
* @property-read string $pathString @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see Location::getPathString()} instead.
28+
* @property-read array $path @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see Location::getPath()} instead.
29+
* @property-read int $depth @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see Location::getDepth()} instead.
3030
* @property-read int $sortField Specifies which property the child locations should be sorted on. Valid values are found at {@link Location::SORT_FIELD_*}
3131
* @property-read int $sortOrder Specifies whether the sort order should be ascending or descending. Valid values are {@link Location::SORT_ORDER_*}
3232
*/
@@ -158,6 +158,13 @@ abstract class Location extends ValueObject
158158
*/
159159
protected $pathString;
160160

161+
/**
162+
* Same as {@see Location::$pathString} but as array, e.g.: <code>[ '1', '2', '4', '23' ]</code>.
163+
*
164+
* @var string[]
165+
*/
166+
protected array $path;
167+
161168
/**
162169
* Depth location has in the location tree.
163170
*
@@ -194,12 +201,22 @@ abstract class Location extends ValueObject
194201
abstract public function getContentInfo(): ContentInfo;
195202

196203
/**
197-
* Return the parent location of of this location.
204+
* Return the parent location of this location.
198205
*
199206
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Location|null
200207
*/
201208
abstract public function getParentLocation(): ?Location;
202209

210+
public function getId(): int
211+
{
212+
return $this->id;
213+
}
214+
215+
public function getContentId(): int
216+
{
217+
return $this->getContentInfo()->getId();
218+
}
219+
203220
/**
204221
* Returns true if current location is a draft.
205222
*
@@ -248,6 +265,62 @@ public function getPathString(): string
248265
{
249266
return $this->pathString;
250267
}
268+
269+
/**
270+
* Same as {@see Location::getPathString()} but as array, e.g.: <code>[ '1', '2', '4', '23' ]</code>.
271+
*
272+
* @return string[]
273+
*/
274+
public function getPath(): array
275+
{
276+
if (isset($this->path)) {
277+
return $this->path;
278+
}
279+
280+
$pathString = trim($this->pathString ?? '', '/');
281+
282+
return $this->path = !empty($pathString) ? explode('/', $pathString) : [];
283+
}
284+
285+
/**
286+
* Indicates that the Location is not visible, being either marked as hidden itself, or implicitly hidden by
287+
* its Content or an ancestor Location.
288+
*/
289+
public function isInvisible(): bool
290+
{
291+
return $this->invisible;
292+
}
293+
294+
/**
295+
* Indicates that the Location is hidden either explicitly or by content.
296+
*/
297+
public function isHidden(): bool
298+
{
299+
return $this->hidden;
300+
}
301+
302+
public function getDepth(): int
303+
{
304+
return $this->depth;
305+
}
306+
307+
public function __isset($property)
308+
{
309+
if ($property === 'path') {
310+
return true;
311+
}
312+
313+
return parent::__isset($property);
314+
}
315+
316+
public function __get($property)
317+
{
318+
if ($property === 'path') {
319+
return $this->getPath();
320+
}
321+
322+
return parent::__get($property);
323+
}
251324
}
252325

253326
class_alias(Location::class, 'eZ\Publish\API\Repository\Values\Content\Location');

src/contracts/Repository/Values/Content/VersionInfo.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @property-read \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo calls getContentInfo()
2020
* @property-read mixed $id the internal id of the version
21-
* @property-read int $versionNo the version number of this version (which only increments in scope of a single Content object)
21+
* @property-read int $versionNo @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see VersionInfo::getVersionNo()} instead.
2222
* @property-read \DateTime $modificationDate the last modified date of this version
2323
* @property-read \DateTime $creationDate the creation date of this version
2424
* @property-read mixed $creatorId the user id of the user which created this version
@@ -115,6 +115,11 @@ public function getLanguageCodes(): array
115115
return $this->languageCodes;
116116
}
117117

118+
public function getVersionNo(): int
119+
{
120+
return $this->versionNo;
121+
}
122+
118123
/**
119124
* Returns true if version is a draft.
120125
*

src/contracts/Repository/Values/ContentType/ContentType.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @property-read \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionCollection $fieldDefinitions calls getFieldDefinitions() or on access getFieldDefinition($fieldDefIdentifier)
2020
* @property-read mixed $id the id of the content type
2121
* @property-read int $status the status of the content type. One of ContentType::STATUS_DEFINED|ContentType::STATUS_DRAFT|ContentType::STATUS_MODIFIED
22-
* @property-read string $identifier the identifier of the content type
22+
* @property-read string $identifier @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see ContentType::getIdentifier()} instead.
2323
* @property-read \DateTime $creationDate the date of the creation of this content type
2424
* @property-read \DateTime $modificationDate the date of the last modification of this content type
2525
* @property-read mixed $creatorId the user id of the creator of this content type
@@ -176,6 +176,11 @@ abstract public function getContentTypeGroups();
176176
*/
177177
abstract public function getFieldDefinitions(): FieldDefinitionCollection;
178178

179+
public function getIdentifier(): string
180+
{
181+
return $this->identifier;
182+
}
183+
179184
/**
180185
* This method returns the field definition for the given identifier.
181186
*

0 commit comments

Comments
 (0)