Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan-Hendrik Willms
Stud.IP
Commits
e1a10fa9
Commit
e1a10fa9
authored
3 months ago
by
Jan-Hendrik Willms
Browse files
Options
Downloads
Patches
Plain Diff
course block type changes rector
parent
80aeb934
No related branches found
Branches containing commit
No related tags found
1 merge request
!18
Draft: add rector and provide initial set of rectors for stud.ip 6.0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/Rectors/Studip-6.0-Set.php
+2
-1
2 additions, 1 deletion
lib/Rectors/Studip-6.0-Set.php
lib/Rectors/Studip60/RewriteCoursewareBlockTypesRector.php
+60
-0
60 additions, 0 deletions
lib/Rectors/Studip60/RewriteCoursewareBlockTypesRector.php
rector-test.php
+42
-0
42 additions, 0 deletions
rector-test.php
with
104 additions
and
1 deletion
lib/Rectors/Studip-6.0-Set.php
+
2
−
1
View file @
e1a10fa9
...
...
@@ -8,7 +8,8 @@ use Studip\Rectors\Studip60\RemoveIncludesRector;
return
RectorConfig
::
configure
()
->
withRules
([
Studip\Rectors\Studip60\RemoveGetConfigRector
::
class
,
Studip\Rectors\Studip60\RemoveSidebarMethodsRector
::
class
Studip\Rectors\Studip60\RemoveSidebarMethodsRector
::
class
,
Studip\Rectors\Studip60\RewriteCoursewareBlockTypesRector
::
class
,
])
->
withConfiguredRule
(
RenameFunctionRector
::
class
,
[
'studip_json_decode'
=>
'json_decode'
,
...
...
This diff is collapsed.
Click to expand it.
lib/Rectors/Studip60/RewriteCoursewareBlockTypesRector.php
0 → 100644
+
60
−
0
View file @
e1a10fa9
<?php
declare
(
strict_types
=
1
);
namespace
Studip\Rectors\Studip60
;
use
PhpParser\Node
;
use
PhpParser\Node\Expr\StaticCall
;
use
PhpParser\Node\Stmt\Class_
;
use
PhpParser\Node\Stmt\ClassMethod
;
use
Rector\Rector\AbstractRector
;
final
class
RewriteCoursewareBlockTypesRector
extends
AbstractRector
{
public
function
getNodeTypes
():
array
{
return
[
StaticCall
::
class
,
Class_
::
class
];
}
/**
* @param StaticCall|Class_ $node
*/
public
function
refactor
(
Node
$node
)
{
if
(
$this
->
shouldSkip
(
$node
))
{
return
null
;
}
if
(
$node
instanceof
Class_
)
{
$this
->
traverseNodesWithCallable
(
$node
->
getMethods
(),
[
$this
,
'refactor'
]
);
return
null
;
}
elseif
(
$node
instanceof
ClassMethod
)
{
$node
->
returnType
=
new
Node\Identifier
(
'string'
);
return
$node
;
}
elseif
(
$node
instanceof
StaticCall
)
{
return
$node
->
args
[
0
]
->
value
;
}
}
public
function
shouldSkip
(
Node
$node
):
bool
{
return
!
(
$node
instanceof
Class_
&&
$this
->
isName
(
$node
->
extends
,
'Courseware\BlockTypes\BlockType'
)
)
&&
!
(
$node
instanceof
ClassMethod
&&
$this
->
isName
(
$node
->
name
,
'getJsonSchema'
)
&&
$this
->
isName
(
$node
->
returnType
,
'Opis\JsonSchema\Schema'
)
)
&&
!
(
$node
instanceof
StaticCall
&&
$this
->
isName
(
$node
->
class
,
'Opis\JsonSchema\Schema'
)
&&
$this
->
isName
(
$node
->
name
,
'fromJsonString'
)
);
}
}
This diff is collapsed.
Click to expand it.
rector-test.php
+
42
−
0
View file @
e1a10fa9
...
...
@@ -51,3 +51,45 @@ try {
echo
'some exception'
;
}
class
TestBlockType
extends
\Courseware\BlockTypes\BlockType
{
public
static
function
getType
():
string
{
return
''
;
}
public
static
function
getTitle
():
string
{
return
''
;
}
public
static
function
getDescription
():
string
{
return
''
;
}
public
function
initialPayload
():
array
{
return
[];
}
public
static
function
getCategories
():
array
{
return
[];
}
public
static
function
getContentTypes
():
array
{
return
[];
}
public
static
function
getFileTypes
():
array
{
return
[];
}
public
static
function
getJsonSchema
():
\Opis\JsonSchema\Schema
{
return
\Opis\JsonSchema\Schema
::
fromJsonString
(
file_get_contents
(
__FILE__
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment