"value":"\n <p>Following yesterday's email about input validation, guard clauses and assertion libraries, these can be used to compliment PHP's native types and checking.<\/p>\n\n<p>For example:<\/p>\n\n<pre><code class=\"language-php\">function createJourney(string $from, string $to, int $duration): void {\n var_dump($from, $to, $duration);\n}\n<\/code><\/pre>\n\n<p>In this code, each parameter has a type, but there's no validation on the values.<\/p>\n\n<p>If I run this:<\/p>\n\n<pre><code class=\"language-plain\">createJourney('', '', -10);\n<\/code><\/pre>\n\n<p>I would get this output:<\/p>\n\n<pre><code class=\"language-plain\">string(0) \"\"\nstring(0) \"\"\nint(-10)\n<\/code><\/pre>\n\n<p>This is probably not what you want.<\/p>\n\n<p>I expect <code>$to<\/code> and <code>$from<\/code> to be not empty and the duration to be greater than zero.<\/p>\n\n<h2 id=\"here%27s-the-thing\">Here's the thing<\/h2>\n\n<p>I can use an assertion library or throw my own Exceptions if the values pass the type checks but aren't what I need.<\/p>\n\n<p>For example:<\/p>\n\n<pre><code class=\"language-php\">function createJourney(string $from, string $to, int $duration): void {\n Assert::stringNotEmpty($from);\n Assert::stringNotEmpty($to);\n Assert::positiveInteger($duration);\n\n var_dump($from, $to, $duration);\n}\n<\/code><\/pre>\n\n<p>Now, if an empty string or negative duration is passed - in my implementation or test code - an Exception will be thrown.<\/p>\n\n ",
"format":"full_html",
"processed":"\n <p>Following yesterday's email about input validation, guard clauses and assertion libraries, these can be used to compliment PHP's native types and checking.<\/p>\n\n<p>For example:<\/p>\n\n<pre><code class=\"language-php\">function createJourney(string $from, string $to, int $duration): void {\n var_dump($from, $to, $duration);\n}\n<\/code><\/pre>\n\n<p>In this code, each parameter has a type, but there's no validation on the values.<\/p>\n\n<p>If I run this:<\/p>\n\n<pre><code class=\"language-plain\">createJourney('', '', -10);\n<\/code><\/pre>\n\n<p>I would get this output:<\/p>\n\n<pre><code class=\"language-plain\">string(0) \"\"\nstring(0) \"\"\nint(-10)\n<\/code><\/pre>\n\n<p>This is probably not what you want.<\/p>\n\n<p>I expect <code>$to<\/code> and <code>$from<\/code> to be not empty and the duration to be greater than zero.<\/p>\n\n<h2 id=\"here%27s-the-thing\">Here's the thing<\/h2>\n\n<p>I can use an assertion library or throw my own Exceptions if the values pass the type checks but aren't what I need.<\/p>\n\n<p>For example:<\/p>\n\n<pre><code class=\"language-php\">function createJourney(string $from, string $to, int $duration): void {\n Assert::stringNotEmpty($from);\n Assert::stringNotEmpty($to);\n Assert::positiveInteger($duration);\n\n var_dump($from, $to, $duration);\n}\n<\/code><\/pre>\n\n<p>Now, if an empty string or negative duration is passed - in my implementation or test code - an Exception will be thrown.<\/p>\n\n ",