77 * OrmClassesGenerator is the main class that generates collection, model & record classes for any application using LeanOrm
88 *
99 * @author rotimi
10+ * @psalm-suppress UnusedClass
1011 */
1112class OrmClassesGenerator {
1213
@@ -68,6 +69,10 @@ public function __construct(protected array $config) {
6869 $ ds = DIRECTORY_SEPARATOR ;
6970 $ this ->defaultTemplatesDirectory = realpath (__DIR__ . "{$ ds }.. {$ ds }templates {$ ds }" );
7071
72+ /**
73+ * @psalm-suppress MixedAssignment
74+ * @psalm-suppress UnresolvableInclude
75+ */
7176 $ this ->defaultConfig = require __DIR__ . "{$ ds }.. {$ ds }sample-config.php " ;
7277
7378 if (!array_key_exists ('pdo ' , $ this ->config )) {
@@ -79,15 +84,28 @@ public function __construct(protected array $config) {
7984 throw new \Exception ('`pdo` entry in config is not an array & is also not a PDO instance! ' );
8085 }
8186
87+ /**
88+ * @psalm-suppress MixedArgument
89+ */
8290 $ this ->pdo = ($ this ->config ['pdo ' ] instanceof \PDO )
8391 ? $ this ->config ['pdo ' ]
8492 : new \PDO (...$ this ->config ['pdo ' ]);
8593
86- // fill config with defaults
94+ /**
95+ * Fill config with defaults
96+ *
97+ * @psalm-suppress MixedAssignment
98+ */
8799 foreach ($ this ->defaultConfig as $ key =>$ val ) {
88100
101+ /**
102+ * @psalm-suppress MixedArgument
103+ */
89104 if (!array_key_exists ($ key , $ this ->config )) {
90105
106+ /**
107+ * @psalm-suppress MixedArrayOffset
108+ */
91109 $ this ->config [$ key ] = $ val ;
92110 }
93111 }
@@ -116,11 +134,19 @@ public function __construct(protected array $config) {
116134 if (
117135 OtherUtils::isNonEmptyString ($ this ->config ['custom_templates_directory ' ])
118136 ) {
137+ /**
138+ * @psalm-suppress MixedArgument
139+ * @psalm-suppress PossiblyInvalidCast
140+ * @psalm-suppress PossiblyInvalidArgument
141+ */
119142 if (!FileIoUtils::isDir ($ this ->config ['custom_templates_directory ' ])) {
120143
121144 throw new \Exception ('`custom_templates_directory` entry in config is not a valid directory! ' );
122145 }
123146
147+ /**
148+ * @psalm-suppress MixedAssignment
149+ */
124150 $ this ->customTemplatesDirectory = $ this ->config ['custom_templates_directory ' ];
125151
126152 } elseif (
@@ -321,29 +347,55 @@ protected function generateClassFiles(string $tableOrViewName=''): ?int {
321347
322348 echo "\tGenerating class files for table ` {$ tableName }` .... " . PHP_EOL ;
323349
350+ /**
351+ * @psalm-suppress MixedAssignment
352+ * @psalm-suppress MixedFunctionCall
353+ */
324354 $ collectionOrModelNamePrefix =
325355 $ this ->config ['table_name_to_collection_and_model_class_prefix_transformer ' ]($ tableName );
326356
357+ /**
358+ * @psalm-suppress MixedAssignment
359+ * @psalm-suppress MixedFunctionCall
360+ */
327361 $ recordNamePrefix =
328362 $ this ->config ['table_name_to_record_class_prefix_transformer ' ]($ tableName );
329363
364+ /**
365+ * @psalm-suppress MixedOperand
366+ */
330367 $ collectionClassName = $ collectionOrModelNamePrefix . 'Collection.php ' ;
368+ /**
369+ * @psalm-suppress MixedOperand
370+ */
331371 $ modelClassName = $ collectionOrModelNamePrefix . 'Model.php ' ;
372+ /**
373+ * @psalm-suppress MixedOperand
374+ */
332375 $ fieldsFileName = $ collectionOrModelNamePrefix . 'FieldsMetadata.php ' ;
376+ /**
377+ * @psalm-suppress MixedOperand
378+ */
333379 $ recordClassName = $ recordNamePrefix . 'Record.php ' ;
334380
335381 echo "\t\tCollection class file name: ` {$ collectionClassName }` " . PHP_EOL ;
336382 echo "\t\tModel class file name: ` {$ modelClassName }` " . PHP_EOL ;
337383 echo "\t\tFields Metadata file name: ` {$ fieldsFileName }` " . PHP_EOL ;
338384 echo "\t\tRecord class file name: ` {$ recordClassName }` " . PHP_EOL ;
339385
386+ /**
387+ * @psalm-suppress MixedArgument
388+ */
340389 $ destinationDirectory =
341390 FileIoUtils::concatDirAndFileName ($ this ->destinationDirectory , $ collectionOrModelNamePrefix );
342391
343392 echo "\tClass files for table ` {$ tableName }` will be written to ` {$ destinationDirectory }` " . PHP_EOL ;
344393
345394 $ this ->filesToWrite [$ destinationDirectory ] = [];
346395
396+ /**
397+ * @psalm-suppress MixedArgument
398+ */
347399 $ this ->filesToWrite [$ destinationDirectory ][$ collectionClassName ]
348400 = $ this ->generateCollectionClassFile ($ tableName , $ collectionOrModelNamePrefix , $ recordNamePrefix );
349401
@@ -381,6 +433,9 @@ protected function generateCollectionClassFile(string $tableName, string $collec
381433 return strtr ($ this ->loadedCollectionTemplateFile , $ translations );
382434 }
383435
436+ /**
437+ * @psalm-suppress PossiblyUnusedParam
438+ */
384439 protected function generateFieldsMetadataFile (string $ tableName , string $ collectionOrModelNamePrefix , string $ recordNamePrefix ): string {
385440
386441 $ colDefs = SchemaUtils::fetchTableColsFromDB ($ tableName , $ this ->pdo );
@@ -406,6 +461,9 @@ protected function generateFieldsMetadataFile(string $tableName, string $collect
406461 return strtr ($ this ->loadedFieldsMetadataTemplateFile , $ translations );
407462 }
408463
464+ /**
465+ * @psalm-suppress MixedArgument
466+ */
409467 protected function generateModelClassFile (string $ tableName , string $ collectionOrModelNamePrefix , string $ recordNamePrefix ): string {
410468
411469 $ colDefs = SchemaUtils::fetchTableColsFromDB ($ tableName , $ this ->pdo );
@@ -466,6 +524,9 @@ protected function generateRecordClassFile(string $tableName, string $collection
466524 return strtr ($ this ->loadedRecordTemplateFile , $ translations );
467525 }
468526
527+ /**
528+ * @psalm-suppress RedundantCastGivenDocblockType
529+ */
469530 protected function generateColNamesAsPhpDocClassProperties (string $ tableName ): string {
470531
471532 $ colDefs = SchemaUtils::fetchTableColsFromDB ($ tableName , $ this ->pdo );
@@ -483,6 +544,7 @@ protected function generateColNamesAsPhpDocClassProperties(string $tableName): s
483544 }
484545
485546 $ props .= " * @property mixed \${$ col ->name } {$ coltype }" ;
547+
486548 if ($ col ->size !== null ) {
487549 $ props .= "( {$ col ->size }" ;
488550
@@ -512,12 +574,25 @@ protected function writeGeneratedClassFilesToDestinationDirectory(): ?int {
512574
513575 echo "Creating generated collection, model & record class files .... " . PHP_EOL ;
514576
577+ /**
578+ * @psalm-suppress MixedAssignment
579+ */
515580 foreach ($ this ->filesToWrite as $ modelDirectory => $ modelFilesInfo ) {
516581
582+ /**
583+ * @psalm-suppress MixedArgumentTypeCoercion
584+ */
517585 $ this ->mkdir ($ modelDirectory );
518586
587+ /**
588+ * @psalm-suppress MixedAssignment
589+ */
519590 foreach ($ modelFilesInfo as $ fileName => $ fileContents ) {
520591
592+ /**
593+ * @psalm-suppress MixedArgument
594+ * @psalm-suppress MixedArgumentTypeCoercion
595+ */
521596 $ destinationFile = FileIoUtils::concatDirAndFileName ($ modelDirectory , $ fileName );
522597
523598 if (FileIoUtils::isFile ($ destinationFile ) && !str_contains ($ destinationFile , 'FieldsMetadata ' )) {
@@ -529,6 +604,9 @@ protected function writeGeneratedClassFilesToDestinationDirectory(): ?int {
529604 echo ((FileIoUtils::isFile ($ destinationFile ))? "Updating " : "Creating " )
530605 . "` {$ destinationFile }`! " . PHP_EOL ;
531606
607+ /**
608+ * @psalm-suppress MixedArgument
609+ */
532610 FileIoUtils::put ($ destinationFile , $ fileContents );
533611 }
534612
@@ -582,8 +660,14 @@ protected function loadTableAndViewNames(): ?int {
582660
583661 sort ($ tableNames );
584662
663+ /**
664+ * @psalm-suppress MixedAssignment
665+ */
585666 foreach ($ tableNames as $ tableName ) {
586667
668+ /**
669+ * @psalm-suppress MixedArgument
670+ */
587671 if (
588672 (
589673 strtolower (SchemaUtils::getPdoDriverName ($ this ->pdo )) === 'sqlite '
@@ -600,6 +684,9 @@ protected function loadTableAndViewNames(): ?int {
600684 }
601685
602686 echo "Adding table ` {$ tableName }` " . PHP_EOL ;
687+ /**
688+ * @psalm-suppress MixedPropertyTypeCoercion
689+ */
603690 $ this ->tableAndViewNames [] = $ tableName ;
604691
605692 } // foreach($tableNames as $tableName)
0 commit comments