Skip to content

Commit

Permalink
added table map psalm type
Browse files Browse the repository at this point in the history
  • Loading branch information
mringler committed Nov 2, 2022
1 parent 7c3f30c commit de639e5
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/Propel/Runtime/Map/DatabaseMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
* @author Hans Lellelid <[email protected]> (Propel)
* @author John D. McNally <[email protected]> (Torque)
* @author Daniel Rall <[email protected]> (Torque)
*
* @psalm-type \Propel\Runtime\Map\MapType = 'tablesByName' | 'tablesByPhpName'
* @psalm-type \Propel\Runtime\Map\TableMapDump array<\Propel\Runtime\Map\MapType, array<string, class-string<\Propel\Runtime\Map\TableMap>>>
*/
class DatabaseMap
{
Expand All @@ -38,14 +41,14 @@ class DatabaseMap
/**
* Tables in the database, using table name as key
*
* @var array<\Propel\Runtime\Map\TableMap|class-string<\Propel\Runtime\Map\TableMap>>
* @var array<string, \Propel\Runtime\Map\TableMap|class-string<\Propel\Runtime\Map\TableMap>>
*/
protected $tables = [];

/**
* Tables in the database, using table phpName as key
*
* @var array<\Propel\Runtime\Map\TableMap|class-string<\Propel\Runtime\Map\TableMap>>
* @var array<string, \Propel\Runtime\Map\TableMap|class-string<\Propel\Runtime\Map\TableMap>>
*/
protected $tablesByPhpName = [];

Expand Down Expand Up @@ -121,7 +124,7 @@ protected function addTableByPhpName(?string $phpName, $tableOrClassMap): void
/**
* Add a new table to the database, using the tablemap class name.
*
* @param string $tableMapClass The name of the table map to add
* @param class-string<\Propel\Runtime\Map\TableMap> $tableMapClass The name of the table map to add
*
* @return \Propel\Runtime\Map\TableMap The TableMap object
*/
Expand All @@ -137,23 +140,26 @@ public function addTableFromMapClass(string $tableMapClass): TableMap
/**
* Dump table maps. Used during configuration generation.
*
* @return array A dump that can be loaded again with {@link DatabaseMap::loadMapsFromDump()}
* @return \Propel\Runtime\Map\TableMapDump A dump that can be loaded again with {@link DatabaseMap::loadMapsFromDump()}
*/
public function dumpMaps(): array
{
/**
* @param $tableMap class-string<\Propel\Runtime\Map\TableMap>|\Propel\Runtime\Map\TableMap
* @return class-string<\Propel\Runtime\Map\TableMap>
*/
$toClassString = fn ($tableMap) => is_string($tableMap) ? $tableMap : get_class($tableMap);
$maps = [

return [
'tablesByName' => array_map($toClassString, $this->tables),
'tablesByPhpName' => array_map($toClassString, $this->tablesByPhpName),
];

return $maps;
}

/**
* Load internal table maps from dump. Used during Propel initialization.
*
* @param $mapsDump Table map dump as created by {@link DatabaseMap::dumpMaps()}
* @param \Propel\Runtime\Map\TableMapDump|array $mapsDump Table map dump as created by {@link DatabaseMap::dumpMaps()}
*
* @return void
*/
Expand Down Expand Up @@ -208,7 +214,7 @@ public function registerTableMapClassByName(string $tableName, ?string $tablePhp
* Registers a list of table map classes (by qualified name) as table maps
* belonging to this database.
*
* @param array<class-string> $tableMapClasses
* @param array<class-string<\Propel\Runtime\Map\TableMap>> $tableMapClasses
*
* @return void
*/
Expand Down

0 comments on commit de639e5

Please sign in to comment.