Skip to content

Commit 7c44f93

Browse files
committed
Add lesson for simple Make Static refactoring
1 parent cf2b6d5 commit 7c44f93

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Make Static
4+
*
5+
* Make method static.
6+
*
7+
*/
8+
9+
namespace Refactoring16\JetBrains;
10+
11+
// 1. Make method split static.
12+
class Splitter
13+
{
14+
private $delimiter;
15+
16+
public function __construct($delimiter)
17+
{
18+
$this->delimiter = $delimiter;
19+
}
20+
21+
public function split($subject)
22+
{
23+
return explode($this->delimiter, $subject);
24+
}
25+
}
26+
27+
// 2. Note that calls to Splitter::split() have updated to static calls
28+
// as well as a new argument with instance have been provided.
29+
$splitter = new Splitter(' ');
30+
$myArray = $splitter->split('This is a test');
31+
$myCsvRecord = $splitter->split('PhpStorm JetBrains');

0 commit comments

Comments
 (0)