diff --git a/composer.json b/composer.json index 022314d3..425d6dde 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 fd982a7a..ee6d4bfb 100644 --- a/flight/database/PdoWrapper.php +++ b/flight/database/PdoWrapper.php @@ -106,36 +106,36 @@ public function fetchAll(string $sql, array $params = []): array 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 27a4e703..2070cc63 100644 --- a/flight/net/Route.php +++ b/flight/net/Route.php @@ -192,7 +192,9 @@ public function hydrateUrl(array $params = []): string // catches potential optional parameter $url = str_replace('(/', '/', $url); // trim any trailing slashes - $url = rtrim($url, '/'); + if ($url !== '/') { + $url = rtrim($url, '/'); + } return $url; } diff --git a/tests/RouterTest.php b/tests/RouterTest.php index 1f0d33a1..f67759f6 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -533,6 +533,13 @@ public function testRewindAndValid() $this->assertTrue($result); } + public function testGetRootUrlByAlias() + { + $this->router->map('/', [$this, 'ok'], false, 'path1'); + $url = $this->router->getUrlByAlias('path1'); + $this->assertEquals('/', $url); + } + public function testGetUrlByAliasNoMatches() { $this->router->map('/path1', [$this, 'ok'], false, 'path1');