diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index f1eb157c..b8be2e7c 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -10,7 +10,7 @@ on: jobs: phpstan: name: PHPStan - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: fail-fast: false @@ -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 diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index ab413bd8..0e4ee1b4 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -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 @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 42c88ec8..26982d3b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -47,6 +47,8 @@ jobs: php-version: - 8.1 - 8.2 + - 8.3 + - 8.4 database: - mysql - pgsql diff --git a/composer.json b/composer.json index 3d2f46d2..43f189c2 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/lib/Adapter/MysqlAdapter.php b/lib/Adapter/MysqlAdapter.php index ef021ea6..50059cd3 100644 --- a/lib/Adapter/MysqlAdapter.php +++ b/lib/Adapter/MysqlAdapter.php @@ -1,4 +1,5 @@ raw_type = (count($matches) > 0 ? $matches[1] : $column['type']); - if (count($matches) >= 4) { + if (isset($matches[3])) { $c->length = intval($matches[3]); } } diff --git a/lib/Adapter/PgsqlAdapter.php b/lib/Adapter/PgsqlAdapter.php index a7bb2b14..07dc34ab 100644 --- a/lib/Adapter/PgsqlAdapter.php +++ b/lib/Adapter/PgsqlAdapter.php @@ -1,4 +1,5 @@ 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; diff --git a/lib/Adapter/SqliteAdapter.php b/lib/Adapter/SqliteAdapter.php index 217b8cad..04500076 100644 --- a/lib/Adapter/SqliteAdapter.php +++ b/lib/Adapter/SqliteAdapter.php @@ -1,4 +1,5 @@ registry)) { throw new ActiveRecordException("No callbacks were defined for: $name on " . ($model ? get_class($model) : 'null')); @@ -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; diff --git a/lib/Column.php b/lib/Column.php index a68c62c8..ccf944fa 100644 --- a/lib/Column.php +++ b/lib/Column.php @@ -1,4 +1,5 @@ logger ?? null; } diff --git a/lib/Connection.php b/lib/Connection.php index c43fc47f..99594661 100644 --- a/lib/Connection.php +++ b/lib/Connection.php @@ -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. */ @@ -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(); diff --git a/lib/ConnectionManager.php b/lib/ConnectionManager.php index f5c4cd25..c7d0920d 100644 --- a/lib/ConnectionManager.php +++ b/lib/ConnectionManager.php @@ -1,4 +1,5 @@ get_default_connection(); diff --git a/lib/DateTime.php b/lib/DateTime.php index 9b050924..ee36ddf3 100644 --- a/lib/DateTime.php +++ b/lib/DateTime.php @@ -1,4 +1,5 @@ \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 { @@ -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) { @@ -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); diff --git a/lib/DateTimeInterface.php b/lib/DateTimeInterface.php index 49765c84..3cc5600b 100644 --- a/lib/DateTimeInterface.php +++ b/lib/DateTimeInterface.php @@ -1,4 +1,5 @@ $method(...$args); } @@ -1674,7 +1675,7 @@ public static function ids(): array * * @return static|array|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); } @@ -1684,7 +1685,7 @@ public static function take(int $limit = null): static|array|null * * @return static|array|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); } @@ -1694,7 +1695,7 @@ public static function first(int $limit = null): static|array|null * * @return static|array|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); } diff --git a/lib/Reflections.php b/lib/Reflections.php index 3a255dca..5ec5327e 100644 --- a/lib/Reflections.php +++ b/lib/Reflections.php @@ -1,4 +1,5 @@ |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); @@ -798,7 +799,7 @@ public function take(int $limit = null): Model|array|null * * @return TModel|array|null */ - public function first(int $limit = null): Model|array|null + public function first(?int $limit = null): Model|array|null { $models = $this->firstOrLast($limit, true); @@ -819,7 +820,7 @@ public function first(int $limit = null): Model|array|null * * @return TModel|array|null */ - public function last(int $limit = null): Model|array|null + public function last(?int $limit = null): Model|array|null { $models = $this->firstOrLast($limit, false); @@ -849,7 +850,7 @@ public function reverse_order(): array /** * @return array */ - 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]); @@ -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 diff --git a/lib/Relationship/AbstractRelationship.php b/lib/Relationship/AbstractRelationship.php index 6b3aa2f9..7de81f99 100644 --- a/lib/Relationship/AbstractRelationship.php +++ b/lib/Relationship/AbstractRelationship.php @@ -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(); diff --git a/lib/Relationship/HasAndBelongsToMany.php b/lib/Relationship/HasAndBelongsToMany.php index ff20dfde..70e33015 100644 --- a/lib/Relationship/HasAndBelongsToMany.php +++ b/lib/Relationship/HasAndBelongsToMany.php @@ -62,7 +62,7 @@ public static function inferJoiningTableName(string $class_name, string $associa return implode('_', $parts); } - public function construct_inner_join_sql(Table $from_table, bool $using_through = false, string $alias = null): string + public function construct_inner_join_sql(Table $from_table, bool $using_through = false, ?string $alias = null): string { $other_table = Table::load($this->class_name); $associated_table_name = $other_table->table; diff --git a/lib/SQLBuilder.php b/lib/SQLBuilder.php index e81c2f96..c6160376 100644 --- a/lib/SQLBuilder.php +++ b/lib/SQLBuilder.php @@ -1,4 +1,5 @@ $data */ - private function write(array $data, string $tag = null): void + private function write(array $data, ?string $tag = null): void { foreach ($data as $attr => $value) { $attr = $tag ?? $attr; diff --git a/lib/Singleton.php b/lib/Singleton.php index 86e4bd4a..4e1317ee 100644 --- a/lib/Singleton.php +++ b/lib/Singleton.php @@ -1,4 +1,5 @@ columns as $raw_name => $column) { if ($column->inflected_name == $inflected_name) { @@ -408,7 +409,7 @@ public function has_relationship(string $name): bool * * @throws Exception\ActiveRecordException */ - public function insert(array &$data, string|int $pk = null, string $sequence_name = null): \PDOStatement + public function insert(array &$data, string|int|null $pk = null, ?string $sequence_name = null): \PDOStatement { $data = $this->process_data($data); diff --git a/lib/Utils.php b/lib/Utils.php index fd882df0..474f9a55 100644 --- a/lib/Utils.php +++ b/lib/Utils.php @@ -1,4 +1,5 @@ > @@ -170,7 +170,7 @@ public function full_messages(): array * * @return array> */ - public function to_array(callable $closure = null): array + public function to_array(?callable $closure = null): array { $errors = []; diff --git a/lib/Validations.php b/lib/Validations.php index 0c5029f0..3fdd01d5 100644 --- a/lib/Validations.php +++ b/lib/Validations.php @@ -1,4 +1,5 @@ heavily borrowed from Ruby on Rails' ActiveRecord so much that * this piece can be considered a straight port. The reason for this is that the vaildation process is diff --git a/lib/WhereClause.php b/lib/WhereClause.php index 8e6934ae..c574eee4 100644 --- a/lib/WhereClause.php +++ b/lib/WhereClause.php @@ -1,4 +1,5 @@ values; $expression = $this->expression; diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 3be409c8..b722738d 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,8 +6,8 @@ parameters: - %currentWorkingDirectory%/test/phpstan reportUnmatchedIgnoredErrors: false - checkGenericClassInNonGenericObjectType: false ignoreErrors: + - identifier: missingType.generics includes: - extension.neon diff --git a/scripts/TestCommand.php b/scripts/TestCommand.php index 8ccf5015..1552582c 100644 --- a/scripts/TestCommand.php +++ b/scripts/TestCommand.php @@ -47,7 +47,7 @@ public static function runTest(Event $event) } } - private static function buildArgs(string|null $fileName, string|null $filter): array + private static function buildArgs(?string $fileName, ?string $filter): array { $args = ['vendor/bin/phpunit']; diff --git a/test/ActiveRecordFindTest.php b/test/ActiveRecordFindTest.php index b9d5e6cd..949f5c7c 100644 --- a/test/ActiveRecordFindTest.php +++ b/test/ActiveRecordFindTest.php @@ -189,13 +189,13 @@ public function testFindHashUsingAliasWithNull() public function testFindAllHash() { - $books = \test\models\Book::all()->where(['author_id' => 1])->to_a(); + $books = test\models\Book::all()->where(['author_id' => 1])->to_a(); $this->assertTrue(count($books) > 0); } public function testFindAllHashWithOrder() { - $books = \test\models\Book::order('name DESC')->where(['author_id' => 1])->to_a(); + $books = test\models\Book::order('name DESC')->where(['author_id' => 1])->to_a(); $this->assertTrue(count($books) > 0); } @@ -259,7 +259,7 @@ public function testForEach() $res = Author::all()->to_a(); foreach ($res as $author) { - $this->assertTrue($author instanceof ActiveRecord\Model); + $this->assertTrue($author instanceof Model); ++$i; } $this->assertTrue($i > 0); @@ -270,7 +270,7 @@ public function testFetchAll() $i = 0; foreach (Author::all()->to_a() as $author) { - $this->assertTrue($author instanceof ActiveRecord\Model); + $this->assertTrue($author instanceof Model); ++$i; } $this->assertTrue($i > 0); diff --git a/test/ActiveRecordGroupTest.php b/test/ActiveRecordGroupTest.php index f2a69472..6115d15a 100644 --- a/test/ActiveRecordGroupTest.php +++ b/test/ActiveRecordGroupTest.php @@ -2,7 +2,6 @@ namespace test; -use ActiveRecord; use ActiveRecord\Table; use test\models\Author; use test\models\Venue; @@ -13,7 +12,7 @@ public function testWithString(): void { $venues = Venue::select('state')->group('state')->to_a(); $this->assertTrue(count($venues) > 0); - $this->assert_sql_includes('GROUP BY state', ActiveRecord\Table::load(Venue::class)->last_sql); + $this->assert_sql_includes('GROUP BY state', Table::load(Venue::class)->last_sql); } public function testWithArray(): void @@ -21,7 +20,7 @@ public function testWithArray(): void $venues = Venue::select(['city', 'state'])->group(['city', 'state'])->to_a(); $this->assertTrue(count($venues) > 0); - $this->assert_sql_includes('GROUP BY city, state', ActiveRecord\Table::load(Venue::class)->last_sql); + $this->assert_sql_includes('GROUP BY city, state', Table::load(Venue::class)->last_sql); } public function testWithList(): void @@ -29,7 +28,7 @@ public function testWithList(): void $venues = Venue::select('city', 'state')->group('city', 'state')->to_a(); $this->assertTrue(count($venues) > 0); - $this->assert_sql_includes('GROUP BY city, state', ActiveRecord\Table::load(Venue::class)->last_sql); + $this->assert_sql_includes('GROUP BY city, state', Table::load(Venue::class)->last_sql); } public function testGroupWithOrderAndLimitAndHaving(): void @@ -42,7 +41,7 @@ public function testGroupWithOrderAndLimitAndHaving(): void $venues = $relation->to_a(); $this->assertTrue(count($venues) > 0); - $this->assert_sql_includes('SELECT state FROM venues GROUP BY state HAVING length(state) = 2 ORDER BY state', ActiveRecord\Table::load(Venue::class)->last_sql); + $this->assert_sql_includes('SELECT state FROM venues GROUP BY state HAVING length(state) = 2 ORDER BY state', Table::load(Venue::class)->last_sql); } public function testHaving(): void diff --git a/test/ActiveRecordNotTest.php b/test/ActiveRecordNotTest.php index d484edca..a74130fe 100644 --- a/test/ActiveRecordNotTest.php +++ b/test/ActiveRecordNotTest.php @@ -15,20 +15,20 @@ public static function conditions(): array ], 'array' => [ [ - 'name = ?', 'Another Book', + 'name = ?', 'Another Book', ], static fn ($book) => 'AnotherBook' != $book->name ], 'hash' => [[ - 'name' => 'Another Book', - ], + 'name' => 'Another Book', + ], static fn ($book) => 'AnotherBook' != $book->name ], 'in' => [[ 'book_id in (?)', [1, 2], - ], - static fn ($book) => 1 != $book->name && 2 != $book->name - ], + ], + static fn ($book) => 1 != $book->name && 2 != $book->name + ], ]; } diff --git a/test/ActiveRecordTest.php b/test/ActiveRecordTest.php index cb8a3b94..ac31ed33 100644 --- a/test/ActiveRecordTest.php +++ b/test/ActiveRecordTest.php @@ -121,14 +121,14 @@ public function testReloadProtectedAttribute() public function testNamespaceGetsStrippedFromTableName() { - new \test\models\namespacetest\Book(); - $this->assertEquals('books', Table::load(\test\models\namespacetest\Book::class)->table); + new test\models\namespacetest\Book(); + $this->assertEquals('books', Table::load(test\models\namespacetest\Book::class)->table); } public function testNamespaceGetsStrippedFromInferredForeignKey() { - $model = new \test\models\namespacetest\Book(); - $table = ActiveRecord\Table::load(get_class($model)); + $model = new test\models\namespacetest\Book(); + $table = Table::load(get_class($model)); $this->assertEquals($table->get_relationship('parent_book')->foreign_key[0], 'book_id'); $this->assertEquals($table->get_relationship('parent_book_2')->foreign_key[0], 'book_id'); @@ -137,8 +137,8 @@ public function testNamespaceGetsStrippedFromInferredForeignKey() public function testNamespacedRelationshipAssociatesCorrectly() { - $model = new \test\models\namespacetest\Book(); - $table = ActiveRecord\Table::load(get_class($model)); + $model = new test\models\namespacetest\Book(); + $table = Table::load(get_class($model)); $this->assertNotNull($table->get_relationship('parent_book')); $this->assertNotNull($table->get_relationship('parent_book_2')); @@ -266,7 +266,7 @@ public function testCastWhenUsingSetter() public function testCastWhenLoading() { - $book = \test\models\Book::find(1); + $book = Book::find(1); $this->assertSame(1, $book->book_id); $this->assertSame('Ancient Art of Main Tanking', $book->name); } @@ -400,10 +400,10 @@ public function testUndefinedInstanceMethod() public function testClearCacheForSpecificClass() { - $book_table1 = ActiveRecord\Table::load(Book::class); - $book_table2 = ActiveRecord\Table::load(Book::class); - ActiveRecord\Table::clear_cache('Book'); - $book_table3 = ActiveRecord\Table::load(Book::class); + $book_table1 = Table::load(Book::class); + $book_table2 = Table::load(Book::class); + Table::clear_cache('Book'); + $book_table3 = Table::load(Book::class); $this->assertTrue($book_table1 === $book_table2); $this->assertTrue($book_table1 !== $book_table3); @@ -437,7 +437,7 @@ public function testGh245DirtyAttributeShouldNotRaisePhpNoticeIfNotDirty() public function testAssigningPhpDatetimeGetsConvertedToDateClassWithDefaults() { $author = new Author(); - $author->created_at = $now = new \DateTime(); + $author->created_at = $now = new DateTime(); $this->assertInstanceOf('ActiveRecord\\DateTime', $author->created_at); $this->assertEquals($now->format(DateTime::ATOM), $author->created_at->format(DateTime::ATOM)); } @@ -446,14 +446,14 @@ public function testAssigningPhpDatetimeGetsConvertedToDateClassWithCustomDateCl { ActiveRecord\Config::instance()->set_date_class('\\DateTime'); // use PHP built-in DateTime $author = new Author(); - $author->created_at = $now = new \DateTime(); + $author->created_at = $now = new DateTime(); $this->assertInstanceOf('DateTime', $author->created_at); $this->assertEquals($now->format(DateTime::ATOM), $author->created_at->format(DateTime::ATOM)); } public function testAssigningFromMassAssignmentPhpDatetimeGetsConvertedToArDatetime() { - $author = new Author(['created_at' => new \DateTime()]); + $author = new Author(['created_at' => new DateTime()]); $this->assertInstanceOf('ActiveRecord\\DateTime', $author->created_at); } diff --git a/test/ActiveRecordWriteTest.php b/test/ActiveRecordWriteTest.php index 17451e9f..bdee1106 100644 --- a/test/ActiveRecordWriteTest.php +++ b/test/ActiveRecordWriteTest.php @@ -36,7 +36,7 @@ class AuthorExplicitSequence extends ActiveRecord\Model class ActiveRecordWriteTest extends DatabaseTestCase { - public function setUp(string $connection_name=null): void + public function setUp(?string $connection_name=null): void { parent::setUp($connection_name); static::resetTableData(); @@ -314,7 +314,7 @@ public function testDeleteWithNoPrimaryKeyDefined() { $this->expectException(ActiveRecordException::class); Table::load(Author::class)->pk = []; - $author = author::first(); + $author = Author::first(); $author->delete(); } diff --git a/test/CacheModelTest.php b/test/CacheModelTest.php index e26b74dc..8423c097 100644 --- a/test/CacheModelTest.php +++ b/test/CacheModelTest.php @@ -67,7 +67,7 @@ public function testModelCacheFindByPk() public function testModelCacheNew() { $publisher = new Publisher([ - 'name'=>'HarperCollins' + 'name'=>'HarperCollins' ]); $publisher->save(); diff --git a/test/ColumnTest.php b/test/ColumnTest.php index af945426..a0ebee68 100644 --- a/test/ColumnTest.php +++ b/test/ColumnTest.php @@ -130,7 +130,7 @@ public function testEmptyAndNullDatetimeStringsShouldReturnNull() public function testNativeDateTimeAttributeCopiesExactTz() { - $dt = new \DateTime('', new \DateTimeZone('America/New_York')); + $dt = new \DateTime('', new DateTimeZone('America/New_York')); $column = new Column(); $column->type = Column::DATETIME; @@ -144,7 +144,7 @@ public function testNativeDateTimeAttributeCopiesExactTz() public function testArDateTimeAttributeCopiesExactTz() { - $dt = new DateTime('', new \DateTimeZone('America/New_York')); + $dt = new DateTime('', new DateTimeZone('America/New_York')); $column = new Column(); $column->type = Column::DATETIME; diff --git a/test/ConfigTest.php b/test/ConfigTest.php index 1559f0f5..ce97cf1a 100644 --- a/test/ConfigTest.php +++ b/test/ConfigTest.php @@ -8,7 +8,7 @@ class TestLogger implements LoggerInterface { - public function emergency(string|\Stringable $message, array $context = []): void + public function emergency(string|Stringable $message, array $context = []): void { } @@ -20,7 +20,7 @@ public function emergency(string|\Stringable $message, array $context = []): voi * * @param mixed[] $context */ - public function alert(string|\Stringable $message, array $context = []): void + public function alert(string|Stringable $message, array $context = []): void { } @@ -31,7 +31,7 @@ public function alert(string|\Stringable $message, array $context = []): void * * @param mixed[] $context */ - public function critical(string|\Stringable $message, array $context = []): void + public function critical(string|Stringable $message, array $context = []): void { } @@ -41,7 +41,7 @@ public function critical(string|\Stringable $message, array $context = []): void * * @param mixed[] $context */ - public function error(string|\Stringable $message, array $context = []): void + public function error(string|Stringable $message, array $context = []): void { } @@ -53,7 +53,7 @@ public function error(string|\Stringable $message, array $context = []): void * * @param mixed[] $context */ - public function warning(string|\Stringable $message, array $context = []): void + public function warning(string|Stringable $message, array $context = []): void { } @@ -62,7 +62,7 @@ public function warning(string|\Stringable $message, array $context = []): void * * @param mixed[] $context */ - public function notice(string|\Stringable $message, array $context = []): void + public function notice(string|Stringable $message, array $context = []): void { } @@ -73,7 +73,7 @@ public function notice(string|\Stringable $message, array $context = []): void * * @param mixed[] $context */ - public function info(string|\Stringable $message, array $context = []): void + public function info(string|Stringable $message, array $context = []): void { } @@ -82,7 +82,7 @@ public function info(string|\Stringable $message, array $context = []): void * * @param mixed[] $context */ - public function debug(string|\Stringable $message, array $context = []): void + public function debug(string|Stringable $message, array $context = []): void { } @@ -91,9 +91,9 @@ public function debug(string|\Stringable $message, array $context = []): void * * @param mixed[] $context * - * @throws \Psr\Log\InvalidArgumentException + * @throws Psr\Log\InvalidArgumentException */ - public function log($level, string|\Stringable $message, array $context = []): void + public function log($level, string|Stringable $message, array $context = []): void { } } diff --git a/test/ConnectionTest.php b/test/ConnectionTest.php index 1908dc10..e9cb0292 100644 --- a/test/ConnectionTest.php +++ b/test/ConnectionTest.php @@ -12,12 +12,12 @@ class ConnectionTest extends TestCase public function testConnectionInfoFromShouldThrowExceptionWhenNoHost() { $this->expectException(DatabaseException::class); - ActiveRecord\Connection::parse_connection_url('mysql://user:pass@'); + Connection::parse_connection_url('mysql://user:pass@'); } public function testConnectionInfo() { - $info = ActiveRecord\Connection::parse_connection_url('mysql://user:pass@127.0.0.1:3306/dbname'); + $info = Connection::parse_connection_url('mysql://user:pass@127.0.0.1:3306/dbname'); $this->assertEquals('mysql', $info['protocol']); $this->assertEquals('user', $info['user']); $this->assertEquals('pass', $info['pass']); @@ -28,37 +28,37 @@ public function testConnectionInfo() public function testGh103SqliteConnectionStringRelative() { - $info = ActiveRecord\Connection::parse_connection_url('sqlite://../some/path/to/file.db'); + $info = Connection::parse_connection_url('sqlite://../some/path/to/file.db'); $this->assertEquals('../some/path/to/file.db', $info['host']); } public function testGh103SqliteConnectionStringAbsolute() { $this->expectException(DatabaseException::class); - ActiveRecord\Connection::parse_connection_url('sqlite:///some/path/to/file.db'); + Connection::parse_connection_url('sqlite:///some/path/to/file.db'); } public function testGh103SqliteConnectionStringUnix() { - $info = ActiveRecord\Connection::parse_connection_url('sqlite://unix(/some/path/to/file.db)'); + $info = Connection::parse_connection_url('sqlite://unix(/some/path/to/file.db)'); $this->assertEquals('/some/path/to/file.db', $info['host']); - $info = ActiveRecord\Connection::parse_connection_url('sqlite://unix(/some/path/to/file.db)/'); + $info = Connection::parse_connection_url('sqlite://unix(/some/path/to/file.db)/'); $this->assertEquals('/some/path/to/file.db', $info['host']); - $info = ActiveRecord\Connection::parse_connection_url('sqlite://unix(/some/path/to/file.db)/dummy'); + $info = Connection::parse_connection_url('sqlite://unix(/some/path/to/file.db)/dummy'); $this->assertEquals('/some/path/to/file.db', $info['host']); } public function testGh103SqliteConnectionStringWindows() { - $info = ActiveRecord\Connection::parse_connection_url('sqlite://windows(c%3A/some/path/to/file.db)'); + $info = Connection::parse_connection_url('sqlite://windows(c%3A/some/path/to/file.db)'); $this->assertEquals('c:/some/path/to/file.db', $info['host']); } public function testParseConnectionUrlWithUnixSockets() { - $info = ActiveRecord\Connection::parse_connection_url('mysql://user:password@unix(/tmp/mysql.sock)/database'); + $info = Connection::parse_connection_url('mysql://user:password@unix(/tmp/mysql.sock)/database'); $this->assertEquals('/tmp/mysql.sock', $info['host']); $dsn = Connection::data_source_name($info); @@ -67,20 +67,20 @@ public function testParseConnectionUrlWithUnixSockets() public function testParseConnectionUrlWithDecodeOption() { - $info = ActiveRecord\Connection::parse_connection_url('mysql://h%20az:h%40i@127.0.0.1/test?decode=true'); + $info = Connection::parse_connection_url('mysql://h%20az:h%40i@127.0.0.1/test?decode=true'); $this->assertEquals('h az', $info['user']); $this->assertEquals('h@i', $info['pass']); } public function testEncoding() { - $info = ActiveRecord\Connection::parse_connection_url('mysql://test:test@127.0.0.1/test?charset=utf8'); + $info = Connection::parse_connection_url('mysql://test:test@127.0.0.1/test?charset=utf8'); $this->assertEquals('utf8', $info['charset']); } public function testReestablishConnection() { - $connection = \test\models\Book::reestablish_connection(true); + $connection = test\models\Book::reestablish_connection(true); $this->assertNotNull($connection); } } diff --git a/test/DateTimeTest.php b/test/DateTimeTest.php index fac7527a..5039421a 100644 --- a/test/DateTimeTest.php +++ b/test/DateTimeTest.php @@ -158,7 +158,7 @@ public function testCreateFromFormatWithoutTz() public function testCreateFromFormatWithTz() { - $d = DateTime::createFromFormat('Y-m-d H:i:s', '2000-02-01 03:04:05', new \DateTimeZone('Etc/GMT-10')); + $d = DateTime::createFromFormat('Y-m-d H:i:s', '2000-02-01 03:04:05', new DateTimeZone('Etc/GMT-10')); $d2 = new DateTime('2000-01-31 17:04:05'); $this->assertEquals($d2->getTimestamp(), $d->getTimestamp()); @@ -166,7 +166,7 @@ public function testCreateFromFormatWithTz() public function testNativeDateTimeAttributeCopiesExactTz() { - $dt = new \DateTime('', new \DateTimeZone('America/New_York')); + $dt = new \DateTime('', new DateTimeZone('America/New_York')); $model = $this->get_model(); // Test that the data transforms without modification @@ -180,7 +180,7 @@ public function testNativeDateTimeAttributeCopiesExactTz() public function testArDateTimeAttributeCopiesExactTz() { - $dt = new DateTime('', new \DateTimeZone('America/New_York')); + $dt = new DateTime('', new DateTimeZone('America/New_York')); $model = $this->get_model(); // Test that the data transforms without modification diff --git a/test/MysqlAdapterTest.php b/test/MysqlAdapterTest.php index b541f8f2..2a348966 100644 --- a/test/MysqlAdapterTest.php +++ b/test/MysqlAdapterTest.php @@ -22,10 +22,10 @@ public function testSubstituteEscapesQuotes() public function testValidatesUniquenessOfWorksWithMysqlReservedWordAsColumnName() { ValueStoreValidations::create(['key' => 'GA_KEY', 'value' => 'UA-1234567-1']); - $valuestore = ValuestoreValidations::create(['key' => 'GA_KEY', 'value' => 'UA-1234567-2']); + $valuestore = ValueStoreValidations::create(['key' => 'GA_KEY', 'value' => 'UA-1234567-2']); $this->assertEquals(['Key must be unique'], $valuestore->errors->full_messages()); - $this->assertEquals(1, ValuestoreValidations::where('`key`= ?', 'GA_KEY')->count()); + $this->assertEquals(1, ValueStoreValidations::where('`key`= ?', 'GA_KEY')->count()); } public function testEnum() diff --git a/test/PgsqlAdapterTest.php b/test/PgsqlAdapterTest.php index 65d5df7a..31e9d9ed 100644 --- a/test/PgsqlAdapterTest.php +++ b/test/PgsqlAdapterTest.php @@ -31,7 +31,7 @@ public function testToSql(): void { $this->assert_sql_includes( 'SELECT * FROM authors WHERE "mixedCaseField" = ? ORDER BY name', - \test\models\Author::where('mixedCaseField = ?', 'The Art of Main Tanking') + Author::where('mixedCaseField = ?', 'The Art of Main Tanking') ->order('name')->to_sql() ); } diff --git a/test/RelationTest.php b/test/RelationTest.php index f6b3099b..bcfd1611 100644 --- a/test/RelationTest.php +++ b/test/RelationTest.php @@ -179,7 +179,7 @@ public function testToSql(): void { $this->assert_sql_includes( 'SELECT * FROM `books` WHERE name = ? ORDER BY name', - \test\models\Book::where('name = ?', 'The Art of Main Tanking') + test\models\Book::where('name = ?', 'The Art of Main Tanking') ->order('name')->to_sql() ); } diff --git a/test/RelationshipTest.php b/test/RelationshipTest.php index 89f987e3..c799b541 100644 --- a/test/RelationshipTest.php +++ b/test/RelationshipTest.php @@ -303,7 +303,7 @@ public function testHasAndBelongsToManyIsPoly() public function testHasAndBelongsToManyDoesNotEagerLoad() { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $hasAndBelongsToMany = new HasAndBelongsToMany(Book::class); $hasAndBelongsToMany->load_eagerly([], [], [], Table::load(Book::class)); } @@ -400,7 +400,7 @@ public function testHasManyWithReadonly() try { $venue->events[0]->save(); $this->fail('expected exception ActiveRecord\ReadonlyException'); - } catch (ReadonlyException $e) { + } catch (ReadOnlyException $e) { } $venue->events[0]->description = 'new desc'; @@ -523,7 +523,7 @@ public function testHasManyThroughWithConditions() $venue = Venue::find(2); $this->assertTrue(1 === count($venue->hosts)); - $this->assert_sql_includes('events.title !=', ActiveRecord\Table::load(Host::class)->last_sql); + $this->assert_sql_includes('events.title !=', Table::load(Host::class)->last_sql); } public function testHasManyThroughUsingSource() @@ -545,7 +545,7 @@ public function testHasManyThroughUsingSource() public function testHasManyThroughWithInvalidClassName() { - $this->expectException(\ReflectionException::class); + $this->expectException(ReflectionException::class); Event::$belongs_to = [ 'host' => true ]; @@ -585,7 +585,7 @@ public function testHasManyWithExplicitKeys() $this->assertEquals($book->secondary_author_id, $author->parent_author_id); } - $this->assertTrue(false !== strpos(ActiveRecord\Table::load(Book::class)->last_sql, 'secondary_author_id')); + $this->assertTrue(false !== strpos(Table::load(Book::class)->last_sql, 'secondary_author_id')); } public function testHasOneBasic() @@ -648,7 +648,7 @@ public function testHasOneWithReadonly() try { $employee->position->save(); $this->fail('expected exception ActiveRecord\ReadonlyException'); - } catch (ReadonlyException $e) { + } catch (ReadOnlyException $e) { } $employee->position->title = 'new title'; @@ -681,7 +681,7 @@ public function testHasOneWithExplicitKeys() $book = Book::find(1); $this->assertEquals($book->secondary_author_id, $book->explicit_author->parent_author_id); - $this->assertTrue(false !== strpos(ActiveRecord\Table::load(Author::class)->last_sql, 'parent_author_id')); + $this->assertTrue(false !== strpos(Table::load(Author::class)->last_sql, 'parent_author_id')); } public function testDontAttemptToLoadIfAllForeignKeysAreNull() @@ -727,7 +727,7 @@ public function testEagerLoadingRespectsAssociationOptions() ]; $venues = Venue::includes('events')->find([2, 6]); - $this->assert_sql_includes('WHERE (title = ?) AND (venue_id IN(?,?)) ORDER BY id asc', ActiveRecord\Table::load(Event::class)->last_sql); + $this->assert_sql_includes('WHERE (title = ?) AND (venue_id IN(?,?)) ORDER BY id asc', Table::load(Event::class)->last_sql); $this->assertEquals(1, count($venues[0]->events)); } @@ -750,7 +750,7 @@ public function testEagerLoadingWithThrough() public function testEagerLoadingHasManyX() { $venues = Venue::includes('events')->find([2, 6]); - $this->assert_sql_includes('WHERE venue_id IN(?,?)', ActiveRecord\Table::load(Event::class)->last_sql); + $this->assert_sql_includes('WHERE venue_id IN(?,?)', Table::load(Event::class)->last_sql); foreach ($venues[0]->events as $event) { $this->assertEquals($event->venue_id, $venues[0]->id); @@ -767,8 +767,8 @@ public function testEagerLoadingHasManyWithNoRelatedRows() $this->assertTrue(empty($v->events)); } - $this->assert_sql_includes('WHERE id IN(?,?)', ActiveRecord\Table::load(Venue::class)->last_sql); - $this->assert_sql_includes('WHERE venue_id IN(?,?)', ActiveRecord\Table::load(Event::class)->last_sql); + $this->assert_sql_includes('WHERE id IN(?,?)', Table::load(Venue::class)->last_sql); + $this->assert_sql_includes('WHERE venue_id IN(?,?)', Table::load(Event::class)->last_sql); } public function testEagerLoadingHasManyArrayOfIncludes() @@ -794,9 +794,9 @@ public function testEagerLoadingHasManyArrayOfIncludes() $this->assertIsArray($authors[1]->$assoc); } - $this->assert_sql_includes('WHERE author_id IN(?,?)', ActiveRecord\Table::load(Author::class)->last_sql); - $this->assert_sql_includes('WHERE author_id IN(?,?)', ActiveRecord\Table::load(Book::class)->last_sql); - $this->assert_sql_includes('WHERE author_id IN(?,?)', ActiveRecord\Table::load(AwesomePerson::class)->last_sql); + $this->assert_sql_includes('WHERE author_id IN(?,?)', Table::load(Author::class)->last_sql); + $this->assert_sql_includes('WHERE author_id IN(?,?)', Table::load(Book::class)->last_sql); + $this->assert_sql_includes('WHERE author_id IN(?,?)', Table::load(AwesomePerson::class)->last_sql); } public function testEagerLoadingHasManyNested() @@ -815,9 +815,9 @@ public function testEagerLoadingHasManyNested() } } - $this->assert_sql_includes('WHERE id IN(?,?)', ActiveRecord\Table::load(Venue::class)->last_sql); - $this->assert_sql_includes('WHERE venue_id IN(?,?)', ActiveRecord\Table::load(Event::class)->last_sql); - $this->assert_sql_includes('WHERE id IN(?,?,?)', ActiveRecord\Table::load(Host::class)->last_sql); + $this->assert_sql_includes('WHERE id IN(?,?)', Table::load(Venue::class)->last_sql); + $this->assert_sql_includes('WHERE venue_id IN(?,?)', Table::load(Event::class)->last_sql); + $this->assert_sql_includes('WHERE id IN(?,?,?)', Table::load(Host::class)->last_sql); } public function testEagerLoadingBelongsTo() @@ -829,7 +829,7 @@ public function testEagerLoadingBelongsTo() $this->assertEquals($event->venue_id, $event->venue->id); } - $this->assert_sql_includes('WHERE id IN(?,?,?,?,?)', ActiveRecord\Table::load(Venue::class)->last_sql); + $this->assert_sql_includes('WHERE id IN(?,?,?,?,?)', Table::load(Venue::class)->last_sql); } public function testEagerLoadingBelongsToArrayOfIncludes() @@ -841,9 +841,9 @@ public function testEagerLoadingBelongsToArrayOfIncludes() $this->assertEquals($event->host_id, $event->host->id); } - $this->assert_sql_includes('WHERE id IN(?,?,?,?,?)', ActiveRecord\Table::load(Event::class)->last_sql); - $this->assert_sql_includes('WHERE id IN(?,?,?,?,?)', ActiveRecord\Table::load(Host::class)->last_sql); - $this->assert_sql_includes('WHERE id IN(?,?,?,?,?)', ActiveRecord\Table::load(Venue::class)->last_sql); + $this->assert_sql_includes('WHERE id IN(?,?,?,?,?)', Table::load(Event::class)->last_sql); + $this->assert_sql_includes('WHERE id IN(?,?,?,?,?)', Table::load(Host::class)->last_sql); + $this->assert_sql_includes('WHERE id IN(?,?,?,?,?)', Table::load(Venue::class)->last_sql); } public function testEagerLoadingBelongsToNested() @@ -866,9 +866,9 @@ public function testEagerLoadingBelongsToNested() $this->assertEquals($book->author->author_id, $book->author->awesome_people[0]->author_id); } - $this->assert_sql_includes('WHERE book_id IN(?,?)', ActiveRecord\Table::load(Book::class)->last_sql); - $this->assert_sql_includes('WHERE author_id IN(?,?)', ActiveRecord\Table::load(Author::class)->last_sql); - $this->assert_sql_includes('WHERE author_id IN(?,?)', ActiveRecord\Table::load(AwesomePerson::class)->last_sql); + $this->assert_sql_includes('WHERE book_id IN(?,?)', Table::load(Book::class)->last_sql); + $this->assert_sql_includes('WHERE author_id IN(?,?)', Table::load(Author::class)->last_sql); + $this->assert_sql_includes('WHERE author_id IN(?,?)', Table::load(AwesomePerson::class)->last_sql); } public function testEagerLoadingBelongsToWithNoRelatedRows() @@ -883,8 +883,8 @@ public function testEagerLoadingBelongsToWithNoRelatedRows() $this->assertNull($e->venue); } - $this->assert_sql_includes('WHERE id IN(?,?)', ActiveRecord\Table::load(Event::class)->last_sql); - $this->assert_sql_includes('WHERE id IN(?,?)', ActiveRecord\Table::load(Venue::class)->last_sql); + $this->assert_sql_includes('WHERE id IN(?,?)', Table::load(Event::class)->last_sql); + $this->assert_sql_includes('WHERE id IN(?,?)', Table::load(Venue::class)->last_sql); } public function testEagerLoadingClonesRelatedObjects() @@ -931,7 +931,7 @@ public function testGh23RelationshipsWithJoinsToSameTableShouldAliasTableName() ] ]; - $c = ActiveRecord\Table::load(Book::class)->conn; + $c = Table::load(Book::class)->conn; $select = "books.*, authors.name as to_author_name, {$c->quote_name('from_')}.name as from_author_name, {$c->quote_name('another')}.name as another_author_name"; $book = Book::joins(['to', 'from_', 'another']) diff --git a/test/SerializationTest.php b/test/SerializationTest.php index 9e723ed1..a7e4ba1a 100644 --- a/test/SerializationTest.php +++ b/test/SerializationTest.php @@ -100,7 +100,7 @@ public function testDatetimeValuesGetConvertedToStrings() { $now = new DateTime(); $a = $this->_a(['only' => 'created_at'], new Author(['created_at' => $now])); - $this->assertEquals($now->format(\ActiveRecord\Serialize\Serialization::$DATETIME_FORMAT), $a['created_at']); + $this->assertEquals($now->format(ActiveRecord\Serialize\Serialization::$DATETIME_FORMAT), $a['created_at']); } public function testToJson() @@ -200,7 +200,7 @@ public function testToCsvOnlyMethodOnHeader() $book = Book::find(1); $this->assertEquals('secondary_author_id,name', $book->to_csv(['only'=>['secondary_author_id', 'name'], - 'only_header'=>true]) + 'only_header'=>true]) ); } diff --git a/test/SqliteAdapterTest.php b/test/SqliteAdapterTest.php index 850c528a..2773ac71 100644 --- a/test/SqliteAdapterTest.php +++ b/test/SqliteAdapterTest.php @@ -7,7 +7,7 @@ class SqliteAdapterTest extends AdapterTestCase { - public function setUp(string $connection_name=null): void + public function setUp(?string $connection_name=null): void { parent::setUp('sqlite'); } diff --git a/test/ValidationsTest.php b/test/ValidationsTest.php index e3e791fd..1efb43eb 100644 --- a/test/ValidationsTest.php +++ b/test/ValidationsTest.php @@ -22,7 +22,7 @@ public function validate() class ValidationsTest extends DatabaseTestCase { - public function setUp(string $connection_name=null): void + public function setUp(?string $connection_name=null): void { parent::setUp($connection_name); diff --git a/test/helpers/AdapterTestCase.php b/test/helpers/AdapterTestCase.php index b9b3bd51..36306255 100644 --- a/test/helpers/AdapterTestCase.php +++ b/test/helpers/AdapterTestCase.php @@ -10,7 +10,7 @@ abstract class AdapterTestCase extends DatabaseTestCase { public const InvalidDb = '__1337__invalid_db__'; - public function setUp(string $connection_name=null): void + public function setUp(?string $connection_name=null): void { if (($connection_name && !in_array($connection_name, PDO::getAvailableDrivers())) || 'skip' == ActiveRecord\Config::instance()->get_connection($connection_name)) { diff --git a/test/helpers/DatabaseTestCase.php b/test/helpers/DatabaseTestCase.php index 15e64bd6..b081dd6c 100644 --- a/test/helpers/DatabaseTestCase.php +++ b/test/helpers/DatabaseTestCase.php @@ -17,7 +17,7 @@ abstract class DatabaseTestCase extends TestCase public static $log = false; public static $db; - public function setUp(string $connection_name=null): void + public function setUp(?string $connection_name=null): void { ActiveRecord\Table::clear_cache(); Cache::flush(); @@ -38,7 +38,7 @@ public function setUp(string $connection_name=null): void } try { - ActiveRecord\ConnectionManager::get_connection($connection_name); + ConnectionManager::get_connection($connection_name); } catch (Exception $e) { $this->markTestSkipped($connection_name . ' failed to connect. ' . $e->getMessage()); } diff --git a/test/helpers/config.php b/test/helpers/config.php index 4ffd8326..3e05bcc3 100644 --- a/test/helpers/config.php +++ b/test/helpers/config.php @@ -51,9 +51,9 @@ if (class_exists('Monolog\Logger')) { // Monolog installed $log = new Monolog\Logger('arlog'); - $log->pushHandler(new \Monolog\Handler\StreamHandler( + $log->pushHandler(new Monolog\Handler\StreamHandler( dirname(__FILE__) . '/../log/query.log', - \Monolog\Level::Warning) + Monolog\Level::Warning) ); $cfg->set_logging(true); diff --git a/test/phpstan/ModelDynamicFindBy.php b/test/phpstan/ModelDynamicFindBy.php index 96fd0a05..200eb9fe 100644 --- a/test/phpstan/ModelDynamicFindBy.php +++ b/test/phpstan/ModelDynamicFindBy.php @@ -1,4 +1,5 @@ first(); } - public function bookFromLast(): Book|null + public function bookFromLast(): ?Book { return Book::all()->last(); } @@ -45,7 +46,7 @@ public function booksFromToA(): array return Book::all()->to_a(); } - public function bookFromTake(): Book|null + public function bookFromTake(): ?Book { return Book::all()->take(); }