Skip to content

Commit

Permalink
Merge pull request #598 from tienvx/extract-traits
Browse files Browse the repository at this point in the history
refactor: Extract traits
  • Loading branch information
tienvx committed May 10, 2024
2 parents 4b15877 + 73a5914 commit d9b24d7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 30 deletions.
20 changes: 2 additions & 18 deletions src/PhpPact/Consumer/Matcher/Matchers/AbstractMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,13 @@

namespace PhpPact\Consumer\Matcher\Matchers;

use PhpPact\Consumer\Matcher\Formatters\ValueOptionalFormatter;
use PhpPact\Consumer\Matcher\Model\Attributes;
use PhpPact\Consumer\Matcher\Model\FormatterInterface;
use PhpPact\Consumer\Matcher\Model\MatcherInterface;
use PhpPact\Consumer\Matcher\Trait\FormatterAwareTrait;

abstract class AbstractMatcher implements MatcherInterface
{
private FormatterInterface $formatter;

public function __construct()
{
$this->formatter = new ValueOptionalFormatter();
}

public function setFormatter(FormatterInterface $formatter): void
{
$this->formatter = $formatter;
}

public function getFormatter(): FormatterInterface
{
return $this->formatter;
}
use FormatterAwareTrait;

/**
* @return string|array<string, mixed>
Expand Down
14 changes: 2 additions & 12 deletions src/PhpPact/Consumer/Matcher/Matchers/GeneratorAwareMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,11 @@
use PhpPact\Consumer\Matcher\Exception\GeneratorNotRequiredException;
use PhpPact\Consumer\Matcher\Exception\GeneratorRequiredException;
use PhpPact\Consumer\Matcher\Model\GeneratorAwareInterface;
use PhpPact\Consumer\Matcher\Model\GeneratorInterface;
use PhpPact\Consumer\Matcher\Trait\GeneratorAwareTrait;

abstract class GeneratorAwareMatcher extends AbstractMatcher implements GeneratorAwareInterface
{
private ?GeneratorInterface $generator = null;

public function setGenerator(?GeneratorInterface $generator): void
{
$this->generator = $generator;
}

public function getGenerator(): ?GeneratorInterface
{
return $this->generator;
}
use GeneratorAwareTrait;

/**
* @return string|array<string, mixed>
Expand Down
26 changes: 26 additions & 0 deletions src/PhpPact/Consumer/Matcher/Trait/FormatterAwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace PhpPact\Consumer\Matcher\Trait;

use PhpPact\Consumer\Matcher\Formatters\ValueOptionalFormatter;
use PhpPact\Consumer\Matcher\Model\FormatterInterface;

trait FormatterAwareTrait
{
private FormatterInterface $formatter;

public function __construct()
{
$this->formatter = new ValueOptionalFormatter();
}

public function setFormatter(FormatterInterface $formatter): void
{
$this->formatter = $formatter;
}

public function getFormatter(): FormatterInterface
{
return $this->formatter;
}
}
20 changes: 20 additions & 0 deletions src/PhpPact/Consumer/Matcher/Trait/GeneratorAwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace PhpPact\Consumer\Matcher\Trait;

use PhpPact\Consumer\Matcher\Model\GeneratorInterface;

trait GeneratorAwareTrait
{
private ?GeneratorInterface $generator = null;

public function setGenerator(?GeneratorInterface $generator): void
{
$this->generator = $generator;
}

public function getGenerator(): ?GeneratorInterface
{
return $this->generator;
}
}

0 comments on commit d9b24d7

Please sign in to comment.