Skip to content

Commit

Permalink
Merge pull request #153 from elecena/php81/linter
Browse files Browse the repository at this point in the history
Run linter using PHP 8.1 as well (and fix any issues)
  • Loading branch information
macbre committed Sep 22, 2022
2 parents 0679e83 + 9b09bcd commit f6e8502
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/linter.yaml
Expand Up @@ -14,6 +14,7 @@ jobs:
- '7.3'
- '7.4'
- '8.0'
- '8.1'

steps:
- name: Checkout
Expand Down
12 changes: 7 additions & 5 deletions classes/DatabaseResult.class.php
Expand Up @@ -49,7 +49,7 @@ public function seek($rowId)
/**
* Return data from current row
*
* @return mixed data
* @return array|bool data
*/
public function fetchRow()
{
Expand Down Expand Up @@ -81,15 +81,15 @@ public function free()
/**
* Implement Countable interface
*/
public function count()
public function count(): int
{
return $this->numRows();
}

/**
* Implement Iterator interface
*/
public function rewind()
public function rewind(): void
{
if ($this->numRows()) {
$this->seek(0);
Expand All @@ -98,6 +98,7 @@ public function rewind()
$this->currentRow = null;
}

#[ReturnTypeWillChange]
public function current()
{
if (is_null($this->currentRow)) {
Expand All @@ -107,19 +108,20 @@ public function current()
return $this->currentRow;
}

public function key()
public function key(): int
{
return $this->pos;
}

#[ReturnTypeWillChange]
public function next()
{
$this->pos++;
$this->currentRow = $this->fetchRow();
return $this->currentRow;
}

public function valid()
public function valid(): bool
{
return $this->current() !== false;
}
Expand Down
11 changes: 9 additions & 2 deletions classes/Router.class.php
Expand Up @@ -279,10 +279,17 @@ public function getPathPrefix()
/**
* Sanitize given string to be used in URL
*
* Replace all non alphanumeric characters with a dash
* Replace all non-alphanumeric characters with a dash
*
* @param string|null $string
* @return string
*/
public function sanitize($string)
public function sanitize(?string $string): string
{
if (is_null($string)) {
return '';
}

$string = mb_strtolower(trim($string));
$string = strtr($string, [
'ą' => 'a',
Expand Down
1 change: 1 addition & 0 deletions tests/RouterTest.php
Expand Up @@ -28,6 +28,7 @@ public function testSanitize()
{
$router = $this->getRouter();

$this->assertEquals('', $router->sanitize(null));
$this->assertEquals('foobar', $router->sanitize('foobar'));
$this->assertEquals('foo-bar', $router->sanitize('foo/bar'));
$this->assertEquals('foo-bar', $router->sanitize('foo - bar'));
Expand Down

0 comments on commit f6e8502

Please sign in to comment.