ILIAS  release_8 Revision v8.24
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 60 of file ChangeLicenseHeader.php.

61 {
62 $this->standard_comment = new Comment($this->license_header_default);
63 }

Member Function Documentation

◆ filterComments()

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

Definition at line 109 of file ChangeLicenseHeader.php.

109 : array
110 {
111 foreach ($node->getComments() as $comment) {
112 if (preg_match(self::EXISTING_LICENSE_PATTERN, $comment->getText()) > 0) {
113 continue;
114 }
115 $default[] = $comment;
116 }
117 return $default;
118 }
$comment
Definition: buildRTE.php:72

References $comment.

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

+ Here is the caller graph for this function:

◆ getNodeTypes()

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

Definition at line 68 of file ChangeLicenseHeader.php.

68 : array
69 {
70 return [
71 Node\Stmt\Class_::class,
72 Node\Stmt\Interface_::class,
73 Node\Stmt\Trait_::class
74 ];
75 }

◆ getRuleDefinition()

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

Definition at line 120 of file ChangeLicenseHeader.php.

120 : RuleDefinition
121 {
122 return new RuleDefinition(
123 'Adds or replaces a license-header in each class-file',
124 [
125 new CodeSample(
126 // code before
127 '',
128 // code after
129 ''
130 ),
131 ]
132 );
133 }

◆ refactor()

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

Definition at line 80 of file ChangeLicenseHeader.php.

80 : ?Node
81 {
82 if (preg_match(self::IGNORE_SUBPATHS, $this->file->getSmartFileInfo()->getPathname()) > 0) {
83 return $node;
84 }
85 $node->setAttribute('comments', $this->filterComments($node));
86 $current = $node;
87 $previous = $node->getAttribute(AttributeKeys::PREVIOUS_NODE);
88 while (is_object($previous) && in_array(get_class($previous), $this->previous_search)) {
89 if ($previous instanceof \PhpParser\Node\Name) {
90 $previous = $previous->getAttribute(AttributeKeys::PARENT_NODE);
91 }
92 $current = $previous;
93 $current->setAttribute(
94 AttributeKeys::COMMENTS,
95 $this->filterComments($current)
96 );
97 $previous = $current->getAttribute(AttributeKeys::PREVIOUS_NODE);
98 }
99
100 $current->setAttribute(AttributeKeys::COMMENTS, $this->filterComments($current, [$this->standard_comment]));
101
102 return $node;
103 }
filterComments(Node $node, array $default=[])

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

+ 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\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: