diff --git a/src/PhpPact/Consumer/Matcher/Matchers/AbstractMatcher.php b/src/PhpPact/Consumer/Matcher/Matchers/AbstractMatcher.php index 5326bc33..d7d7b956 100644 --- a/src/PhpPact/Consumer/Matcher/Matchers/AbstractMatcher.php +++ b/src/PhpPact/Consumer/Matcher/Matchers/AbstractMatcher.php @@ -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 diff --git a/src/PhpPact/Consumer/Matcher/Matchers/GeneratorAwareMatcher.php b/src/PhpPact/Consumer/Matcher/Matchers/GeneratorAwareMatcher.php index 41301f30..4d2d5bfb 100644 --- a/src/PhpPact/Consumer/Matcher/Matchers/GeneratorAwareMatcher.php +++ b/src/PhpPact/Consumer/Matcher/Matchers/GeneratorAwareMatcher.php @@ -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 diff --git a/src/PhpPact/Consumer/Matcher/Trait/FormatterAwareTrait.php b/src/PhpPact/Consumer/Matcher/Trait/FormatterAwareTrait.php new file mode 100644 index 00000000..d6931257 --- /dev/null +++ b/src/PhpPact/Consumer/Matcher/Trait/FormatterAwareTrait.php @@ -0,0 +1,26 @@ +formatter = new ValueOptionalFormatter(); + } + + public function setFormatter(FormatterInterface $formatter): void + { + $this->formatter = $formatter; + } + + public function getFormatter(): FormatterInterface + { + return $this->formatter; + } +} diff --git a/src/PhpPact/Consumer/Matcher/Trait/GeneratorAwareTrait.php b/src/PhpPact/Consumer/Matcher/Trait/GeneratorAwareTrait.php new file mode 100644 index 00000000..78a7f1a0 --- /dev/null +++ b/src/PhpPact/Consumer/Matcher/Trait/GeneratorAwareTrait.php @@ -0,0 +1,20 @@ +generator = $generator; + } + + public function getGenerator(): ?GeneratorInterface + { + return $this->generator; + } +}