Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
with:
path: lib/ tests/
level: 9
php_version: 8.1
php_version: 8.2
18 changes: 17 additions & 1 deletion .wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,20 @@ Traceback
nodejs
npm
fediverse
readme
readme
phpnomad
datastore
schemas
lookups
DateCreatedFactory
DateModifiedFactory
PHPNomad
PrimaryKeyFactory
PostsTable
getUnprefixedName
DatabaseServiceProvider
IdentifiableDatabaseDatastoreHandler
TableSchemaService
WithDatastoreHandlerMethods
PostDatabaseDatastoreHandler
txt
5 changes: 3 additions & 2 deletions lib/Factories/Columns/DateCreatedFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

namespace PHPNomad\Database\Factories\Columns;

use DateTimeImmutable;
use PHPNomad\Chrono\Interfaces\ClockStrategy;
use PHPNomad\Database\Factories\Column;
use PHPNomad\Database\Interfaces\CanConvertToColumn;

class DateCreatedFactory implements CanConvertToColumn
{
public function __construct(protected ClockStrategy $clock)
public function __construct(protected ?ClockStrategy $clock = null)
{
}

public function toColumn(): Column
{
return (new Column('dateCreated', 'TIMESTAMP', null, 'NOT NULL DEFAULT CURRENT_TIMESTAMP'))
->withPhpDefault(fn (): string => $this->clock->now()->format('Y-m-d H:i:s'));
->withPhpDefault(fn (): string => ($this->clock === null ? new DateTimeImmutable() : $this->clock->now())->format('Y-m-d H:i:s'));
}
}
5 changes: 3 additions & 2 deletions lib/Factories/Columns/DateModifiedFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

namespace PHPNomad\Database\Factories\Columns;

use DateTimeImmutable;
use PHPNomad\Chrono\Interfaces\ClockStrategy;
use PHPNomad\Database\Factories\Column;
use PHPNomad\Database\Interfaces\CanConvertToColumn;

class DateModifiedFactory implements CanConvertToColumn
{
public function __construct(protected ClockStrategy $clock)
public function __construct(protected ?ClockStrategy $clock = null)
{
}

public function toColumn(): Column
{
return (new Column('dateModified', 'TIMESTAMP', null, 'NOT NULL DEFAULT CURRENT_TIMESTAMP'))
->withPhpDefault(fn (): string => $this->clock->now()->format('Y-m-d H:i:s'));
->withPhpDefault(fn (): string => ($this->clock === null ? new DateTimeImmutable() : $this->clock->now())->format('Y-m-d H:i:s'));
}
}
956 changes: 956 additions & 0 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
includes:
- phpstan-baseline.neon

parameters:
level: 9
2 changes: 1 addition & 1 deletion tests/Unit/Factories/Columns/DateCreatedFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testProducesDateCreatedColumnWithDbDefault(): void

public function testProvidesPhpDefaultThatReturnsMysqlFormatTimestamp(): void
{
$column = (new DateCreatedFactory($this->makeClock()))->toColumn();
$column = (new DateCreatedFactory())->toColumn();
$default = $column->getPhpDefault();

$this->assertIsCallable($default);
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Factories/Columns/DateModifiedFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testProducesDateModifiedColumnWithDbDefault(): void

public function testProvidesPhpDefaultThatReturnsMysqlFormatTimestamp(): void
{
$column = (new DateModifiedFactory($this->makeClock()))->toColumn();
$column = (new DateModifiedFactory())->toColumn();
$default = $column->getPhpDefault();

$this->assertIsCallable($default);
Expand Down
Loading