From b80f04f07af59905e16ef56f480c89847eb3f4d2 Mon Sep 17 00:00:00 2001 From: Marcos Coelho Date: Fri, 27 Oct 2023 19:40:29 -0300 Subject: [PATCH] refactoring: code standarding --- classes/PHPMock.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/classes/PHPMock.php b/classes/PHPMock.php index 484be96..2a12b03 100644 --- a/classes/PHPMock.php +++ b/classes/PHPMock.php @@ -8,7 +8,6 @@ use phpmock\Deactivatable; use PHPUnit\Event\Facade; use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Runner\Version; use ReflectionClass; use ReflectionProperty; use SebastianBergmann\Template\Template; @@ -44,8 +43,9 @@ trait PHPMock { public static $templatesPath = '/tmp'; - private $openInvocation = 'new \PHPUnit\Framework\MockObject\Invocation('; - private $openWrapper = '\phpmock\phpunit\DefaultArgumentRemover::removeDefaultArgumentsWithReflection('; + private $phpunitVersionClass = '\\PHPUnit\\Runner\\Version'; + private $openInvocation = 'new \\PHPUnit\\Framework\\MockObject\\Invocation('; + private $openWrapper = '\\phpmock\\phpunit\\DefaultArgumentRemover::removeDefaultArgumentsWithReflection('; private $closeFunc = ')'; /** @@ -180,7 +180,7 @@ private function prepareCustomTemplates() $templates = []; - $prefix = 'phpmock-phpunit-' . Version::id() . '-'; + $prefix = 'phpmock-phpunit-' . $this->getPhpUnitVersion() . '-'; foreach ($directoryIterator as $fileinfo) { if ($fileinfo->getExtension() !== 'tpl') { @@ -219,10 +219,13 @@ private function prepareCustomTemplates() private function shouldPrepareCustomTemplates() { - $phpunitVersionClass = 'PHPUnit\\Runner\\Version'; + return class_exists($this->phpunitVersionClass) + && version_compare($this->getPhpUnitVersion(), '10.0.0') >= 0; + } - return class_exists($phpunitVersionClass) - && version_compare(call_user_func([$phpunitVersionClass, 'id']), '10.0.0') >= 0; + private function getPhpUnitVersion() + { + return call_user_func([$this->phpunitVersionClass, 'id']); } /**