move build methods to from Builder to Rector

This commit is contained in:
TomasVotruba 2018-02-24 11:01:33 +01:00
parent c9435ee9a2
commit 7c109a0749
2 changed files with 18 additions and 54 deletions

View File

@ -46,8 +46,6 @@ final class CaseRector extends AbstractRector
}
}
dump($this->methodName);
if ($this->methodName) {
if (! $this->methodCallAnalyzer->isMethod($node, $this->methodName)) {
return false;
@ -65,26 +63,30 @@ final class CaseRector extends AbstractRector
die;
}
public function setMethodCallType(string $methodCallType): void
public function matchMethodCallByType(string $methodCallType): self
{
$this->methodCallType = $methodCallType;
return $this;
}
public function setMethodName(string $methodName): void
public function matchMethodName(string $methodName): self
{
$this->methodName = $methodName;
return $this;
}
public function setNewMethodName(string $newMethodName): void
public function changeMethodNameTo(string $newMethodName): self
{
$this->newMethodName = $newMethodName;
return $this;
}
/**
* @param mixed $value
*/
public function addNewArgument(int $position, $value): void
public function addArgument(int $position, $value): self
{
$this->newArguments[$position] = $value;
return $this;
}
}

View File

@ -8,11 +8,6 @@ use Rector\NodeChanger\PropertyAdder;
final class CaseRectorBuilder
{
/**
* @var CaseRector|null
*/
private $caseRector;
/**
* @var MethodCallAnalyzer
*/
@ -28,57 +23,24 @@ final class CaseRectorBuilder
*/
private $propertyAdder;
public function __construct(MethodCallAnalyzer $methodCallAnalyzer, ExpressionAdder $expressionAdder, PropertyAdder $propertyAdder)
{
public function __construct(
MethodCallAnalyzer $methodCallAnalyzer,
ExpressionAdder $expressionAdder,
PropertyAdder $propertyAdder
) {
$this->methodCallAnalyzer = $methodCallAnalyzer;
$this->expressionAdder = $expressionAdder;
$this->propertyAdder = $propertyAdder;
}
public function matchMethodCallByType(string $methodCallType): self
public function create(): CaseRector
{
$this->getCaseRector()->setMethodCallType($methodCallType);
return $this;
}
$caseRector = new CaseRector($this->methodCallAnalyzer);
public function matchMethodName(string $methodName): self
{
$this->getCaseRector()->setMethodName($methodName);
return $this;
}
public function changeMethodNameTo(string $newMethodName): self
{
$this->getCaseRector()->setNewMethodName($newMethodName);
return $this;
}
public function addArgument(int $position, $value): self
{
$this->getCaseRector()->addNewArgument($position, $value);
return $this;
}
public function build(): CaseRector
{
$caseRector = $this->caseRector;
$this->caseRector = null;
// @required setter DI replacement
$caseRector->setExpressionAdder($this->expressionAdder);
$caseRector->setPropertyToClassAdder($this->propertyAdder);
return $caseRector;
}
private function getCaseRector(): CaseRector
{
if ($this->caseRector) {
return $this->caseRector;
}
$this->caseRector = new CaseRector($this->methodCallAnalyzer);
// @required setter DI replacement
$this->caseRector->setExpressionAdder($this->expressionAdder);
$this->caseRector->setPropertyToClassAdder($this->propertyAdder);
return $this->caseRector;
}
}