From 4c60454fa0a79bc2251f14ab1bfe31a7d2d86a87 Mon Sep 17 00:00:00 2001 From: Austin Collier Date: Sat, 27 Jan 2024 20:00:42 -0700 Subject: [PATCH] beautified --- composer.json | 2 +- flight/database/PdoWrapper.php | 44 +++++++++++++++++----------------- flight/net/Route.php | 6 ++--- tests/RouterTest.php | 2 +- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/composer.json b/composer.json index 022314d..425d6dd 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,7 @@ "test-coverage": "rm clover.xml && XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html=coverage --coverage-clover=clover.xml && vendor/bin/coverage-check clover.xml 100", "lint": "phpstan --no-progress -cphpstan.neon", "beautify": "phpcbf --standard=phpcs.xml", - "phpcs": "phpcs --standard=phpcs.xml" + "phpcs": "phpcs --standard=phpcs.xml -n" }, "suggest": { "latte/latte": "Latte template engine", diff --git a/flight/database/PdoWrapper.php b/flight/database/PdoWrapper.php index fd982a7..ee6d4bf 100644 --- a/flight/database/PdoWrapper.php +++ b/flight/database/PdoWrapper.php @@ -106,36 +106,36 @@ class PdoWrapper extends PDO protected function processInStatementSql(string $sql, array $params = []): array { // Replace "IN(?)" with "IN(?,?,?)" - $sql = preg_replace('/IN\s*\(\s*\?\s*\)/i', 'IN(?)', $sql); + $sql = preg_replace('/IN\s*\(\s*\?\s*\)/i', 'IN(?)', $sql); - $current_index = 0; - while (($current_index = strpos($sql, 'IN(?)', $current_index)) !== false) { - $preceeding_count = substr_count($sql, '?', 0, $current_index - 1); + $current_index = 0; + while (($current_index = strpos($sql, 'IN(?)', $current_index)) !== false) { + $preceeding_count = substr_count($sql, '?', 0, $current_index - 1); - $param = $params[$preceeding_count]; - $question_marks = '?'; + $param = $params[$preceeding_count]; + $question_marks = '?'; - if (is_string($param) || is_array($param)) { - $params_to_use = $param; - if (is_string($param)) { - $params_to_use = explode(',', $param); - } + if (is_string($param) || is_array($param)) { + $params_to_use = $param; + if (is_string($param)) { + $params_to_use = explode(',', $param); + } - foreach ($params_to_use as $key => $value) { - if (is_string($value)) { - $params_to_use[$key] = trim($value); + foreach ($params_to_use as $key => $value) { + if (is_string($value)) { + $params_to_use[$key] = trim($value); + } } - } - $question_marks = join(',', array_fill(0, count($params_to_use), '?')); - $sql = substr_replace($sql, $question_marks, $current_index + 3, 1); + $question_marks = join(',', array_fill(0, count($params_to_use), '?')); + $sql = substr_replace($sql, $question_marks, $current_index + 3, 1); - array_splice($params, $preceeding_count, 1, $params_to_use); - } + array_splice($params, $preceeding_count, 1, $params_to_use); + } - $current_index += strlen($question_marks) + 4; - } + $current_index += strlen($question_marks) + 4; + } - return [ 'sql' => $sql, 'params' => $params ]; + return [ 'sql' => $sql, 'params' => $params ]; } } diff --git a/flight/net/Route.php b/flight/net/Route.php index 886fa13..2070cc6 100644 --- a/flight/net/Route.php +++ b/flight/net/Route.php @@ -192,9 +192,9 @@ class Route // catches potential optional parameter $url = str_replace('(/', '/', $url); // trim any trailing slashes - if($url !== '/') { - $url = rtrim($url, '/'); - } + if ($url !== '/') { + $url = rtrim($url, '/'); + } return $url; } diff --git a/tests/RouterTest.php b/tests/RouterTest.php index 6580bf1..f67759f 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -533,7 +533,7 @@ class RouterTest extends TestCase $this->assertTrue($result); } - public function testGetRootUrlByAlias() + public function testGetRootUrlByAlias() { $this->router->map('/', [$this, 'ok'], false, 'path1'); $url = $this->router->getUrlByAlias('path1');