Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add PHPStan check #1409

Merged
merged 10 commits into from
Feb 9, 2023
Merged

ci: Add PHPStan check #1409

merged 10 commits into from
Feb 9, 2023

Conversation

jtojnar
Copy link
Member

@jtojnar jtojnar commented Feb 8, 2023

No description provided.

@netlify
Copy link

netlify bot commented Feb 8, 2023

Deploy Preview for selfoss canceled.

Name Link
🔨 Latest commit e88cb72
🔍 Latest deploy log https://app.netlify.com/sites/selfoss/deploys/63e443a9360b7a00084c795c

Had to disable php-cs-fixer phpdoc rules since it would try to add invalid typehints.
All three supported database engines will return `null` PHP value for a `NULL` value in database.
Previously all ensured values would be cast to the expected type (except for `DateTime` which had a special case for `NULL`), possibly replacing `NULL` value with 0 or other incorrect value.
Let’s make the `null` part of the “type system” using binary or.
It will also be useful once we start adding return type hints for daos methods.

----

```php
$c = $dice->create(helpers\DatabaseConnection::class);
$v = $c->exec('select NULL as "null", 42 as "int", 3.14 as "decimal", CURRENT_TIMESTAMP as "timestamp", \'test\' as "string", true as "true", false as "false";');
var_dump($v);
```

## PHP 8.2
### SQLite
```php
array(1) {
  [0]=>
  array(7) {
    ["null"]=>
    NULL
    ["int"]=>
    int(42)
    ["decimal"]=>
    float(3.14)
    ["timestamp"]=>
    string(19) "2023-02-08 23:07:00"
    ["string"]=>
    string(4) "test"
    ["true"]=>
    int(1)
    ["false"]=>
    int(0)
  }
}
```

### MariaDB 10.6.11
```php
array(1) {
  [0]=>
  array(7) {
    ["null"]=>
    NULL
    ["int"]=>
    int(42)
    ["decimal"]=>
    string(4) "3.14"
    ["timestamp"]=>
    string(19) "2023-02-09 00:06:47"
    ["string"]=>
    string(4) "test"
    ["true"]=>
    int(1)
    ["false"]=>
    int(0)
  }
}
```

### PostgreSQL 14.6
```php
array(1) {
  [0]=>
  array(7) {
    ["null"]=>
    NULL
    ["int"]=>
    int(42)
    ["decimal"]=>
    string(4) "3.14"
    ["timestamp"]=>
    string(29) "2023-02-08 23:06:57.433412+00"
    ["string"]=>
    string(4) "test"
    ["true"]=>
    bool(true)
    ["false"]=>
    bool(false)
  }
}
```

## PHP 7.2
### SQLite
```php
array(1) {
  [0]=>
  array(7) {
    ["null"]=>
    NULL
    ["int"]=>
    string(2) "42"
    ["decimal"]=>
    string(4) "3.14"
    ["timestamp"]=>
    string(19) "2023-02-08 23:23:54"
    ["string"]=>
    string(4) "test"
    ["true"]=>
    string(1) "1"
    ["false"]=>
    string(1) "0"
  }
}
```

### MariaDB 10.6.11
```php
array(1) {
  [0]=>
  array(7) {
    ["null"]=>
    NULL
    ["int"]=>
    string(2) "42"
    ["decimal"]=>
    string(4) "3.14"
    ["timestamp"]=>
    string(19) "2023-02-09 00:24:33"
    ["string"]=>
    string(4) "test"
    ["true"]=>
    string(1) "1"
    ["false"]=>
    string(1) "0"
  }
}
```

### PostgreSQL 14.6
```php
array(1) {
  [0]=>
  array(7) {
    ["null"]=>
    NULL
    ["int"]=>
    int(42)
    ["decimal"]=>
    string(4) "3.14"
    ["timestamp"]=>
    string(29) "2023-02-08 23:24:30.032842+00"
    ["string"]=>
    string(4) "test"
    ["true"]=>
    bool(true)
    ["false"]=>
    bool(false)
  }
}
```
It is not needed since PHP 7.0.
Up to level 5.
Will still require more work on filling in array item types.
@jtojnar jtojnar added this pull request to the merge queue Feb 9, 2023
Merged via the queue into master with commit 0b33b1c Feb 9, 2023
@jtojnar jtojnar deleted the type-hints branch February 9, 2023 00:53
@jtojnar jtojnar added this to the 2.20 milestone Feb 16, 2023
@jtojnar jtojnar mentioned this pull request Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant