ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ILIAS\CI\Rector\ChangeLicenseHeader Class Reference
+ Inheritance diagram for ILIAS\CI\Rector\ChangeLicenseHeader:
+ Collaboration diagram for ILIAS\CI\Rector\ChangeLicenseHeader:

Public Member Functions

 __construct ()
 
 getNodeTypes ()
 
 refactor (Node $node)
 
 getRuleDefinition ()
 

Data Fields

const EXISTING_LICENSE_PATTERN = '(copyright|Copyright|GPL-3\.0|GPLv3|LICENSE)'
 
const IGNORE_SUBPATHS = '(lib|vendor|data|Customizing)'
 

Private Member Functions

 filterComments (Node $node, array $default=[])
 

Private Attributes

string $license_header_default
 
Comment $standard_comment
 
array $previous_search
 

Detailed Description

Definition at line 28 of file ChangeLicenseHeader.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\CI\Rector\ChangeLicenseHeader::__construct ( )

Definition at line 63 of file ChangeLicenseHeader.php.

64  {
65  $this->standard_comment = new Comment($this->license_header_default);
66  }

Member Function Documentation

◆ filterComments()

ILIAS\CI\Rector\ChangeLicenseHeader::filterComments ( Node  $node,
array  $default = [] 
)
private
Returns
Comment[]

Definition at line 114 of file ChangeLicenseHeader.php.

References $comment.

Referenced by ILIAS\CI\Rector\ChangeLicenseHeader\refactor().

114  : array
115  {
116  foreach ($node->getComments() as $comment) {
117  if (preg_match(self::EXISTING_LICENSE_PATTERN, $comment->getText()) > 0) {
118  continue;
119  }
120  $default[] = $comment;
121  }
122  return $default;
123  }
$comment
Definition: buildRTE.php:72
+ Here is the caller graph for this function:

◆ getNodeTypes()

ILIAS\CI\Rector\ChangeLicenseHeader::getNodeTypes ( )
Returns
class-string[]

Definition at line 71 of file ChangeLicenseHeader.php.

71  : array
72  {
73  return [
74  Node\Stmt\Class_::class,
75  Node\Stmt\Interface_::class,
76  Node\Stmt\Trait_::class
77  ];
78  }

◆ getRuleDefinition()

ILIAS\CI\Rector\ChangeLicenseHeader::getRuleDefinition ( )

Definition at line 125 of file ChangeLicenseHeader.php.

125  : RuleDefinition
126  {
127  return new RuleDefinition(
128  'Adds or replaces a license-header in each class-file',
129  [
130  new CodeSample(
131  // code before
132  '',
133  // code after
134  ''
135  ),
136  ]
137  );
138  }

◆ refactor()

ILIAS\CI\Rector\ChangeLicenseHeader::refactor ( Node  $node)
Parameters
Node\Stmt\Global_$node

Definition at line 83 of file ChangeLicenseHeader.php.

References ILIAS\CI\Rector\ChangeLicenseHeader\filterComments().

84  {
85  if (preg_match(self::IGNORE_SUBPATHS, $this->file->getFilePath()) > 0) {
86  return $node;
87  }
88  $node->setAttribute('comments', $this->filterComments($node));
89  $current = $node;
90  $previous = $node->getAttribute(AttributeKeys::PREVIOUS_NODE);
91  while (is_object($previous) && in_array($previous::class, $this->previous_search)) {
92  if ($previous instanceof \PhpParser\Node\Name) {
93  $previous = $previous->getAttribute(AttributeKeys::PARENT_NODE);
94  }
95  if ($previous instanceof Node\Expr\Empty_) {
96  $this->removeNode($previous);
97  }
98  $current = $previous;
99  $current->setAttribute(
100  AttributeKeys::COMMENTS,
101  $this->filterComments($current)
102  );
103  $previous = $current->getAttribute(AttributeKeys::PREVIOUS_NODE);
104  }
105 
106  $current->setAttribute(AttributeKeys::COMMENTS, $this->filterComments($current, [$this->standard_comment]));
107 
108  return $node;
109  }
filterComments(Node $node, array $default=[])
+ Here is the call graph for this function:

Field Documentation

◆ $license_header_default

string ILIAS\CI\Rector\ChangeLicenseHeader::$license_header_default
private
Initial value:
= "/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/
"

Definition at line 32 of file ChangeLicenseHeader.php.

◆ $previous_search

array ILIAS\CI\Rector\ChangeLicenseHeader::$previous_search
private
Initial value:
= [
Node\Stmt\If_::class,
Node\Expr\Empty_::class,
Node\Stmt\Global_::class,
Node\Expr\Include_::class,
Node\Stmt\Use_::class,
Node\Stmt\Namespace_::class,
Node\Name::class,
Node\Stmt\Class_::class,
Node\Stmt\Expression::class,
Node\Stmt\Declare_::class,
]

Definition at line 50 of file ChangeLicenseHeader.php.

◆ $standard_comment

Comment ILIAS\CI\Rector\ChangeLicenseHeader::$standard_comment
private

Definition at line 49 of file ChangeLicenseHeader.php.

◆ EXISTING_LICENSE_PATTERN

const ILIAS\CI\Rector\ChangeLicenseHeader::EXISTING_LICENSE_PATTERN = '(copyright|Copyright|GPL-3\.0|GPLv3|LICENSE)'

Definition at line 30 of file ChangeLicenseHeader.php.

◆ IGNORE_SUBPATHS

const ILIAS\CI\Rector\ChangeLicenseHeader::IGNORE_SUBPATHS = '(lib|vendor|data|Customizing)'

Definition at line 31 of file ChangeLicenseHeader.php.


The documentation for this class was generated from the following file: