-
Notifications
You must be signed in to change notification settings - Fork 28
/
playground.php
122 lines (106 loc) · 3.29 KB
/
playground.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace AdoY\PHP\Refactoring\Toolbox;
use I\Am\Really\Useless as NobodyLovesMe;
use I\Am\Usefull as Lover;
class Playground
{
private $renameMe = 10;
/**
* Place your cursor on a local variable and press <Leader>rlv
* to rename a function local variable
*/
public function testRenameLocalVariable($renameMe)
{
$renameMe = 'renameMe will be renamed';
$renameMeAlso = $renameMe;
$this->renameMe = 'I will be renamed in the next test';
}
/**
* Place your cursor on a class variable and press <Leader>rcv
* to rename a property (class variable)
*/
public function testRenameClassVariable($renameMe)
{
$this->renameMe = 'RenameMe rename every usage of this property in the current class';
$renameMe = 'I\'m not renamed';
}
/**
* Place your cursor on a method name and press <Leader>rm
* to rename a method
*/
public function testRenameMethod()
{
$this->testRenameMethod();
}
/**
* Place your cursor on a Fully qualified class name and press <Leader>eu
* to create an alias and place the new Use statement on top of the file
*/
public function testExtractUse(\Fully\Qualified\Classname $obj)
{
if (!$obj instanceof \Fully\Qualified\Classname) {
Throw new Exception('$obj is not a \Fully\Qualified\Classname');
}
return new \Fully\Qualified\AnOtherClassname;
}
/**
* Select the content you want to place in the content with the visual mode
* (you could use viw on int or va' on string)
* and then press <Leader>ec to create a constant and replace every occurence of this
* by the constant usage
*/
public function testExtractConst()
{
$dix = 1001;
$string = 'FOOBAR';
}
/**
* Place your cursor on the "localVariableWanabeAClassVariable" variable
* and press <Leader>ep to promote this variable as class property
*/
public function testExtractClassProperty($newval)
{
$localVariableWanabeAClassVariable = $newval;
}
/**
* Select different block of code and extract it to different methods using
* <Leader>em
*/
public function testExtractMethod($message)
{
// Make a very cool wave with the message
for ($i = 0; $i < strlen($message); $i++) {
$message[$i] = $i % 2 ? strtoupper($message[$i]) : strtolower($message[$i]);
}
// Put the message in a fancy box
$borderTopAndBottom = '+' . str_repeat('=', strlen($message)+2) . '+';
$newMessage = $borderTopAndBottom . PHP_EOL;
$newMessage .= '| ' . $message . ' |' . PHP_EOL;
$newMessage .= $borderTopAndBottom . PHP_EOL;
return $newMessage;
}
/**
* Press <Leader>np to create a property
*/
public function testCreateNewProperty()
{
$this->notCreated;
}
/**
* Press <Leader>du to detect unused use statements
*/
public function testDetectUnusedStatements()
{
new Lover;
}
/**
* Select the inner function block
* and press <Leader>== to align all assignements
*/
public function testAlignAssigns()
{
$oneVar = 'Foo';
$anOtherVar = 'Bar';
$oneVar += 'Baz';
}
}