function it_should_define_percentage_of_target_nodes(ObjectCollection $collection, Relationship $relationship) { $collection->count()->willReturn(100); $relationship->hasPercentage()->willReturn(false); $relationship->getEndNode()->willReturn('person'); $this->getTargetNodesCount($relationship, $collection)->shouldBe(60); $collection->count()->willReturn(1); $relationship->hasPercentage()->willReturn(false); $relationship->getEndNode()->willReturn('person'); $this->getTargetNodesCount($relationship, $collection)->shouldBe(1); $collection->count()->willReturn(1000); $relationship->hasPercentage()->willReturn(false); $this->getTargetNodesCount($relationship, $collection)->shouldBe(200); $collection->count()->willReturn(100); $relationship->hasPercentage()->willReturn(true); $relationship->getPercentage()->willReturn(65); $this->getTargetNodesCount($relationship, $collection)->shouldBe(65); $collection->count()->willReturn(1000); $relationship->hasPercentage()->willReturn(true); $relationship->getPercentage()->willReturn(45); $this->getTargetNodesCount($relationship, $collection)->shouldBe(450); }
/** * @param RelationshipDefinition $relationship * @param ObjectCollection $targetNodes * @return int */ public function getTargetNodesCount(RelationshipDefinition $relationship, ObjectCollection $targetNodes) { $targetCount = $targetNodes->count(); if ($relationship->hasPercentage()) { $pct = $relationship->getPercentage(); } else { $pct = $targetCount <= 100 ? 60 : 20; } $percentage = $pct / 100; $count = round($targetCount * $percentage); return (int) $count; }