Skip to content

Commit fab7b75

Browse files
authored
Merge pull request #1 from julles/analysis-q1ORjy
Apply fixes from StyleCI
2 parents 472716a + fac0960 commit fab7b75

File tree

4 files changed

+111
-100
lines changed

4 files changed

+111
-100
lines changed

example.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
2-
include "vendor/autoload.php";
2+
3+
include 'vendor/autoload.php';
34
echo $str = stringer('azer')
4-
->reverse()
5-
->replace("a","i")
6-
->repeat(2," ")
7-
->display();
5+
->reverse()
6+
->replace('a', 'i')
7+
->repeat(2, ' ')
8+
->display();

src/Stringer.php

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php namespace RezaAr\Stringer;
1+
<?php
2+
3+
namespace RezaAr\Stringer;
24

35
class Stringer
46
{
@@ -30,80 +32,88 @@ public function custom(callable $call)
3032
return $this;
3133
}
3234

33-
public function camelCase($separator = " ")
35+
public function camelCase($separator = ' ')
3436
{
35-
$string = $this->string;
37+
$string = $this->string;
3638
$explode = explode($separator, $string);
37-
$result = "";
39+
$result = '';
3840
foreach ($explode as $index => $row) {
3941
$result .= ucfirst($row);
4042
}
4143
$this->string = $result;
44+
4245
return $this;
4346
}
4447

45-
public function appendFirst($first="")
48+
public function appendFirst($first = '')
4649
{
47-
$this->string = $first.$this->string;
48-
return $this;
50+
$this->string = $first.$this->string;
51+
52+
return $this;
4953
}
5054

51-
public function appendLast($last="")
55+
public function appendLast($last = '')
5256
{
53-
$this->string = $this->string.$last;
54-
return $this;
57+
$this->string = $this->string.$last;
58+
59+
return $this;
5560
}
5661

57-
public function repeat($loop=1,$separator="")
62+
public function repeat($loop = 1, $separator = '')
5863
{
59-
$result="";
60-
for($a=0;$a<$loop;$a++)
61-
{
62-
$result .= $this->string.$separator;
63-
}
64-
$this->string = $result;
65-
return $this;
64+
$result = '';
65+
for ($a = 0; $a < $loop; $a++) {
66+
$result .= $this->string.$separator;
67+
}
68+
$this->string = $result;
69+
70+
return $this;
6671
}
6772

6873
public function upperFirst()
6974
{
70-
$this->string = ucfirst($this->string);
71-
return $this;
75+
$this->string = ucfirst($this->string);
76+
77+
return $this;
7278
}
7379

7480
public function lowerFirst()
7581
{
76-
$this->string = lcfirst($this->string);
77-
return $this;
82+
$this->string = lcfirst($this->string);
83+
84+
return $this;
7885
}
7986

8087
public function upperLast()
8188
{
82-
$last = ucfirst(strrev($this->string));
83-
$this->string = strrev($last);
84-
return $this;
89+
$last = ucfirst(strrev($this->string));
90+
$this->string = strrev($last);
91+
92+
return $this;
8593
}
8694

8795
public function lowerLast()
8896
{
89-
$last = lcfirst(strrev($this->string));
90-
$this->string = strrev($last);
91-
return $this;
97+
$last = lcfirst(strrev($this->string));
98+
$this->string = strrev($last);
99+
100+
return $this;
92101
}
93102

94-
public function replace($search,$replace)
103+
public function replace($search, $replace)
95104
{
96-
$replace = str_replace($search, $replace, $this->string);
105+
$replace = str_replace($search, $replace, $this->string);
97106

98-
$this->string = $replace;
107+
$this->string = $replace;
99108

100-
return $this;
109+
return $this;
101110
}
102111

103112
public function shuffle()
104113
{
105-
$this->string = str_shuffle($this->string);
106-
return $this;
114+
$this->string = str_shuffle($this->string);
115+
116+
return $this;
107117
}
108118

109119
public function display()

src/str.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
function stringer($str)
44
{
5-
return (new RezaAr\Stringer\Stringer($str));
6-
}
5+
return new RezaAr\Stringer\Stringer($str);
6+
}

tests/StringerTest.php

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
<?php namespace Testing;
1+
<?php
2+
3+
namespace Testing;
24

35
use PHPUnit\Framework\TestCase;
46

