Skip to content

Commit

Permalink
changed trait method names
Browse files Browse the repository at this point in the history
  • Loading branch information
orlyk-rollun committed Jan 25, 2023
1 parent e0e10ef commit ac7e573
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
10 changes: 7 additions & 3 deletions src/Domain/Traits/ProblemTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@ trait ProblemTrait
* @param ArrayObjectItemInterface $problem
* @return void
*/
public function addProblem(mixed $problem)
public function addProblemItem(mixed $problem)
{
if ($this->problems === null) {
$this->problems = new ArrayObject(true);
}

$this->problems->addItem(new ArrayObjectItem($problem));
if (!$problem instanceof ArrayObjectItem) {
$problem = new ArrayObjectItem($problem);
}

$this->problems->addItem($problem);
}

/**
* @param $problem
* @return bool
*/
public function hasProblem($problem): bool
public function hasProblemItem($problem): bool
{
if (isset($this->problems)) {
return $this->problems->hasItem($problem);
Expand Down
14 changes: 9 additions & 5 deletions src/Domain/Traits/TagTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait TagTrait
/**
* @var ArrayObject|null
*/
protected $tags;
protected ?ArrayObject $tags = null;

protected function enclose(string $tag)
{
Expand All @@ -26,21 +26,25 @@ protected function enclose(string $tag)
* @param string $tag
* @return void
*/
public function addTag(string $tag): void
public function addTagItem(ArrayObjectItem|string $tag): void
{
$tag = $this->enclose($tag);
if ($this->tags === null) {
$this->tags = new ArrayObject(true);
}

if (is_string($tag)) {
$tag = new ArrayObjectItem($tag);
}

$this->tags->addItem(new ArrayObjectItem($tag));
$this->tags->addItem($tag);
}

/**
* @param $tag
* @return bool
*/
public function hasTag($tag): bool
public function hasTagItem($tag): bool
{
$tag = $this->enclose($tag);
if (isset($this->tags)) {
Expand All @@ -50,7 +54,7 @@ public function hasTag($tag): bool
return false;
}

public function deleteTag(string $tag)
public function deleteTagItem(string $tag)
{
$tag = $this->enclose($tag);
if ($this->tags !== null) {
Expand Down
14 changes: 7 additions & 7 deletions test/unit/Domain/Traits/TagTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function testAddTag()
use TagTrait;
};

$instance->addTag('hello');
$instance->addTagItem('hello');

$property = new \ReflectionProperty($instance, 'tags');
$property->setAccessible(true);
Expand All @@ -33,17 +33,17 @@ public function testHasTag()
use TagTrait;
};

$instance->addTag('#hello#');
$instance->addTagItem('#hello#');

$result = $instance->hasTag('hello');
$result = $instance->hasTagItem('hello');

$this->assertTrue($result);

$result = $instance->hasTag('#hello#');
$result = $instance->hasTagItem('#hello#');

$this->assertTrue($result);

$result = $instance->hasTag('world');
$result = $instance->hasTagItem('world');

$this->assertFalse($result);
}
Expand All @@ -54,9 +54,9 @@ public function testDeleteTag()
use TagTrait;
};

$instance->addTag('#hello#');
$instance->addTagItem('#hello#');

$instance->deleteTag('hello');
$instance->deleteTagItem('hello');

$property = new \ReflectionProperty($instance, 'tags');
$property->setAccessible(true);
Expand Down

0 comments on commit ac7e573

Please sign in to comment.