-
-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rectorphp/rector-src@78829b3 Decouple ConstructorClassMethodFactory (#1269)
- Loading branch information
1 parent
976ae72
commit fd1f097
Showing
8 changed files
with
73 additions
and
43 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
rules/Compatibility/NodeFactory/ConstructorClassMethodFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
namespace Rector\Compatibility\NodeFactory; | ||
|
||
use PhpParser\Node\Param; | ||
use PhpParser\Node\Stmt\Class_; | ||
use PhpParser\Node\Stmt\ClassMethod; | ||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; | ||
use Rector\Compatibility\ValueObject\PropertyWithPhpDocInfo; | ||
use Rector\Core\ValueObject\MethodName; | ||
use Rector\DeadCode\PhpDoc\TagRemover\ParamTagRemover; | ||
final class ConstructorClassMethodFactory | ||
{ | ||
/** | ||
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory | ||
*/ | ||
private $phpDocInfoFactory; | ||
/** | ||
* @var \Rector\DeadCode\PhpDoc\TagRemover\ParamTagRemover | ||
*/ | ||
private $paramTagRemover; | ||
public function __construct(\Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory $phpDocInfoFactory, \Rector\DeadCode\PhpDoc\TagRemover\ParamTagRemover $paramTagRemover) | ||
{ | ||
$this->phpDocInfoFactory = $phpDocInfoFactory; | ||
$this->paramTagRemover = $paramTagRemover; | ||
} | ||
/** | ||
* @param PropertyWithPhpDocInfo[] $requiredPropertiesWithPhpDocInfos | ||
* @param Param[] $params | ||
*/ | ||
public function createConstructorClassMethod(array $requiredPropertiesWithPhpDocInfos, array $params) : \PhpParser\Node\Stmt\ClassMethod | ||
{ | ||
$classMethod = new \PhpParser\Node\Stmt\ClassMethod(\Rector\Core\ValueObject\MethodName::CONSTRUCT, ['flags' => \PhpParser\Node\Stmt\Class_::MODIFIER_PUBLIC, 'params' => $params]); | ||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod); | ||
foreach ($requiredPropertiesWithPhpDocInfos as $requiredPropertyWithPhpDocInfo) { | ||
$paramTagValueNode = $requiredPropertyWithPhpDocInfo->getParamTagValueNode(); | ||
$phpDocInfo->addTagValueNode($paramTagValueNode); | ||
} | ||
$this->paramTagRemover->removeParamTagsIfUseless($phpDocInfo, $classMethod); | ||
return $classMethod; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters