Skip to content

Commit

Permalink
add do not add in constructor interface
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinDev committed Nov 12, 2023
1 parent df1c0df commit 7b3de24
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/RectorizeTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace League\Plates;

use League\Plates\Template\DoNotAddItInConstructorInterface;
use League\Plates\Template\Template;
use League\Plates\Template\TemplateClass;
use League\Plates\Template\TemplateClassInterface;
Expand All @@ -27,6 +28,7 @@
*/
final class RectorizeTemplate extends AbstractRector
{
const CLASS_TO_NOT_ADD_IN_CONSTRUCTOR = [Template::class, TemplateClass::class, DoNotAddItInConstructorInterface::class];
/**
* @readonly
* @var \Rector\Core\NodeAnalyzer\ParamAnalyzer
Expand Down Expand Up @@ -108,8 +110,10 @@ public function refactor(Node $node) : ?Node
$methodDocBlock = $displayMethod?->getDocComment()?->getText() ?? '';
foreach($displayMethod->params as $parameter) {
$paramType = $this->paramTypeResolver->resolve($parameter);
if ($paramType instanceof FullyQualifiedObjectType && in_array($paramType->getClassName(), [Template::class, TemplateClass::class], true))
continue;
if ($paramType instanceof FullyQualifiedObjectType
&& in_array($paramType->getClassName(), self::CLASS_TO_NOT_ADD_IN_CONSTRUCTOR, true)) {
continue;
}

$paramDocBlock = $this->getParameterDocblock($methodDocBlock, $this->getName($parameter));
if ($paramDocBlock !== null)
Expand Down
7 changes: 7 additions & 0 deletions src/Template/DoNotAddItInConstructorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace League\Plates\Template;

interface DoNotAddItInConstructorInterface // so retrieve from data
{
}

0 comments on commit 7b3de24

Please sign in to comment.