Skip to content

Commit ceb4b77

Browse files
committed
arrow functions
1 parent 89b7e95 commit ceb4b77

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+167
-373
lines changed

src/AppTest.php

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class AppTest
2727
*/
2828
function test_array_access_with_provider()
2929
{
30-
$app = new App([], function($name) { return 'foo' == $name ? 'bar' : null; });
30+
$app = new App([], fn($name) => 'foo' == $name ? 'bar' : null);
3131

3232
$this->assertEquals('bar', $app['foo']);
3333
}
@@ -54,7 +54,7 @@ function test_config()
5454
*/
5555
function test_invoke_with_provider()
5656
{
57-
$app = new App([], function() { return 'bar'; });
57+
$app = new App([], fn() => 'bar');
5858

5959
$this->assertEquals('bar', $app('foo'));
6060
}
@@ -76,38 +76,28 @@ function test_provider_and_scope()
7676
{
7777
$app = new App([
7878
Arg::SERVICES => [
79-
'var3' => function() { return 'foobar'; },
79+
'var3' => fn() => 'foobar',
8080
'var2' => [Config::class, new Args(['var3' => new Plugin('var3')])],
81-
'bat' => function($var2) {
82-
return $var2['var3'];
83-
},
81+
'bat' => fn($var2) => $var2['var3'],
8482
Config::class => Config::class,
85-
'v3' => function() { return '6'; },
83+
'v3' => fn() => '6',
8684
'v2' => [Config::class, new Args(['v3' => new Plugin('v3')])],
87-
'var4' => function($v2) { return $v2['v3']; },
85+
'var4' => fn($v2) => $v2['v3'],
8886
'code' => 1,
8987
'foo' => new Plugins([
9088
'home' => 9,
9189
'var2' => new Plugin(Config::class, [new Args(['var3' => new Provide('var4')])]),
92-
Config::class => function($argv) {
93-
return new Config($argv);
94-
},
90+
Config::class => fn($argv) => new Config($argv),
9591
'code' => 2,
9692
'bar' => new Plugins([
9793
'code' => 5,
9894
Config::class => new Provide(Config::class), //Provide from parent
99-
'test' => function($bat, $code, $home, $var2, Config $config) {
100-
return function($param, $param2, Config $config) use($bat, $code, $home, $var2) {
101-
return $bat . $code . $home . $param . $var2['var3'] . $param2;
102-
};
103-
},
104-
'baz' => function() {
105-
return function($param2) {
106-
/** @var \Mvc5\Service\Plugin $this */
107-
108-
return $this->call('test', ['param' => '3', 'param2' => $param2]);
109-
};
110-
}
95+
'test' => fn($bat, $code, $home, $var2, Config $config) =>
96+
fn($param, $param2, Config $config) =>
97+
$bat . $code . $home . $param . $var2['var3'] . $param2,
98+
'baz' => fn() => fn($param2) => $this->call('test', ['param' => '3', 'param2' => $param2])
99+
100+
111101
])
112102
])
113103
]
@@ -129,9 +119,7 @@ function test_scope()
129119
{
130120
$app = new App([
131121
'services' => [
132-
'bar' => function() {
133-
return $this;
134-
},
122+
'bar' => fn() => $this,
135123
'foo' => new Plugin('bar')
136124
]
137125
], null, true);
@@ -149,9 +137,7 @@ function test_custom_scope()
149137

150138
$app = new App([
151139
'services' => [
152-
'bar' => function() {
153-
return $this;
154-
},
140+
'bar' => fn() => $this,
155141
'foo' => new Plugin('bar')
156142
]
157143
], null, $config);
@@ -167,12 +153,8 @@ function test_callable_closure_scope()
167153
{
168154
$app = new App([
169155
'services' => [
170-
'bar' => new Callback(function() {
171-
return $this;
172-
}),
173-
'foo' => new Invoke(function() {
174-
return $this;
175-
}),
156+
'bar' => new Callback(fn() => $this),
157+
'foo' => new Invoke(fn() => $this),
176158
]
177159
], null, true);
178160

@@ -189,12 +171,8 @@ function test_callable_closure_custom_scope()
189171

190172
$app = new App([
191173
'services' => [
192-
'bar' => new Callback(function() {
193-
return $this;
194-
}),
195-
'foo' => new Invoke(function() {
196-
return $this;
197-
}),
174+
'bar' => new Callback(fn() => $this),
175+
'foo' => new Invoke(fn() => $this),
198176
]
199177
], null, $config);
200178

@@ -209,12 +187,8 @@ function test_callable_closure_without_scope()
209187
{
210188
$app = new App([
211189
'services' => [
212-
'bar' => new Callback(function() {
213-
return $this;
214-
}),
215-
'foo' => new Invoke(function() {
216-
return $this;
217-
}),
190+
'bar' => new Callback(fn() => $this),
191+
'foo' => new Invoke(fn() => $this),
218192
]
219193
]);
220194

src/Controller/ActionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function test_call_controller()
1919
{
2020
$action = new Action(new App);
2121

22-
$this->assertEquals('foo', $action(function() { return 'foo'; }));
22+
$this->assertEquals('foo', $action(fn() => 'foo'));
2323
}
2424

2525
/**

src/Event/EventModelTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ function test_named_args()
1818
{
1919
$event = new TestEvent;
2020

21-
$callable = function($foo){
22-
return 'foo' . $foo;
23-
};
21+
$callable = fn($foo) => 'foo' . $foo;
2422

2523
$this->assertEquals('foo/bar', $event($callable, ['foo' => '/bar']));
2624
}
@@ -32,9 +30,7 @@ function test_no_args()
3230
{
3331
$event = new TestEvent;
3432

35-
$callable = function(Event $event){
36-
return $event->name();
37-
};
33+
$callable = fn(Event $event) => $event->name();
3834

3935
$this->assertEquals(TestEvent::class, $event($callable));
4036
}
@@ -46,9 +42,7 @@ function test_numeric_args()
4642
{
4743
$event = new TestEvent;
4844

49-
$callable = function($foo, $bar){
50-
return $foo. '/' . $bar;
51-
};
45+
$callable = fn($foo, $bar) => $foo. '/' . $bar;
5246

5347
$this->assertEquals('foo/bar', $event($callable, ['foo', 'bar']));
5448
}

src/Event/EventTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function test_named_args()
2828
{
2929
$event = new Event;
3030

31-
$this->assertEquals('bar', $event(function($bar, $foo) { return $foo; }, ['foo' => 'bar', 'bar' => 'baz']));
31+
$this->assertEquals('bar', $event(fn($bar, $foo) => $foo, ['foo' => 'bar', 'bar' => 'baz']));
3232
}
3333

3434
/**
@@ -38,7 +38,7 @@ function test_numeric_args()
3838
{
3939
$event = new Event;
4040

41-
$this->assertEquals('baz', $event(function($bar, $foo) { return $foo; }, ['bar', 'baz']));
41+
$this->assertEquals('baz', $event(fn($bar, $foo) => $foo, ['bar', 'baz']));
4242
}
4343

4444
/**
@@ -48,7 +48,7 @@ function test_stopped()
4848
{
4949
$event = new Event;
5050

51-
$event(function(Event $event) { $event->stop(); });
51+
$event(fn(Event $event) => $event->stop());
5252

5353
$this->assertTrue($event->stopped());
5454
}

src/Event/GeneratorTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,11 @@ function test_event_array()
109109
{
110110
$app = new App([
111111
'services' => [
112-
'test_event' => function() {
113-
return [
112+
'test_event' => fn() => [
114113
'@Mvc5\Test\Event\GeneratorTest::foo',
115114
'@Mvc5\Test\Event\GeneratorTest::bar',
116115
'@Mvc5\Test\Event\GeneratorTest::baz',
117-
];
118-
}
116+
]
119117
]
120118
]);
121119

src/Http/MiddlewareTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,8 @@ function test_reset()
3434
$middleware = new Middleware(
3535
new App,
3636
[
37-
function(HttpRequest $request, HttpResponse $response, callable $next) {
38-
return $next($request, $response);
39-
},
40-
function(HttpRequest $request, HttpResponse $response, callable $next) {
41-
return $next($request, $response);
42-
}
37+
fn(HttpRequest $request, HttpResponse $response, callable $next) => $next($request, $response),
38+
fn(HttpRequest $request, HttpResponse $response, callable $next) => $next($request, $response)
4339
]
4440
);
4541

src/Log/LoggerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ function test_message()
1818
{
1919
$logger = new Logger;
2020

21-
$this->assertEquals('foo', $logger(function() { return 'foo'; }));
22-
$this->assertEquals('foo', $logger(function($message) { return $message; }));
21+
$this->assertEquals('foo', $logger(fn() => 'foo'));
22+
$this->assertEquals('foo', $logger(fn($message) => $message));
2323
}
2424

2525
/**
@@ -29,7 +29,7 @@ function test_throw_exception_false()
2929
{
3030
$logger = new Logger;
3131

32-
$this->assertFalse($logger(function($throw_exception = false) { return $throw_exception; }));
32+
$this->assertFalse($logger(fn($throw_exception = false) => $throw_exception));
3333
}
3434

3535
/**
@@ -39,6 +39,6 @@ function test_throw_exception_true()
3939
{
4040
$logger = new Logger(true);
4141

42-
$this->assertTrue($logger(function($throw_exception) { return $throw_exception; }));
42+
$this->assertTrue($logger(fn($throw_exception) => $throw_exception));
4343
}
4444
}

src/Plugin/CallTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function test()
2828
*/
2929
function test_named()
3030
{
31-
$call = new Call(function($foo, $bar) { return $foo . $bar; });
31+
$call = new Call(fn($foo, $bar) => $foo . $bar);
3232

3333
$this->assertEquals('foobar', (new App)->plugin($call, ['foo' => 'foo', 'bar' => 'bar']));
3434
}
@@ -38,7 +38,7 @@ function test_named()
3838
*/
3939
function test_named_with_parent_args()
4040
{
41-
$call = new Call(function($foo, $bar) { return $foo . $bar; }, ['bar' => 'bar']);
41+
$call = new Call(fn($foo, $bar) => $foo . $bar, ['bar' => 'bar']);
4242

4343
$this->assertEquals('foobar', (new App)->plugin($call, ['foo' => 'foo']));
4444
}
@@ -48,7 +48,7 @@ function test_named_with_parent_args()
4848
*/
4949
function test_no_args()
5050
{
51-
$call = new Call(function() { return 'foobar'; });
51+
$call = new Call(fn() => 'foobar');
5252

5353
$this->assertEquals('foobar', (new App)->plugin($call));
5454
}
@@ -58,7 +58,7 @@ function test_no_args()
5858
*/
5959
function test_not_named()
6060
{
61-
$call = new Call(function($foo, $bar) { return $foo . $bar; });
61+
$call = new Call(fn($foo, $bar) => $foo . $bar);
6262

6363
$this->assertEquals('foobar', (new App)->plugin($call, ['foo', 'bar']));
6464
}
@@ -68,7 +68,7 @@ function test_not_named()
6868
*/
6969
function test_not_named_with_parent_args()
7070
{
71-
$call = new Call(function($foo, $bar) { return $foo . $bar; }, ['bar']);
71+
$call = new Call(fn($foo, $bar) => $foo . $bar, ['bar']);
7272

7373
$this->assertEquals('foobar', (new App)->plugin($call, ['foo']));
7474
}

src/Plugin/CallbackTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CallbackTest
1717
*/
1818
function test()
1919
{
20-
$scoped = new Callback(function(){});
20+
$scoped = new Callback(fn() => null);
2121

2222
$this->assertInstanceOf(\Closure::class, $scoped->closure());
2323
$this->assertFalse($scoped->scoped());
@@ -30,9 +30,7 @@ function test_app_scope()
3030
{
3131
$app = new App(null, null, true);
3232

33-
$result = $app->call(new Callback(function() {
34-
return $this;
35-
}));
33+
$result = $app->call(new Callback(fn() => $this));
3634

3735
$this->assertTrue($result === $app);
3836
}
@@ -44,9 +42,7 @@ function test_current_scope()
4442
{
4543
$app = new App;
4644

47-
$result = $app->call(new Callback(function() {
48-
return $this;
49-
}));
45+
$result = $app->call(new Callback(fn() => $this));
5046

5147
$this->assertTrue($result === $this);
5248
}

src/Plugin/ExpectTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ function test_exception()
4444
{
4545
(new App)(new Expect(
4646
new Call('@Mvc5\Exception::runtime', ['test']),
47-
new Call(function(\Throwable $e) {
48-
$this->assertEquals('test', $e->getMessage());
49-
})
47+
new Call(fn(\Throwable $e) => $this->assertEquals('test', $e->getMessage()))
5048
));
5149
}
5250

@@ -57,7 +55,7 @@ function test_exception_as_named_arg()
5755
{
5856
$result = (new App)(new Expect(
5957
new Call(function() { throw new \Exception('foo'); }),
60-
new Call(function(\Throwable $exception) { return $exception->getMessage(); }),
58+
new Call(fn(\Throwable $exception) => $exception->getMessage()),
6159
true
6260
));
6361

@@ -71,7 +69,7 @@ function test_exception_with_named_args()
7169
{
7270
$result = (new App)(new Expect(
7371
new Call(function() { throw new \Exception('foo'); }),
74-
new Call(function(\Throwable $exception, $argv) { return $exception->getMessage() . $argv['bar']; }),
72+
new Call(fn(\Throwable $exception, $argv) => $exception->getMessage() . $argv['bar']),
7573
true,
7674
true
7775
), ['bar' => 'bar']);
@@ -85,7 +83,7 @@ function test_exception_with_named_args()
8583
function test_named_args()
8684
{
8785
$result = (new App)(new Expect(
88-
new Call(function($b, $a) { return $a . $b; }, ['b' => new Value('bar')])
86+
new Call(fn($b, $a) => $a . $b, ['b' => new Value('bar')])
8987
), ['a' => 'foo']);
9088

9189
$this->assertEquals('foobar', $result);
@@ -96,7 +94,7 @@ function test_named_args()
9694
*/
9795
function test_not_named_args()
9896
{
99-
$result = (new App)(new Expect(new Call(function($a, $b) { return $a . $b; }, ['bar'])), ['foo']);
97+
$result = (new App)(new Expect(new Call(fn($a, $b) => $a . $b, ['bar'])), ['foo']);
10098

10199
$this->assertEquals('foobar', $result);
102100
}

0 commit comments

Comments
 (0)