Skip to content

Commit

Permalink
[CLEANUP] Drop redundant property type annotations for mappers
Browse files Browse the repository at this point in the history
Also make some type annotations more specific.

Fixes #1014
  • Loading branch information
oliverklee committed Jun 26, 2022
1 parent 554bd91 commit 7fc789f
Show file tree
Hide file tree
Showing 16 changed files with 9 additions and 132 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
- Avoid crashes in `Collection` in PHP 8.1 (#946)
- Avoid invalid array accesses in the view helpers (#944)
- Move PHPCov to PHIVE (#943, #948)
- Improve the type annotations (#941, #942, #995, #1001, #1005)
- Improve the type annotations (#941, #942, #995, #1001, #1005, #1016)
- Make the usage of types more strict (#940)

## 4.1.6
Expand Down
4 changes: 2 additions & 2 deletions Classes/Mapper/AbstractDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ abstract class AbstractDataMapper
protected $relations = [];

/**
* @var array<int, string> the column names of additional string keys
* @var array<int, non-empty-string> the column names of additional string keys
*/
protected $additionalKeys = [];

/**
* The column names of an additional compound key.
* There can only be one compound key per data mapper.
*
* @var string[]
* @var non-empty-string[]
*/
protected $compoundKeyParts = [];

Expand Down
10 changes: 0 additions & 10 deletions Classes/Mapper/BackEndUserGroupMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,10 @@
*/
class BackEndUserGroupMapper extends AbstractDataMapper
{
/**
* @var non-empty-string the name of the database table for this mapper
*/
protected $tableName = 'be_groups';

/**
* @var class-string<BackEndUserGroup> the model class name for this mapper, must not be empty
*/
protected $modelClassName = BackEndUserGroup::class;

/**
* @var array<non-empty-string, class-string>
* the (possible) relations of the created models in the format DB column name => mapper name
*/
protected $relations = [
'subgroup' => BackEndUserGroupMapper::class,
];
Expand Down
13 changes: 0 additions & 13 deletions Classes/Mapper/BackEndUserMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,14 @@
*/
class BackEndUserMapper extends AbstractDataMapper
{
/**
* @var non-empty-string the name of the database table for this mapper
*/
protected $tableName = 'be_users';

/**
* @var class-string<BackEndUser> the model class name for this mapper, must not be empty
*/
protected $modelClassName = BackEndUser::class;

/**
* @var array<non-empty-string, class-string>
* the (possible) relations of the created models in the format DB column name => mapper name
*/
protected $relations = [
'usergroup' => BackEndUserGroupMapper::class,
];

/**
* @var array<int, string> the column names of additional string keys
*/
protected $additionalKeys = ['username'];

/**
Expand Down
9 changes: 0 additions & 9 deletions Classes/Mapper/CountryMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@
*/
class CountryMapper extends AbstractDataMapper
{
/**
* @var non-empty-string the name of the database table for this mapper
*/
protected $tableName = 'static_countries';

/**
* @var class-string<Country> the model class name for this mapper, must not be empty
*/
protected $modelClassName = Country::class;

/**
* @var array<int, string> the column names of additional string keys
*/
protected $additionalKeys = ['cn_iso_2', 'cn_iso_3'];

/**
Expand Down
11 changes: 0 additions & 11 deletions Classes/Mapper/CurrencyMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,17 @@
*/
class CurrencyMapper extends AbstractDataMapper
{
/**
* @var non-empty-string the name of the database table for this mapper
*/
protected $tableName = 'static_currencies';

/**
* @var class-string<Currency> the model class name for this mapper, must not be empty
*/
protected $modelClassName = Currency::class;

/**
* @var array<int, string> the column names of additional string keys
*/
protected $additionalKeys = ['cu_iso_3'];

/**
* Finds a language by its ISO 4217 alpha-3 code.
*
* @param non-empty-string $isoAlpha3Code the ISO 4217 alpha-3 code to find
*
* @return Currency the currency
*
* @throws NotFoundException if there is no record with the provided ISO 4217 alpha-3 code
*/
public function findByIsoAlpha3Code(string $isoAlpha3Code): Currency
Expand Down
9 changes: 0 additions & 9 deletions Classes/Mapper/FederalStateMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,10 @@
*/
class FederalStateMapper extends AbstractDataMapper
{
/**
* @var non-empty-string
*/
protected $tableName = 'static_country_zones';

/**
* @var class-string<FederalState>
*/
protected $modelClassName = FederalState::class;

/**
* @var string[] the column names of additional combined keys
*/
protected $compoundKeyParts = ['zn_country_iso_2', 'zn_code'];

/**
Expand Down
6 changes: 0 additions & 6 deletions Classes/Mapper/FrontEndUserGroupMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@
*/
class FrontEndUserGroupMapper extends AbstractDataMapper
{
/**
* @var non-empty-string the name of the database table for this mapper
*/
protected $tableName = 'fe_groups';

/**
* @var class-string<FrontEndUserGroup> the model class name for this mapper, must not be empty
*/
protected $modelClassName = FrontEndUserGroup::class;
}
13 changes: 0 additions & 13 deletions Classes/Mapper/FrontEndUserMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,14 @@
*/
class FrontEndUserMapper extends AbstractDataMapper
{
/**
* @var non-empty-string the name of the database table for this mapper
*/
protected $tableName = 'fe_users';

/**
* @var class-string<FrontEndUser> the model class name for this mapper, must not be empty
*/
protected $modelClassName = FrontEndUser::class;

/**
* @var array<non-empty-string, class-string>
* the (possible) relations of the created models in the format DB column name => mapper name
*/
protected $relations = [
'usergroup' => FrontEndUserGroupMapper::class,
];

/**
* @var array<int, string> the column names of additional string keys
*/
protected $additionalKeys = ['username'];

/**
Expand Down
9 changes: 0 additions & 9 deletions Classes/Mapper/LanguageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@
*/
class LanguageMapper extends AbstractDataMapper
{
/**
* @var non-empty-string the name of the database table for this mapper
*/
protected $tableName = 'static_languages';

/**
* @var class-string<Language> the model class name for this mapper, must not be empty
*/
protected $modelClassName = Language::class;

/**
* @var array<int, string> the column names of additional string keys
*/
protected $additionalKeys = ['lg_iso_2'];

/**
Expand Down
13 changes: 1 addition & 12 deletions Tests/Unit/Mapper/Fixtures/ColumnLessTestingMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,10 @@
*/
class ColumnLessTestingMapper extends AbstractDataMapper
{
/**
* @var non-empty-string the name of the database table for this mapper
*/
protected $tableName = 'tx_oelib_test';

/**
* @var non-empty-string a comma-separated list of DB column names to retrieve or "*" for all columns,
* must not be empty
*
* @phpstan-ignore-next-line We are explicitly testing for a contract violation here.
*/
// @phpstan-ignore-next-line We are explicitly testing for a contract violation here.
protected $columns = '';

/**
* @var class-string<TestingModel> the model class name for this mapper, must not be empty
*/
protected $modelClassName = TestingModel::class;
}
3 changes: 0 additions & 3 deletions Tests/Unit/Mapper/Fixtures/ModelLessTestingMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@
*/
class ModelLessTestingMapper extends AbstractDataMapper
{
/**
* @var non-empty-string the name of the database table for this mapper
*/
protected $tableName = 'tx_oelib_test';
}
3 changes: 0 additions & 3 deletions Tests/Unit/Mapper/Fixtures/TableLessTestingMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@
*/
class TableLessTestingMapper extends AbstractDataMapper
{
/**
* @var class-string<TestingModel> the model class name for this mapper, must not be empty
*/
protected $modelClassName = TestingModel::class;
}
10 changes: 0 additions & 10 deletions Tests/Unit/Mapper/Fixtures/TestingChildMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,10 @@
*/
class TestingChildMapper extends AbstractDataMapper
{
/**
* @var non-empty-string the name of the database table for this mapper
*/
protected $tableName = 'tx_oelib_testchild';

/**
* @var class-string<TestingChildModel> the model class name for this mapper, must not be empty
*/
protected $modelClassName = TestingChildModel::class;

/**
* @var array<non-empty-string, class-string>
* the (possible) relations of the created models in the format DB column name => mapper name
*/
protected $relations = [
'parent' => TestingMapper::class,
'tx_oelib_parent2' => TestingMapper::class,
Expand Down
16 changes: 0 additions & 16 deletions Tests/Unit/Mapper/Fixtures/TestingMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,10 @@
*/
class TestingMapper extends AbstractDataMapper
{
/**
* @var non-empty-string the name of the database table for this mapper
*/
protected $tableName = 'tx_oelib_test';

/**
* @var class-string<TestingModel> the model class name for this mapper, must not be empty
*/
protected $modelClassName = TestingModel::class;

/**
* @var array<non-empty-string, class-string>
* the (possible) relations of the created models in the format DB column name => mapper name
*/
protected $relations = [
'friend' => TestingMapper::class,
'owner' => FrontEndUserMapper::class,
Expand All @@ -43,14 +33,8 @@ class TestingMapper extends AbstractDataMapper
'bidirectional' => TestingMapper::class,
];

/**
* @var array<int, string> the column names of additional string keys
*/
protected $additionalKeys = ['title'];

/**
* @var string[] the column names of an additional compound key
*/
protected $compoundKeyParts = ['title', 'header'];

/**
Expand Down
10 changes: 5 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ parameters:
path: Classes/Mapper/AbstractDataMapper.php

-
message: "#^PHPDoc type array\\<non\\-empty\\-string, class\\-string\\> of property OliverKlee\\\\Oelib\\\\Mapper\\\\BackEndUserGroupMapper\\:\\:\\$relations is not the same as PHPDoc type array\\<non\\-empty\\-string, class\\-string\\<OliverKlee\\\\Oelib\\\\Mapper\\\\AbstractDataMapper\\<OliverKlee\\\\Oelib\\\\Model\\\\AbstractModel\\>\\>\\> of overridden property OliverKlee\\\\Oelib\\\\Mapper\\\\AbstractDataMapper\\<OliverKlee\\\\Oelib\\\\Model\\\\BackEndUserGroup\\>\\:\\:\\$relations\\.$#"
message: "#^Property OliverKlee\\\\Oelib\\\\Mapper\\\\BackEndUserGroupMapper\\:\\:\\$relations \\(array\\<non\\-empty\\-string, class\\-string\\<OliverKlee\\\\Oelib\\\\Mapper\\\\AbstractDataMapper\\<OliverKlee\\\\Oelib\\\\Model\\\\AbstractModel\\>\\>\\>\\) does not accept default value of type array\\{subgroup\\: 'OliverKlee\\\\\\\\Oelib\\\\\\\\Mapper\\\\\\\\BackEndUserGroupMapper'\\}\\.$#"
count: 1
path: Classes/Mapper/BackEndUserGroupMapper.php

-
message: "#^PHPDoc type array\\<non\\-empty\\-string, class\\-string\\> of property OliverKlee\\\\Oelib\\\\Mapper\\\\BackEndUserMapper\\:\\:\\$relations is not the same as PHPDoc type array\\<non\\-empty\\-string, class\\-string\\<OliverKlee\\\\Oelib\\\\Mapper\\\\AbstractDataMapper\\<OliverKlee\\\\Oelib\\\\Model\\\\AbstractModel\\>\\>\\> of overridden property OliverKlee\\\\Oelib\\\\Mapper\\\\AbstractDataMapper\\<OliverKlee\\\\Oelib\\\\Model\\\\BackEndUser\\>\\:\\:\\$relations\\.$#"
message: "#^Property OliverKlee\\\\Oelib\\\\Mapper\\\\BackEndUserMapper\\:\\:\\$relations \\(array\\<non\\-empty\\-string, class\\-string\\<OliverKlee\\\\Oelib\\\\Mapper\\\\AbstractDataMapper\\<OliverKlee\\\\Oelib\\\\Model\\\\AbstractModel\\>\\>\\>\\) does not accept default value of type array\\{usergroup\\: 'OliverKlee\\\\\\\\Oelib\\\\\\\\Mapper\\\\\\\\BackEndUserGroupMapper'\\}\\.$#"
count: 1
path: Classes/Mapper/BackEndUserMapper.php

-
message: "#^PHPDoc type array\\<non\\-empty\\-string, class\\-string\\> of property OliverKlee\\\\Oelib\\\\Mapper\\\\FrontEndUserMapper\\:\\:\\$relations is not the same as PHPDoc type array\\<non\\-empty\\-string, class\\-string\\<OliverKlee\\\\Oelib\\\\Mapper\\\\AbstractDataMapper\\<OliverKlee\\\\Oelib\\\\Model\\\\AbstractModel\\>\\>\\> of overridden property OliverKlee\\\\Oelib\\\\Mapper\\\\AbstractDataMapper\\<OliverKlee\\\\Oelib\\\\Model\\\\FrontEndUser\\>\\:\\:\\$relations\\.$#"
message: "#^Property OliverKlee\\\\Oelib\\\\Mapper\\\\FrontEndUserMapper\\:\\:\\$relations \\(array\\<non\\-empty\\-string, class\\-string\\<OliverKlee\\\\Oelib\\\\Mapper\\\\AbstractDataMapper\\<OliverKlee\\\\Oelib\\\\Model\\\\AbstractModel\\>\\>\\>\\) does not accept default value of type array\\{usergroup\\: 'OliverKlee\\\\\\\\Oelib\\\\\\\\Mapper\\\\\\\\FrontEndUserGroupMapper'\\}\\.$#"
count: 1
path: Classes/Mapper/FrontEndUserMapper.php

Expand Down Expand Up @@ -236,12 +236,12 @@ parameters:
path: Tests/Functional/ViewHelpers/PriceViewHelperTest.php

-
message: "#^PHPDoc type array\\<non\\-empty\\-string, class\\-string\\> of property OliverKlee\\\\Oelib\\\\Tests\\\\Unit\\\\Mapper\\\\Fixtures\\\\TestingChildMapper\\:\\:\\$relations is not the same as PHPDoc type array\\<non\\-empty\\-string, class\\-string\\<OliverKlee\\\\Oelib\\\\Mapper\\\\AbstractDataMapper\\<OliverKlee\\\\Oelib\\\\Model\\\\AbstractModel\\>\\>\\> of overridden property OliverKlee\\\\Oelib\\\\Mapper\\\\AbstractDataMapper\\<OliverKlee\\\\Oelib\\\\Tests\\\\Unit\\\\Model\\\\Fixtures\\\\TestingChildModel\\>\\:\\:\\$relations\\.$#"
message: "#^Property OliverKlee\\\\Oelib\\\\Tests\\\\Unit\\\\Mapper\\\\Fixtures\\\\TestingChildMapper\\:\\:\\$relations \\(array\\<non\\-empty\\-string, class\\-string\\<OliverKlee\\\\Oelib\\\\Mapper\\\\AbstractDataMapper\\<OliverKlee\\\\Oelib\\\\Model\\\\AbstractModel\\>\\>\\>\\) does not accept default value of type array\\{parent\\: 'OliverKlee\\\\\\\\Oelib\\\\\\\\Tests\\\\\\\\Unit\\\\\\\\Mapper\\\\\\\\Fixtures\\\\\\\\TestingMapper', tx_oelib_parent2\\: 'OliverKlee\\\\\\\\Oelib\\\\\\\\Tests\\\\\\\\Unit\\\\\\\\Mapper\\\\\\\\Fixtures\\\\\\\\TestingMapper', tx_oelib_parent3\\: 'OliverKlee\\\\\\\\Oelib\\\\\\\\Tests\\\\\\\\Unit\\\\\\\\Mapper\\\\\\\\Fixtures\\\\\\\\TestingMapper'\\}\\.$#"
count: 1
path: Tests/Unit/Mapper/Fixtures/TestingChildMapper.php

-
message: "#^PHPDoc type array\\<non\\-empty\\-string, class\\-string\\> of property OliverKlee\\\\Oelib\\\\Tests\\\\Unit\\\\Mapper\\\\Fixtures\\\\TestingMapper\\:\\:\\$relations is not the same as PHPDoc type array\\<non\\-empty\\-string, class\\-string\\<OliverKlee\\\\Oelib\\\\Mapper\\\\AbstractDataMapper\\<OliverKlee\\\\Oelib\\\\Model\\\\AbstractModel\\>\\>\\> of overridden property OliverKlee\\\\Oelib\\\\Mapper\\\\AbstractDataMapper\\<OliverKlee\\\\Oelib\\\\Tests\\\\Unit\\\\Model\\\\Fixtures\\\\TestingModel\\>\\:\\:\\$relations\\.$#"
message: "#^Property OliverKlee\\\\Oelib\\\\Tests\\\\Unit\\\\Mapper\\\\Fixtures\\\\TestingMapper\\:\\:\\$relations \\(array\\<non\\-empty\\-string, class\\-string\\<OliverKlee\\\\Oelib\\\\Mapper\\\\AbstractDataMapper\\<OliverKlee\\\\Oelib\\\\Model\\\\AbstractModel\\>\\>\\>\\) does not accept default value of type array\\{friend\\: 'OliverKlee\\\\\\\\Oelib\\\\\\\\Tests\\\\\\\\Unit\\\\\\\\Mapper\\\\\\\\Fixtures\\\\\\\\TestingMapper', owner\\: 'OliverKlee\\\\\\\\Oelib\\\\\\\\Mapper\\\\\\\\FrontEndUserMapper', children\\: 'OliverKlee\\\\\\\\Oelib\\\\\\\\Tests\\\\\\\\Unit\\\\\\\\Mapper\\\\\\\\Fixtures\\\\\\\\TestingMapper', related_records\\: 'OliverKlee\\\\\\\\Oelib\\\\\\\\Tests\\\\\\\\Unit\\\\\\\\Mapper\\\\\\\\Fixtures\\\\\\\\TestingMapper', composition\\: 'OliverKlee\\\\\\\\Oelib\\\\\\\\Tests\\\\\\\\Unit\\\\\\\\Mapper\\\\\\\\Fixtures\\\\\\\\TestingChildMapper', composition2\\: 'OliverKlee\\\\\\\\Oelib\\\\\\\\Tests\\\\\\\\Unit\\\\\\\\Mapper\\\\\\\\Fixtures\\\\\\\\TestingChildMapper', composition_without_sorting\\: 'OliverKlee\\\\\\\\Oelib\\\\\\\\Tests\\\\\\\\Unit\\\\\\\\Mapper\\\\\\\\Fixtures\\\\\\\\TestingChildMapper', bidirectional\\: 'OliverKlee\\\\\\\\Oelib\\\\\\\\Tests\\\\\\\\Unit\\\\\\\\Mapper\\\\\\\\Fixtures\\\\\\\\TestingMapper'\\}\\.$#"
count: 1
path: Tests/Unit/Mapper/Fixtures/TestingMapper.php

Expand Down

0 comments on commit 7fc789f

Please sign in to comment.