57
class StringerTest extends TestCase
68
{
79
public function testReverse()
810
{
9-
$result = "azer";
10-
11-
$stringer = stringer("reza")
11+
$result = 'azer';
12+
13+
$stringer = stringer('reza')
1214
->reverse()
1315
->display();
14-
16+
1517
$this->assertEquals($result, $stringer);
1618
}
1719

1820
public function testSubstring()
1921
{
20-
$result = "r";
22+
$result = 'r';
2123

22-
$string = stringer("reza")
24+
$string = stringer('reza')
2325
->substring(0, 1)
2426
->display();
2527

@@ -28,11 +30,11 @@ public function testSubstring()
2830

2931
public function testCustom()
3032
{
31-
$result = "reza ar";
33+
$result = 'reza ar';
3234

33-
$string = stringer("reza")
35+
$string = stringer('reza')
3436
->custom(function ($string) {
35-
return $string . ' ar';
37+
return $string.' ar';
3638
})
3739
->display();
3840

@@ -41,112 +43,110 @@ public function testCustom()
4143

4244
public function testCamelCase()
4345
{
44-
$result = "CamelCase";
46+
$result = 'CamelCase';
4547

46-
$string = stringer("camel case")
47-
->camelCase()
48+
$string = stringer('camel case')
49+
->camelCase()
4850
->display();
4951

5052
$this->assertEquals($result, $string);
5153
}
5254

5355
public function testAppendFirst()
5456
{
55-
$result = "muhamad reza";
57+
$result = 'muhamad reza';
5658

57-
$string = stringer("reza")
58-
->appendFirst("muhamad ")
59-
->display();
59+
$string = stringer('reza')
60+
->appendFirst('muhamad ')
61+
->display();
6062

61-
$this->assertEquals($result,$string);
63+
$this->assertEquals($result, $string);
6264
}
6365

6466
public function testAppendLast()
6567
{
66-
$result = "muhamad reza";
68+
$result = 'muhamad reza';
6769

68-
$string = stringer("muhamad")
69-
->appendLast(" reza")
70-
->display();
70+
$string = stringer('muhamad')
71+
->appendLast(' reza')
72+
->display();
7173

72-
$this->assertEquals($result,$string);
74+
$this->assertEquals($result, $string);
7375
}
7476

7577
public function testRepeat()
7678
{
77-
$result = "reza reza ";
79+
$result = 'reza reza ';
7880

79-
$string = stringer("reza")
80-
->repeat(2," ")
81-
->display();
81+
$string = stringer('reza')
82+
->repeat(2, ' ')
83+
->display();
8284

83-
$this->assertEquals($result,$string);
85+
$this->assertEquals($result, $string);
8486
}
8587

8688
public function testUpperFirst()
8789
{
88-
$result = "Reza";
90+
$result = 'Reza';
8991

90-
$string = stringer("reza")
91-
->upperFirst()
92-
->display();
92+
$string = stringer('reza')
93+
->upperFirst()
94+
->display();
9395

94-
$this->assertEquals($result,$string);
96+
$this->assertEquals($result, $string);
9597
}
9698

9799
public function testLowerFirst()
98100
{
99-
$result = "reza";
101+
$result = 'reza';
100102

101-
$string = stringer("Reza")
102-
->lowerFirst()
103-
->display();
103+
$string = stringer('Reza')
104+
->lowerFirst()
105+
->display();
104106

105-
$this->assertEquals($result,$string);
107+
$this->assertEquals($result, $string);
106108
}
107109

108110
public function testUpperLast()
109111
{
110-
$result = "rezA";
112+
$result = 'rezA';
111113

112-
$string = stringer("reza")
113-
->upperLast()
114-
->display();
114+
$string = stringer('reza')
115+
->upperLast()
116+
->display();
115117

116-
$this->assertEquals($result,$string);
118+
$this->assertEquals($result, $string);
117119
}
118120

119121
public function testLowerLast()
120122
{
121-
$result = "reza";
123+
$result = 'reza';
122124

123-
$string = stringer("rezA")
124-
->lowerLast()
125-
->display();
125+
$string = stringer('rezA')
126+
->lowerLast()
127+
->display();
126128

127-
$this->assertEquals($result,$string);
129+
$this->assertEquals($result, $string);
128130
}
129131

130132
public function testReplace()
131133
{
132-
$result = "PHP is Awesome";
134+
$result = 'PHP is Awesome';
133135

134-
$string = stringer("GO is Awesome")
135-
->replace("GO","PHP")
136-
->display();
136+
$string = stringer('GO is Awesome')
137+
->replace('GO', 'PHP')
138+
->display();
137139

138-
$this->assertEquals($result,$string);
140+
$this->assertEquals($result, $string);
139141
}
140142

141143
public function testDisplay()
142144
{
143-
$var = "PHP is Awesome";
145+
$var = 'PHP is Awesome';
144146

145-
$string = stringer($var)
146-
->display();
147+
$string = stringer($var)
148+
->display();
147149

148-
$this->assertEquals($var,$string);
150+
$this->assertEquals($var, $string);
149151
}
150-
151-
152152
}

0 commit comments

Comments
 (0)