Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
fail-fast: false

Expand All @@ -23,7 +23,7 @@ jobs:
with:
coverage: pcov
ini-values: zend.assertions=1, assert.exception=1
php-version: 8.1
php-version: 8.4
extensions: memcached
tools: cs2pr

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
phpcsfixer:
name: PHP CS Fixer
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
fail-fast: false

Expand All @@ -23,7 +23,7 @@ jobs:
with:
coverage: pcov
ini-values: zend.assertions=1, assert.exception=1
php-version: 8.1
php-version: 8.3
extensions: memcached
tools: cs2pr

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
phpunit:
name: PHPUnit
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
services:
memcached:
image: memcached:1.6
Expand Down Expand Up @@ -47,6 +47,8 @@ jobs:
php-version:
- 8.1
- 8.2
- 8.3
- 8.4
database:
- mysql
- pgsql
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"php": ">=8.1.0"
},
"require-dev": {
"phpstan/phpstan": "^1.10",
"phpstan/phpstan": "1.12.23",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^10",
"friendsofphp/php-cs-fixer": "^v3.23.0",
Expand Down
3 changes: 2 additions & 1 deletion lib/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package ActiveRecord
*/
Expand Down Expand Up @@ -69,7 +70,7 @@ public function create_column(array $column): Column

$c->raw_type = (count($matches) > 0 ? $matches[1] : $column['type']);

if (count($matches) >= 4) {
if (isset($matches[3])) {
$c->length = intval($matches[3]);
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Adapter/PgsqlAdapter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package ActiveRecord
*/
Expand Down Expand Up @@ -131,7 +132,7 @@ public function create_column(array $column): Column
preg_match('/^([A-Za-z0-9_]+)(\(([0-9]+(,[0-9]+)?)\))?/', $column['type'], $matches);

$c->raw_type = (count($matches) > 0 ? $matches[1] : $column['type']);
$c->length = count($matches) >= 4 ? intval($matches[3]) : intval($column['attlen']);
$c->length = isset($matches[3]) ? intval($matches[3]) : intval($column['attlen']);

if ($c->length < 0) {
$c->length = null;
Expand Down
1 change: 1 addition & 0 deletions lib/Adapter/SqliteAdapter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package ActiveRecord
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static function flush(): void
*
* @param int $expire in seconds
*/
public static function get(string $key, \Closure $closure, int $expire = null): mixed
public static function get(string $key, \Closure $closure, ?int $expire = null): mixed
{
if (!static::$adapter) {
return $closure();
Expand All @@ -98,7 +98,7 @@ public static function get(string $key, \Closure $closure, int $expire = null):
return $value;
}

public static function set(string $key, mixed $var, int $expire = null): void
public static function set(string $key, mixed $var, ?int $expire = null): void
{
assert(isset(static::$adapter), 'Adapter required to set');

Expand Down
5 changes: 3 additions & 2 deletions lib/CallBack.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package ActiveRecord
*/
Expand Down Expand Up @@ -163,7 +164,7 @@ public function get_callbacks(string $name): array
* that was for a before_* callback and that method returned false. If this happens, execution
* of any other callbacks after the offending callback will not occur.
*/
public function invoke(Model|null $model, string $name, bool $must_exist = true)
public function invoke(?Model $model, string $name, bool $must_exist = true)
{
if ($must_exist && !array_key_exists($name, $this->registry)) {
throw new ActiveRecordException("No callbacks were defined for: $name on " . ($model ? get_class($model) : 'null'));
Expand Down Expand Up @@ -214,7 +215,7 @@ public function invoke(Model|null $model, string $name, bool $must_exist = true)
*
* @throws ActiveRecordException if invalid callback type or callback method was not found
*/
public function register(string $name, \Closure|string $closure_or_method_name = null, array $options = []): void
public function register(string $name, \Closure|string|null $closure_or_method_name = null, array $options = []): void
{
$closure_or_method_name ??= $name;

Expand Down
3 changes: 2 additions & 1 deletion lib/Column.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package ActiveRecord
*/
Expand Down Expand Up @@ -66,7 +67,7 @@ class Column
/**
* The maximum length of this column.
*/
public int|null $length = null;
public ?int $length = null;

/**
* True if this column allows null.
Expand Down
3 changes: 2 additions & 1 deletion lib/Config.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package ActiveRecord
*/
Expand Down Expand Up @@ -202,7 +203,7 @@ public function get_logging(): bool
/**
* Returns the logger
*/
public function get_logger(): LoggerInterface|null
public function get_logger(): ?LoggerInterface
{
return $this->logger ?? null;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract class Connection
/**
* Contains a Logger object that must implement a log() method.
*/
private LoggerInterface|null $logger;
private ?LoggerInterface $logger;
/**
* The name of the protocol that is used.
*/
Expand Down Expand Up @@ -105,7 +105,7 @@ abstract public function create_column(array $column): Column;
*
* @see parse_connection_url
*/
public static function instance(string $connection_string_or_connection_name = null)
public static function instance(?string $connection_string_or_connection_name = null)
{
$config = Config::instance();

Expand Down
3 changes: 2 additions & 1 deletion lib/ConnectionManager.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package ActiveRecord
*/
Expand Down Expand Up @@ -28,7 +29,7 @@ class ConnectionManager extends Singleton
*
* @return Connection
*/
public static function get_connection(string $name=null)
public static function get_connection(?string $name=null)
{
$config = Config::instance();
$name = $name ?? $config->get_default_connection();
Expand Down
9 changes: 5 additions & 4 deletions lib/DateTime.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package ActiveRecord
*/
Expand Down Expand Up @@ -67,8 +68,8 @@ final class DateTime extends \DateTime implements DateTimeInterface
'rss' => \DateTime::RSS,
'w3c' => \DateTime::W3C];

private Model|null $model = null;
private string|null $attribute_name = null;
private ?Model $model = null;
private ?string $attribute_name = null;

public function attribute_of(Model $model, string $attribute_name): void
{
Expand Down Expand Up @@ -109,7 +110,7 @@ public function format(string $format = ''): string
*
* @return string a format string
*/
public static function get_format(string $format = null): string
public static function get_format(?string $format = null): string
{
// use default format if no format specified
if (!$format) {
Expand All @@ -129,7 +130,7 @@ public static function get_format(string $format = null): string
* This needs to be overridden so it returns an instance of this class instead of PHP's \DateTime.
* See http://php.net/manual/en/datetime.createfromformat.php
*/
public static function createFromFormat(string $format, string $time, \DateTimeZone $timezone = null): static
public static function createFromFormat(string $format, string $time, ?\DateTimeZone $timezone = null): static
{
$phpDate = parent::createFromFormat($format, $time, $timezone);
assert($phpDate);
Expand Down
3 changes: 2 additions & 1 deletion lib/DateTimeInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package ActiveRecord
*/
Expand Down Expand Up @@ -29,5 +30,5 @@ public function format(string $format = ''): string;
/**
* See http://php.net/manual/en/datetime.createfromformat.php
*/
public static function createFromFormat(string $format, string $time, \DateTimeZone $timezone = null): static;
public static function createFromFormat(string $format, string $time, ?\DateTimeZone $timezone = null): static;
}
2 changes: 1 addition & 1 deletion lib/Exception/DatabaseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class DatabaseException extends ActiveRecordException
{
public function __construct(string $message = '', int $code = 0, \Throwable $previous = null)
public function __construct(string $message = '', int $code = 0, ?\Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand Down
1 change: 1 addition & 0 deletions lib/Inflector.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package ActiveRecord
*/
Expand Down
11 changes: 6 additions & 5 deletions lib/Model.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* The base class for your models.
*
Expand Down Expand Up @@ -836,7 +837,7 @@ public static function table_name()
* @param string $name Name of an attribute
* @param DelegateOptions $delegate An array containing delegate data
*/
private function is_delegated(string $name, array $delegate): string|null
private function is_delegated(string $name, array $delegate): ?string
{
if (is_array($delegate)) {
if (!empty($delegate['prefix'])) {
Expand Down Expand Up @@ -1403,7 +1404,7 @@ public function reset_dirty(): void
*
* @see Relation::__call()
*/
public static function __callStatic(string $method, mixed $args): static|null
public static function __callStatic(string $method, mixed $args): ?static
{
return static::Relation()->$method(...$args);
}
Expand Down Expand Up @@ -1674,7 +1675,7 @@ public static function ids(): array
*
* @return static|array<static>|null
*/
public static function take(int $limit = null): static|array|null
public static function take(?int $limit = null): static|array|null
{
return static::Relation()->take($limit);
}
Expand All @@ -1684,7 +1685,7 @@ public static function take(int $limit = null): static|array|null
*
* @return static|array<static>|null
*/
public static function first(int $limit = null): static|array|null
public static function first(?int $limit = null): static|array|null
{
return static::Relation()->first($limit);
}
Expand All @@ -1694,7 +1695,7 @@ public static function first(int $limit = null): static|array|null
*
* @return static|array<static>|null
*/
public static function last(int $limit = null): static|array|null
public static function last(?int $limit = null): static|array|null
{
return static::Relation()->last($limit);
}
Expand Down
1 change: 1 addition & 0 deletions lib/Reflections.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package ActiveRecord
*/
Expand Down
13 changes: 7 additions & 6 deletions lib/Relation.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Interface
*
Expand Down Expand Up @@ -147,7 +148,7 @@ public function none(): Relation
*
* @return Model|null The first model that meets the find by criteria, or null if no row meets that criteria
*/
public function __call(string $method, mixed $args): Model|null
public function __call(string $method, mixed $args): ?Model
{
$create = false;

Expand Down Expand Up @@ -778,7 +779,7 @@ protected function get_models_from_cache(array $pks)
*
* @return TModel|array<TModel>|null
*/
public function take(int $limit = null): Model|array|null
public function take(?int $limit = null): Model|array|null
{
$options = array_merge($this->options, ['limit' => $limit ?? 1]);
$models = $this->_to_a($options);
Expand All @@ -798,7 +799,7 @@ public function take(int $limit = null): Model|array|null
*
* @return TModel|array<TModel>|null
*/
public function first(int $limit = null): Model|array|null
public function first(?int $limit = null): Model|array|null
{
$models = $this->firstOrLast($limit, true);

Expand All @@ -819,7 +820,7 @@ public function first(int $limit = null): Model|array|null
*
* @return TModel|array<TModel>|null
*/
public function last(int $limit = null): Model|array|null
public function last(?int $limit = null): Model|array|null
{
$models = $this->firstOrLast($limit, false);

Expand Down Expand Up @@ -849,7 +850,7 @@ public function reverse_order(): array
/**
* @return array<TModel>
*/
private function firstOrLast(int $limit = null, bool $isAscending): array
private function firstOrLast(?int $limit = null, bool $isAscending = true): array
{
$options = array_merge($this->options, ['limit' => $limit ?? 1]);

Expand Down Expand Up @@ -1083,7 +1084,7 @@ public function exists(mixed $conditions = []): bool
* 'name' => 'Oscar' // WHERE "users"."name" = 'Oscar'
* ])->to_sql()
*
* @throws Exception\ActiveRecordException
* @throws ActiveRecordException
* @throws Exception\RelationshipException
*/
public function to_sql(): string
Expand Down
2 changes: 1 addition & 1 deletion lib/Relationship/AbstractRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ protected function create_conditions_from_keys(Model $model, array $condition_ke
*
* @return string SQL INNER JOIN fragment
*/
public function construct_inner_join_sql(Table $from_table, bool $using_through = false, string $alias = null)
public function construct_inner_join_sql(Table $from_table, bool $using_through = false, ?string $alias = null)
{
if ($using_through) {
$join_table_name = $from_table->get_fully_qualified_table_name();
Expand Down
Loading