Skip to content

Commit 39fd6db

Browse files
WIP
1 parent ce4da19 commit 39fd6db

File tree

7 files changed

+49
-102
lines changed

7 files changed

+49
-102
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
1010

1111
- Added support for PHP 8
1212

13+
### Changed
14+
15+
- Internal PHP 8 code updates
16+
1317
### Removed
1418

1519
- Removed support for PHP 7

src/Item.php

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,23 @@
44

55
class Item
66
{
7-
/**
8-
* The current value being handled.
9-
*
10-
* @var mixed
11-
*/
12-
protected $value;
7+
protected mixed $value;
138

14-
/**
15-
* @param mixed $value The value you want to process.
16-
*/
17-
public function __construct($value)
9+
public function __construct(mixed $value)
1810
{
1911
$this->value = $value;
2012

2113
if (! defined('PIPED_VALUE')) {
22-
define('PIPED_VALUE', 'PIPED_VALUE-' . uniqid());
14+
define('PIPED_VALUE', 'PIPED_VALUE-'.uniqid('', true));
2315
}
2416
}
2517

26-
/**
27-
* @param string $name
28-
* @param array $arguments
29-
*
30-
* @return mixed
31-
*/
32-
public function __call($name, $arguments)
18+
public function __call(string $name, array $arguments): mixed
3319
{
3420
return $this->pipe($name, ...$arguments);
3521
}
3622

37-
/**
38-
* Perform an operation on the current value.
39-
*
40-
* @param callable|string|object $callback
41-
* @param array ...$arguments
42-
*
43-
* @return \SebastiaanLuca\PipeOperator\Item|\SebastiaanLuca\PipeOperator\PipeProxy
44-
*/
45-
public function pipe($callback, ...$arguments)
23+
public function pipe(callable|object|string $callback, mixed ...$arguments): Item|PipeProxy
4624
{
4725
if (! is_callable($callback)) {
4826
return new PipeProxy($this, $callback);
@@ -55,14 +33,7 @@ public function pipe($callback, ...$arguments)
5533
return $this;
5634
}
5735

58-
/**
59-
* Add the given value to the list of arguments.
60-
*
61-
* @param array $arguments
62-
*
63-
* @return array
64-
*/
65-
public function addValueToArguments(array $arguments) : array
36+
public function addValueToArguments(array $arguments): array
6637
{
6738
// If the caller hasn't explicitly specified where they want the value
6839
// to be added, we will add it as the first value. Otherwise we will
@@ -77,12 +48,7 @@ public function addValueToArguments(array $arguments) : array
7748
}, $arguments);
7849
}
7950

80-
/**
81-
* Get the current value.
82-
*
83-
* @return mixed
84-
*/
85-
public function get()
51+
public function get(): mixed
8652
{
8753
return $this->value;
8854
}

src/PipeProxy.php

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,16 @@
66

77
class PipeProxy
88
{
9-
/**
10-
* @var \SebastiaanLuca\PipeOperator\Item
11-
*/
12-
protected $item;
9+
protected Item $item;
10+
protected object $object;
1311

14-
/**
15-
* @var object
16-
*/
17-
protected $object;
18-
19-
/**
20-
* @param \SebastiaanLuca\PipeOperator\Item $item
21-
* @param object $object
22-
*/
23-
public function __construct(Item $item, $object)
12+
public function __construct(Item $item, object $object)
2413
{
2514
$this->item = $item;
2615
$this->object = $object;
2716
}
2817

29-
/**
30-
* @param string $method
31-
* @param array $arguments
32-
*
33-
* @return \SebastiaanLuca\PipeOperator\Item
34-
*/
35-
public function __call($method, array $arguments)
18+
public function __call(string $method, array $arguments): Item
3619
{
3720
$callback = Closure::bind(function (...$arguments) use ($method) {
3821
return $this->{$method}(...$arguments);

src/functions.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
if (! function_exists('take')) {
66
/**
77
* Create a new piped item from a given value.
8-
*
9-
* @param mixed $value The value you want to process.
10-
*
11-
* @return \SebastiaanLuca\PipeOperator\Item
128
*/
13-
function take($value) : Item
9+
function take(mixed $value): Item
1410
{
1511
return new Item($value);
1612
}

tests/Unit/IdentifierTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class IdentifierTest extends TestCase
99
/**
1010
* @test
1111
*/
12-
public function it uses the identifier to replace the value() : void
12+
public function it uses the identifier to replace the value(): void
1313
{
1414
$this->assertSame(
1515
'key',
@@ -22,7 +22,7 @@ public function it uses the identifier to replace the value() : void
2222
/**
2323
* @test
2424
*/
25-
public function it uses the identifier to replace the value using the method directly() : void
25+
public function it uses the identifier to replace the value using the method directly(): void
2626
{
2727
$this->assertSame(
2828
'key',

tests/Unit/MethodsTest.php

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class MethodsTest extends TestCase
1010
/**
1111
* @test
1212
*/
13-
public function it can transform a value using a callable string method() : void
13+
public function it can transform a value using a callable string method(): void
1414
{
1515
$this->assertSame(
1616
'STRING',
@@ -23,7 +23,7 @@ public function it can transform a value using a callable string method
2323
/**
2424
* @test
2525
*/
26-
public function it can transform a value using a callable string method using the method directly() : void
26+
public function it can transform a value using a callable string method using the method directly(): void
2727
{
2828
$this->assertSame(
2929
'STRING',
@@ -36,13 +36,13 @@ public function it can transform a value using a callable string method
3636
/**
3737
* @test
3838
*/
39-
public function it can transform a value using a closure() : void
39+
public function it can transform a value using a closure(): void
4040
{
4141
$this->assertSame(
4242
'prefixed-string',
4343
take('string')
4444
->pipe(function (string $value) {
45-
return 'prefixed-' . $value;
45+
return 'prefixed-'.$value;
4646
})
4747
->get()
4848
);
@@ -51,7 +51,20 @@ public function it can transform a value using a closure() : void
5151
/**
5252
* @test
5353
*/
54-
public function it can transform a value using a public class method() : void
54+
public function it can transform a value using a short closure(): void
55+
{
56+
$this->assertSame(
57+
'prefixed-string',
58+
take('string')
59+
->pipe(fn (string $value): string => 'prefixed-'.$value)
60+
->get()
61+
);
62+
}
63+
64+
/**
65+
* @test
66+
*/
67+
public function it can transform a value using a public class method(): void
5568
{
5669
$this->assertSame(
5770
'UPPERCASE',
@@ -64,7 +77,7 @@ public function it can transform a value using a public class method()
6477
/**
6578
* @test
6679
*/
67-
public function it can transform a value using a proxied public class method() : void
80+
public function it can transform a value using a proxied public class method(): void
6881
{
6982
$this->assertSame(
7083
'UPPERCASE',
@@ -77,7 +90,7 @@ public function it can transform a value using a proxied public class 
7790
/**
7891
* @test
7992
*/
80-
public function it can transform a value using a private class method() : void
93+
public function it can transform a value using a private class method(): void
8194
{
8295
$this->assertSame(
8396
'lowercase',
@@ -90,7 +103,7 @@ public function it can transform a value using a private class method()
90103
/**
91104
* @test
92105
*/
93-
public function it can transform a value using a proxied private class method() : void
106+
public function it can transform a value using a proxied private class method(): void
94107
{
95108
$this->assertSame(
96109
'start-add-this',
@@ -104,7 +117,7 @@ public function it can transform a value using a proxied private class
104117
/**
105118
* @test
106119
*/
107-
public function it can transform a value while accepting pipe parameters() : void
120+
public function it can transform a value while accepting pipe parameters(): void
108121
{
109122
$this->assertSame(
110123
['KEY' => 'value'],
@@ -117,7 +130,7 @@ public function it can transform a value while accepting pipe parameters
117130
/**
118131
* @test
119132
*/
120-
public function it can transform a value while accepting pipe parameters using the method directly() : void
133+
public function it can transform a value while accepting pipe parameters using the method directly(): void
121134
{
122135
$this->assertSame(
123136
['KEY' => 'value'],
@@ -127,32 +140,17 @@ public function it can transform a value while accepting pipe parameters
127140
);
128141
}
129142

130-
/**
131-
* @param string $value
132-
*
133-
* @return string
134-
*/
135-
public function uppercase(string $value) : string
143+
public function uppercase(string $value): string
136144
{
137145
return mb_strtoupper($value);
138146
}
139147

140-
/**
141-
* @param string $value
142-
*
143-
* @return string
144-
*/
145-
private function lowercase(string $value) : string
148+
private function lowercase(string $value): string
146149
{
147150
return mb_strtolower($value);
148151
}
149152

150-
/**
151-
* @param array ...$values
152-
*
153-
* @return string
154-
*/
155-
private function join(...$values) : string
153+
private function join(string ...$values): string
156154
{
157155
return implode('-', $values);
158156
}

tests/Unit/ObjectTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ObjectTest extends TestCase
1010
/**
1111
* @test
1212
*/
13-
public function it returns an item object when get has not been called yet() : void
13+
public function it returns an item object when get has not been called yet(): void
1414
{
1515
$this->assertInstanceOf(
1616
Item::class,
@@ -21,7 +21,7 @@ public function it returns an item object when get has not been called
2121
/**
2222
* @test
2323
*/
24-
public function it returns an item object when get has not been called yet using the method directly() : void
24+
public function it returns an item object when get has not been called yet using the method directly(): void
2525
{
2626
$this->assertInstanceOf(
2727
Item::class,
@@ -32,7 +32,7 @@ public function it returns an item object when get has not been called
3232
/**
3333
* @test
3434
*/
35-
public function it can transform a complex value in multiple steps() : void
35+
public function it can transform a complex value in multiple steps(): void
3636
{
3737
$this->assertSame(
3838
'blog',
@@ -48,7 +48,7 @@ public function it can transform a complex value in multiple steps() : v
4848
/**
4949
* @test
5050
*/
51-
public function it can transform a complex value in multiple steps using the method directly() : void
51+
public function it can transform a complex value in multiple steps using the method directly(): void
5252
{
5353
$this->assertSame(
5454
'blog',
@@ -63,7 +63,7 @@ public function it can transform a complex value in multiple steps usin
6363
/**
6464
* @test
6565
*/
66-
public function it can transform a complex value in multiple steps using different method calls() : void
66+
public function it can transform a complex value in multiple steps using different method calls(): void
6767
{
6868
$this->assertSame(
6969
'blog',

0 commit comments

Comments
 (0)