Skip to content

Commit

Permalink
Merge pull request #926 from oat-sa/feature/adf-494/improve-depends-o…
Browse files Browse the repository at this point in the history
…n-property-collection-setter

Feature/ADF-494/Improve depends on property collection getter
  • Loading branch information
shpran authored Oct 8, 2021
2 parents ec8f285 + a7208a2 commit 9cb677b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
25 changes: 13 additions & 12 deletions core/kernel/classes/class.Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public function __construct($uri, $debug = '')

$this->lgDependent = null;
$this->multiple = null;
$this->dependsOnPropertyCollection = new DependsOnPropertyCollection();
}

/**
Expand Down Expand Up @@ -228,22 +227,24 @@ public function setRange(core_kernel_classes_Class $class)
return (bool) $returnValue;
}

/**
* @TODO Improve getter
*/
public function getDependsOnPropertyCollection(): DependsOnPropertyCollection
{
$dependsOnProperty = $this->getProperty(GenerisRdf::PROPERTY_DEPENDS_ON_PROPERTY);
$dependsOnPropertyValues = $this->getPropertyValues($dependsOnProperty);

foreach ($dependsOnPropertyValues as $dependsOnPropertyValue) {
if ($dependsOnPropertyValue !== GenerisRdf::PROPERTY_DEPENDS_ON_PROPERTY) {
$this->dependsOnPropertyCollection->append(
$this->getProperty($dependsOnPropertyValue)
);
if (!isset($this->dependsOnPropertyCollection)) {
$dependsOnProperty = $this->getProperty(GenerisRdf::PROPERTY_DEPENDS_ON_PROPERTY);
$dependsOnPropertyValues = $this->getPropertyValues($dependsOnProperty);
$this->dependsOnPropertyCollection = new DependsOnPropertyCollection();

foreach ($dependsOnPropertyValues as $dependsOnPropertyValue) {
if ($dependsOnPropertyValue !== GenerisRdf::PROPERTY_DEPENDS_ON_PROPERTY) {
$this->dependsOnPropertyCollection->append(
$this->getProperty($dependsOnPropertyValue)
);
}
}
}

$this->dependsOnPropertyCollection->rewind();

return $this->dependsOnPropertyCollection;
}

Expand Down
5 changes: 5 additions & 0 deletions core/resource/DependsOnPropertyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ static function (core_kernel_classes_Property $property) {
);
}

public function isEmpty(): bool
{
return $this->count() === 0;
}

private function areArraysEqual(array $array1, array $array2): bool
{
return empty(array_diff($array1, $array2)) && empty(array_diff($array2, $array1));
Expand Down
8 changes: 8 additions & 0 deletions test/unit/core/resource/DependsOnPropertyCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,12 @@ public function testGetPropertyUris(): void
$this->sut->append($secondProperty);
$this->assertEquals(['firstProperty', 'secondProperty'], $this->sut->getPropertyUris());
}

public function testIsEmpty(): void
{
$this->assertTrue($this->sut->isEmpty());

$this->sut->append('value');
$this->assertFalse($this->sut->isEmpty());
}
}

0 comments on commit 9cb677b

Please sign in to comment.