From 962dea0613868c9cf13348e15c6e2130aa8816ec Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 29 Aug 2017 15:23:06 +0200 Subject: [PATCH] feat(type) Use strict types. --- Source/Option.php | 3 +- Source/Prelude.php | 2 + Test/Integration/Documentation.php | 31 +++++------ Test/Unit/Option.php | 87 +++++++++++++++--------------- 4 files changed, 64 insertions(+), 59 deletions(-) diff --git a/Source/Option.php b/Source/Option.php index 81468e2..9015535 100644 --- a/Source/Option.php +++ b/Source/Option.php @@ -1,5 +1,7 @@ given( @@ -70,7 +71,7 @@ public function case_readme_0() ->isTrue(); } - public function case_readme_1() + public function case_readme_1(): void { $this ->when($result = Some(42)->unwrap()) @@ -78,24 +79,24 @@ public function case_readme_1() ->integer($result) ->isEqualTo(42) - ->exception(function () { + ->exception(function (): void { None()->unwrap(); }) ->isInstanceOf(RuntimeException::class); } - public function case_readme_2() + public function case_readme_2(): void { $this ->given($x = None()) - ->exception(function () use ($x) { + ->exception(function () use ($x): void { $x->expect('Damn…'); }) ->isInstanceOf(RuntimeException::class) ->hasMessage('Damn…'); } - public function case_readme_3() + public function case_readme_3(): void { $this ->given( @@ -113,7 +114,7 @@ public function case_readme_3() ->isEqualTo(153); } - public function case_readme_4() + public function case_readme_4(): void { $this ->given( @@ -134,7 +135,7 @@ public function case_readme_4() ->isEqualTo(153); } - public function case_readme_5() + public function case_readme_5(): void { $this ->given( @@ -152,7 +153,7 @@ public function case_readme_5() ->isEqualTo(None()); } - public function case_readme_6() + public function case_readme_6(): void { $this ->given($x = None()) @@ -162,7 +163,7 @@ public function case_readme_6() ->isEqualTo(Some(0)); } - public function case_readme_7() + public function case_readme_7(): void { $this ->given( @@ -177,7 +178,7 @@ public function case_readme_7() ->isEqualTo(Some(0)); } - public function case_readme_8() + public function case_readme_8(): void { $this ->when($result = Some(42)->and(Some(153))) @@ -196,7 +197,7 @@ public function case_readme_8() ->isEqualTo(None()); } - public function case_readme_9() + public function case_readme_9(): void { $this ->given( @@ -218,7 +219,7 @@ public function case_readme_9() ->isEqualTo(None()); } - public function case_readme_10() + public function case_readme_10(): void { $this ->when($result = Some(42)->or(Some(153))) @@ -232,7 +233,7 @@ public function case_readme_10() ->isEqualTo(Some(153)); } - public function case_readme_11() + public function case_readme_11(): void { $this ->given( diff --git a/Test/Unit/Option.php b/Test/Unit/Option.php index 2a095d5..5ff0435 100644 --- a/Test/Unit/Option.php +++ b/Test/Unit/Option.php @@ -1,5 +1,7 @@ when($result = Some(42)) @@ -65,7 +66,7 @@ public function case_function_some() ->isEqualTo(42); } - public function case_function_none() + public function case_function_none(): void { $this ->when($result = None()) @@ -78,7 +79,7 @@ public function case_function_none() ->isEqualTo(42); } - public function case_some() + public function case_some(): void { $this ->when($result = Some(42)) @@ -89,10 +90,10 @@ public function case_some() ->isEqualTo(42); } - public function case_some_null() + public function case_some_null(): void { $this - ->exception(function () { + ->exception(function (): void { Some(null); }) ->isInstanceOf(RuntimeException::class) @@ -102,7 +103,7 @@ public function case_some_null() ); } - public function case_none() + public function case_none(): void { $this ->when($result = None()) @@ -113,7 +114,7 @@ public function case_none() ->isEqualTo(42); } - public function case_some_is_some() + public function case_some_is_some(): void { $this ->given($option = Some(42)) @@ -123,7 +124,7 @@ public function case_some_is_some() ->isTrue(); } - public function case_none_is_some() + public function case_none_is_some(): void { $this ->given($option = None()) @@ -133,7 +134,7 @@ public function case_none_is_some() ->isFalse(); } - public function case_some_is_none() + public function case_some_is_none(): void { $this ->given($option = Some(42)) @@ -143,7 +144,7 @@ public function case_some_is_none() ->isFalse(); } - public function case_none_is_none() + public function case_none_is_none(): void { $this ->given($option = None()) @@ -153,7 +154,7 @@ public function case_none_is_none() ->isTrue(); } - public function case_some_expect() + public function case_some_expect(): void { $this ->given($option = Some(42)) @@ -163,18 +164,18 @@ public function case_some_expect() ->isEqualTo(42); } - public function case_none_expect() + public function case_none_expect(): void { $this ->given($option = None()) - ->exception(function () use ($option) { + ->exception(function () use ($option): void { $option->expect('foo'); }) ->isInstanceOf(RuntimeException::class) ->hasMessage('foo'); } - public function case_some_unwrap() + public function case_some_unwrap(): void { $this ->given($option = Some(42)) @@ -184,18 +185,18 @@ public function case_some_unwrap() ->isEqualTo(42); } - public function case_none_unwrap() + public function case_none_unwrap(): void { $this ->given($option = None()) - ->exception(function () use ($option) { + ->exception(function () use ($option): void { $option->unwrap(); }) ->isInstanceOf(RuntimeException::class) ->hasMessage('Called `' . SUT::class . '::unwrap` on a none value.'); } - public function case_some_unwrap_or() + public function case_some_unwrap_or(): void { $this ->given($option = Some(42)) @@ -205,7 +206,7 @@ public function case_some_unwrap_or() ->isEqualTo(42); } - public function case_none_unwrap_or() + public function case_none_unwrap_or(): void { $this ->given($option = None()) @@ -215,7 +216,7 @@ public function case_none_unwrap_or() ->isEqualTo(153); } - public function case_some_unwrap_or_else() + public function case_some_unwrap_or_else(): void { $this ->given( @@ -230,7 +231,7 @@ public function case_some_unwrap_or_else() ->isEqualTo(42); } - public function case_none_unwrap_or_else() + public function case_none_unwrap_or_else(): void { $this ->given( @@ -245,7 +246,7 @@ public function case_none_unwrap_or_else() ->isEqualTo(153); } - public function case_some_map() + public function case_some_map(): void { $this ->given( @@ -262,7 +263,7 @@ public function case_some_map() ->isEqualTo(84); } - public function case_none_map() + public function case_none_map(): void { $this ->given( @@ -279,7 +280,7 @@ public function case_none_map() ->isEqualTo(153); } - public function case_some_map_or() + public function case_some_map_or(): void { $this ->given( @@ -296,7 +297,7 @@ public function case_some_map_or() ->isEqualTo(84); } - public function case_none_map_or() + public function case_none_map_or(): void { $this ->given( @@ -313,7 +314,7 @@ public function case_none_map_or() ->isEqualTo(153); } - public function case_some_map_or_else() + public function case_some_map_or_else(): void { $this ->given( @@ -333,7 +334,7 @@ public function case_some_map_or_else() ->isEqualTo(84); } - public function case_none_map_or_else() + public function case_none_map_or_else(): void { $this ->given( @@ -353,7 +354,7 @@ public function case_none_map_or_else() ->isEqualTo(153); } - public function case_some_and_some() + public function case_some_and_some(): void { $this ->given( @@ -366,7 +367,7 @@ public function case_some_and_some() ->isIdenticalTo($rightOption); } - public function case_some_and_none() + public function case_some_and_none(): void { $this ->given( @@ -379,7 +380,7 @@ public function case_some_and_none() ->isIdenticalTo($rightOption); } - public function case_none_and_some() + public function case_none_and_some(): void { $this ->given( @@ -393,7 +394,7 @@ public function case_none_and_some() ->isNotIdenticalTo($option); } - public function case_none_and_none() + public function case_none_and_none(): void { $this ->given( @@ -407,7 +408,7 @@ public function case_none_and_none() ->isNotIdenticalTo($option); } - public function case_some_and_then_some() + public function case_some_and_then_some(): void { $this ->given( @@ -422,7 +423,7 @@ public function case_some_and_then_some() ->isEqualTo(Some(153)); } - public function case_some_and_then_none() + public function case_some_and_then_none(): void { $this ->given( @@ -437,7 +438,7 @@ public function case_some_and_then_none() ->isEqualTo(None()); } - public function case_none_and_then_some() + public function case_none_and_then_some(): void { $this ->given( @@ -453,7 +454,7 @@ public function case_none_and_then_some() ->isNotIdenticalTo($option); } - public function case_none_and_then_none() + public function case_none_and_then_none(): void { $this ->given( @@ -469,7 +470,7 @@ public function case_none_and_then_none() ->isNotIdenticalTo($option); } - public function case_some_or_some() + public function case_some_or_some(): void { $this ->given( @@ -482,7 +483,7 @@ public function case_some_or_some() ->isIdenticalTo($option); } - public function case_some_or_none() + public function case_some_or_none(): void { $this ->given( @@ -495,7 +496,7 @@ public function case_some_or_none() ->isIdenticalTo($option); } - public function case_none_or_some() + public function case_none_or_some(): void { $this ->given( @@ -508,7 +509,7 @@ public function case_none_or_some() ->isIdenticalTo($rightOption); } - public function case_none_or_none() + public function case_none_or_none(): void { $this ->given( @@ -521,7 +522,7 @@ public function case_none_or_none() ->isIdenticalTo($rightOption); } - public function case_some_or_then_some() + public function case_some_or_then_some(): void { $this ->given( @@ -536,7 +537,7 @@ public function case_some_or_then_some() ->isIdenticalTo($option); } - public function case_some_or_then_none() + public function case_some_or_then_none(): void { $this ->given( @@ -551,7 +552,7 @@ public function case_some_or_then_none() ->isIdenticalTo($option); } - public function case_none_or_then_some() + public function case_none_or_then_some(): void { $this ->given( @@ -566,7 +567,7 @@ public function case_none_or_then_some() ->isEqualTo(Some(153)); } - public function case_none_or_then_none() + public function case_none_or_then_none(): void { $this ->given(