diff --git a/composer.json b/composer.json index e403b2ee..2535a019 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "phpstan/phpstan-nette": "1.2.3", "phpstan/phpstan-mockery": "1.1.0", "phpstan/phpstan-strict-rules": "1.4.5", - "nextras/orm-phpstan": "~1.0", + "nextras/orm-phpstan": "~1.0@dev", "marc-mabe/php-enum-phpstan": "dev-master", "tracy/tracy": "~2.3" }, diff --git a/docs/conventions.md b/docs/conventions.md index f62bda55..e492d8a9 100644 --- a/docs/conventions.md +++ b/docs/conventions.md @@ -10,9 +10,12 @@ Table names are directly resolved in the mapper layer; they are derived from the If you would like to force some other table name, define `$tableName` property, or override `getTableName()` method in the mapper class. ```php -use Nextras\Orm\Mapper\Mapper; +use Nextras\Orm\Mapper\Dbal\DbalMapper; -class EventsMapper extends Mapper +/** + * @extends DbalMapper + */ +class EventsMapper extends DbalMapper { protected $tableName = 'events'; @@ -42,10 +45,13 @@ These predefined classes assume "camelCase" naming in the entity layer and trans You are free to add your own mapping. Just call `setMapping($entityName, $storageName)` method. The right way to do this is to inherit `createConventions()` method in your mapper class. ```php -use Nextras\Orm\Mapper\Mapper; +use Nextras\Orm\Mapper\Dbal\DbalMapper; use Nextras\Orm\Mapper\Dbal\Conventions\IConventions; -class EventsMapper extends Mapper +/** + * @extends DbalMapper + */ +class EventsMapper extends DbalMapper { protected function createConventions(): IConventions { @@ -69,6 +75,9 @@ class File extends Nextras\Orm\Entity\Entity { } +/** + * @extends DbalMapper + */ class FilesMapper extends Nextras\Orm\Mapper\Dbal\DbalMapper { protected function createConventions(): Nextras\Orm\Mapper\Dbal\Conventions\IConventions @@ -97,6 +106,9 @@ class File extends Nextras\Orm\Entity\Entity { } +/** + * @extends DbalMapper + */ class FilesMapper extends Nextras\Orm\Mapper\Dbal\DbalMapper { protected function createConventions(): Nextras\Orm\Mapper\Dbal\Conventions\IConventions @@ -114,11 +126,15 @@ class FilesMapper extends Nextras\Orm\Mapper\Dbal\DbalMapper There are many possibilities to change default table joining conventions. If you are using `m:m`, you can change its pattern property. By default, the pattern is defined as `%s_x_%s`. The first placeholder is the primary table name. ```php -use Nextras\Orm\Mapper\Mapper; use Nextras\Orm\Mapper\Dbal\Conventions\Conventions; use Nextras\Orm\Mapper\Dbal\Conventions\IConventions; +use Nextras\Orm\Mapper\Dbal\DbalMapper; -class BaseMapper extends Mapper +/** + * @template E of \Nextras\Orm\Entity\IEntity + * @extends DbalMapper + */ +class BaseMapper extends DbalMapper { protected function createConventions(): IConventions { @@ -133,9 +149,12 @@ class BaseMapper extends Mapper If you need more advanced configuration, feel free to override `getManyHasManyParameters()` method in your mapper. This method returns an array where the first value is a joining table name, the second is an array of joining keys/columns. If you have only one `m:m` relationship between two entities, you can return the result based only on the passed target mapper, source property's metadata are available for more detailed matching. ```php -use Nextras\Orm\Mapper\Mapper; +use Nextras\Orm\Mapper\Dbal\DbalMapper; -class EmployeesMapper extends Mapper +/** + * @extends DbalMapper + */ +class EmployeesMapper extends DbalMapper { public function getManyHasManyParameters(PropertyMetadata $sourceProperty, DbalMapper $targetMapper): array { diff --git a/docs/entity-sti.md b/docs/entity-sti.md index b6b4727d..5d9823c3 100644 --- a/docs/entity-sti.md +++ b/docs/entity-sti.md @@ -32,6 +32,9 @@ class PublicAddress extends Address { } +/** + * @extends Nextras\Orm\Repository\Repository
+ */ class AddressesRepository extends Nextras\Orm\Repository\Repository { public static function getEntityClassNames(): array diff --git a/docs/mapper.md b/docs/mapper.md index a9ab4e31..21d8f615 100644 --- a/docs/mapper.md +++ b/docs/mapper.md @@ -16,10 +16,13 @@ Dbal mapper uses [Nextras Dbal][1] library. Both Nextras Dbal and Orm support th - Postgres, - SQL Server (currently not supported auto-update mapping). -Dbal mapper is aliased as `Nextras\Orm\Mapper\Mapper` class. To set mapper's database **table name** set `$tableName` property or override `getTableName()` method. +To set mapper's database **table name** set `$tableName` property or override `getTableName()` method. ```php -class BooksMapper extends Nextras\Orm\Mapper\Mapper +/** + * @extends DbalMapper + */ +class BooksMapper extends Nextras\Orm\Mapper\Dbal\DbalMapper { protected $tableName = 'tbl_book'; @@ -37,7 +40,10 @@ If it is impossible to filter data by the repository layer API, you can write mo You can get a new query builder instance by calling the `builder()` method. An instance of the current database connection is available in `$connection` property. Always wrap the result to collection with `toCollection()` call. ```php -class BooksMapper extends Nextras\Orm\Mapper\Mapper +/** + * @extends DbalMapper + */ +class BooksMapper extends Nextras\Orm\Mapper\Dbal\DbalMapper { /** @return Nextras\Orm\Collection\ICollection */ public function getRandomBooksByBuilder(): Nextras\Orm\Collection\ICollection diff --git a/docs/repository.md b/docs/repository.md index a2c95b2f..3d20b790 100644 --- a/docs/repository.md +++ b/docs/repository.md @@ -16,6 +16,9 @@ Repository provides `findAll()` method, which returns `Nextras\Orm\Collection\IC Repository has to define a static method `getEntityClassNames()` that returns an array of entity names that the repository produce. Repository itself can contain user defined methods: ```php +/** + * @extends Repository + */ final class BooksRepository extends Repository { static function getEntityClassNames(): array @@ -46,13 +49,17 @@ Sometimes, it is needed to write pure SQL queries. SQL queries can be written on ```php /** * @method ICollection findBooksWithEvenId() + * @extends Repository */ final class BooksRepository extends Repository { // ... } -final class BooksMapper extends Mapper +/** + * @extends DbalMapper + */ +final class BooksMapper extends DbalMapper { /** @return ICollection */ public function findBooksWithEvenId(): ICollection