Validate POST Input in Sample 45

Errors will result if input is not numeric.
This commit is contained in:
oleibman
2024-09-05 13:12:53 -07:00
parent 59ee38f748
commit fb42a103f1
3 changed files with 100 additions and 45 deletions
+1 -4
View File
@@ -19,11 +19,9 @@ $config
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
'blank_line_before_statement' => true,
'braces' => true,
'cast_spaces' => true,
'class_attributes_separation' => ['elements' => ['method' => 'one', 'property' => 'one']], // const are often grouped with other related const
'class_definition' => false,
'class_keyword_remove' => false, // ::class keyword gives us better support in IDE
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'combine_nested_dirname' => true,
@@ -113,8 +111,7 @@ $config
'no_spaces_inside_parenthesis' => true,
'no_superfluous_elseif' => false, // Might be risky on a huge code base
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
'no_trailing_comma_in_list_call' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_trailing_comma_in_singleline' => ['elements' => ['arguments', 'array_destructuring', 'array', 'group_import']],
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'no_unneeded_control_parentheses' => true,
Generated
+89 -37
View File
@@ -4,24 +4,24 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "202b1e25cc7e8a5216ffa899dc111cda",
"content-hash": "b5731a32d1b1cbfe77e31f4df5d47bf9",
"packages": [
{
"name": "ezyang/htmlpurifier",
"version": "v4.16.0",
"version": "v4.17.0",
"source": {
"type": "git",
"url": "https://github.com/ezyang/htmlpurifier.git",
"reference": "523407fb06eb9e5f3d59889b3978d5bfe94299c8"
"reference": "bbc513d79acf6691fa9cf10f192c90dd2957f18c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/523407fb06eb9e5f3d59889b3978d5bfe94299c8",
"reference": "523407fb06eb9e5f3d59889b3978d5bfe94299c8",
"url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/bbc513d79acf6691fa9cf10f192c90dd2957f18c",
"reference": "bbc513d79acf6691fa9cf10f192c90dd2957f18c",
"shasum": ""
},
"require": {
"php": "~5.6.0 || ~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0"
"php": "~5.6.0 || ~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0"
},
"require-dev": {
"cerdic/css-tidy": "^1.7 || ^2.0",
@@ -63,9 +63,9 @@
],
"support": {
"issues": "https://github.com/ezyang/htmlpurifier/issues",
"source": "https://github.com/ezyang/htmlpurifier/tree/v4.16.0"
"source": "https://github.com/ezyang/htmlpurifier/tree/v4.17.0"
},
"time": "2022-09-18T07:06:19+00:00"
"time": "2023-11-17T15:01:25+00:00"
},
{
"name": "maennchen/zipstream-php",
@@ -1177,16 +1177,16 @@
},
{
"name": "dompdf/dompdf",
"version": "v2.0.3",
"version": "v2.0.8",
"source": {
"type": "git",
"url": "https://github.com/dompdf/dompdf.git",
"reference": "e8d2d5e37e8b0b30f0732a011295ab80680d7e85"
"reference": "c20247574601700e1f7c8dab39310fca1964dc52"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dompdf/dompdf/zipball/e8d2d5e37e8b0b30f0732a011295ab80680d7e85",
"reference": "e8d2d5e37e8b0b30f0732a011295ab80680d7e85",
"url": "https://api.github.com/repos/dompdf/dompdf/zipball/c20247574601700e1f7c8dab39310fca1964dc52",
"reference": "c20247574601700e1f7c8dab39310fca1964dc52",
"shasum": ""
},
"require": {
@@ -1194,7 +1194,7 @@
"ext-mbstring": "*",
"masterminds/html5": "^2.0",
"phenx/php-font-lib": ">=0.5.4 <1.0.0",
"phenx/php-svg-lib": ">=0.3.3 <1.0.0",
"phenx/php-svg-lib": ">=0.5.2 <1.0.0",
"php": "^7.1 || ^8.0"
},
"require-dev": {
@@ -1233,9 +1233,9 @@
"homepage": "https://github.com/dompdf/dompdf",
"support": {
"issues": "https://github.com/dompdf/dompdf/issues",
"source": "https://github.com/dompdf/dompdf/tree/v2.0.3"
"source": "https://github.com/dompdf/dompdf/tree/v2.0.8"
},
"time": "2023-02-07T12:51:48+00:00"
"time": "2024-04-29T13:06:17+00:00"
},
{
"name": "friendsofphp/php-cs-fixer",
@@ -1450,26 +1450,27 @@
},
{
"name": "mpdf/mpdf",
"version": "v8.1.6",
"version": "v8.2.4",
"source": {
"type": "git",
"url": "https://github.com/mpdf/mpdf.git",
"reference": "146c7c1dfd21c826b9d5bbfe3c15e52fd933c90f"
"reference": "9e3ff91606fed11cd58a130eabaaf60e56fdda88"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mpdf/mpdf/zipball/146c7c1dfd21c826b9d5bbfe3c15e52fd933c90f",
"reference": "146c7c1dfd21c826b9d5bbfe3c15e52fd933c90f",
"url": "https://api.github.com/repos/mpdf/mpdf/zipball/9e3ff91606fed11cd58a130eabaaf60e56fdda88",
"reference": "9e3ff91606fed11cd58a130eabaaf60e56fdda88",
"shasum": ""
},
"require": {
"ext-gd": "*",
"ext-mbstring": "*",
"mpdf/psr-http-message-shim": "^1.0 || ^2.0",
"mpdf/psr-log-aware-trait": "^2.0 || ^3.0",
"myclabs/deep-copy": "^1.7",
"paragonie/random_compat": "^1.4|^2.0|^9.99.99",
"php": "^5.6 || ^7.0 || ~8.0.0 || ~8.1.0 || ~8.2.0",
"psr/http-message": "^1.0",
"php": "^5.6 || ^7.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0",
"psr/http-message": "^1.0 || ^2.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"setasign/fpdi": "^2.1"
},
@@ -1487,6 +1488,9 @@
},
"type": "library",
"autoload": {
"files": [
"src/functions.php"
],
"psr-4": {
"Mpdf\\": "src/"
}
@@ -1523,7 +1527,55 @@
"type": "custom"
}
],
"time": "2023-05-03T19:36:43+00:00"
"time": "2024-06-14T16:06:41+00:00"
},
{
"name": "mpdf/psr-http-message-shim",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/mpdf/psr-http-message-shim.git",
"reference": "3206e6b80b6d2479e148ee497e9f2bebadc919db"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mpdf/psr-http-message-shim/zipball/3206e6b80b6d2479e148ee497e9f2bebadc919db",
"reference": "3206e6b80b6d2479e148ee497e9f2bebadc919db",
"shasum": ""
},
"require": {
"psr/http-message": "^1.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Mpdf\\PsrHttpMessageShim\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mark Dorison",
"email": "mark@chromatichq.com"
},
{
"name": "Kristofer Widholm",
"email": "kristofer@chromatichq.com"
},
{
"name": "Nigel Cunningham",
"email": "nigel.cunningham@technocrat.com.au"
}
],
"description": "Shim to allow support of different psr/message versions.",
"support": {
"issues": "https://github.com/mpdf/psr-http-message-shim/issues",
"source": "https://github.com/mpdf/psr-http-message-shim/tree/1.0.0"
},
"time": "2023-09-01T05:59:47+00:00"
},
{
"name": "mpdf/psr-log-aware-trait",
@@ -1891,16 +1943,16 @@
},
{
"name": "phenx/php-svg-lib",
"version": "0.5.0",
"version": "0.5.4",
"source": {
"type": "git",
"url": "https://github.com/dompdf/php-svg-lib.git",
"reference": "76876c6cf3080bcb6f249d7d59705108166a6685"
"reference": "46b25da81613a9cf43c83b2a8c2c1bdab27df691"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dompdf/php-svg-lib/zipball/76876c6cf3080bcb6f249d7d59705108166a6685",
"reference": "76876c6cf3080bcb6f249d7d59705108166a6685",
"url": "https://api.github.com/repos/dompdf/php-svg-lib/zipball/46b25da81613a9cf43c83b2a8c2c1bdab27df691",
"reference": "46b25da81613a9cf43c83b2a8c2c1bdab27df691",
"shasum": ""
},
"require": {
@@ -1919,7 +1971,7 @@
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0"
"LGPL-3.0-or-later"
],
"authors": [
{
@@ -1931,9 +1983,9 @@
"homepage": "https://github.com/PhenX/php-svg-lib",
"support": {
"issues": "https://github.com/dompdf/php-svg-lib/issues",
"source": "https://github.com/dompdf/php-svg-lib/tree/0.5.0"
"source": "https://github.com/dompdf/php-svg-lib/tree/0.5.4"
},
"time": "2022-09-06T12:16:56+00:00"
"time": "2024-04-08T12:52:34+00:00"
},
{
"name": "phpcompatibility/php-compatibility",
@@ -5184,20 +5236,20 @@
},
{
"name": "tecnickcom/tcpdf",
"version": "6.6.2",
"version": "6.7.5",
"source": {
"type": "git",
"url": "https://github.com/tecnickcom/TCPDF.git",
"reference": "e3cffc9bcbc76e89e167e9eb0bbda0cab7518459"
"reference": "951eabf0338ec2522bd0d5d9c79b08a3a3d36b36"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/tecnickcom/TCPDF/zipball/e3cffc9bcbc76e89e167e9eb0bbda0cab7518459",
"reference": "e3cffc9bcbc76e89e167e9eb0bbda0cab7518459",
"url": "https://api.github.com/repos/tecnickcom/TCPDF/zipball/951eabf0338ec2522bd0d5d9c79b08a3a3d36b36",
"reference": "951eabf0338ec2522bd0d5d9c79b08a3a3d36b36",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
"php": ">=5.5.0"
},
"type": "library",
"autoload": {
@@ -5222,7 +5274,7 @@
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0-only"
"LGPL-3.0-or-later"
],
"authors": [
{
@@ -5244,7 +5296,7 @@
],
"support": {
"issues": "https://github.com/tecnickcom/TCPDF/issues",
"source": "https://github.com/tecnickcom/TCPDF/tree/6.6.2"
"source": "https://github.com/tecnickcom/TCPDF/tree/6.7.5"
},
"funding": [
{
@@ -5252,7 +5304,7 @@
"type": "custom"
}
],
"time": "2022-12-17T10:28:59+00:00"
"time": "2024-04-20T17:25:10+00:00"
},
{
"name": "theseer/tokenizer",
+10 -4
View File
@@ -14,7 +14,7 @@ if ($helper->isCli()) {
}
?>
<form action="45_Quadratic_equation_solver.php" method="POST">
Enter the coefficients for the Ax<sup>2</sup> + Bx + C = 0
Enter the coefficients for Ax<sup>2</sup> + Bx + C = 0
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
@@ -47,7 +47,9 @@ if ($helper->isCli()) {
<?php
/** If the user has submitted the form, then we need to execute a calculation * */
if (isset($_POST['submit'])) {
if ($_POST['A'] == 0) {
if (!is_numeric($_POST['A']) || !is_numeric($_POST['B']) || !is_numeric($_POST['C'])) { // validate input
$helper->log('Non-numeric input');
} elseif ($_POST['A'] == 0) {
$helper->log('The equation is not quadratic');
} else {
// Calculate and Display the results
@@ -59,8 +61,12 @@ if (isset($_POST['submit'])) {
$r1Formula = '=IMDIV(IMSUM(-' . $_POST['B'] . ',IMSQRT(' . $discriminant . ')),2 * ' . $_POST['A'] . ')';
$r2Formula = '=IF(' . $discriminant . '=0,"Only one root",IMDIV(IMSUB(-' . $_POST['B'] . ',IMSQRT(' . $discriminant . ')),2 * ' . $_POST['A'] . '))';
$helper->log(Calculation::getInstance()->calculateFormula($r1Formula));
$helper->log(Calculation::getInstance()->calculateFormula($r2Formula));
/** @var string */
$output = Calculation::getInstance()->calculateFormula($r1Formula);
$helper->log("$output");
/** @var string */
$output = Calculation::getInstance()->calculateFormula($r2Formula);
$helper->log("$output");
$callEndTime = microtime(true);
$helper->logEndingNotes();
}