Complex classes like EntityGenerator often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EntityGenerator, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 48 | class EntityGenerator |
||
| 49 | { |
||
| 50 | /** |
||
| 51 | * Specifies class fields should be protected. |
||
| 52 | */ |
||
| 53 | const FIELD_VISIBLE_PROTECTED = 'protected'; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Specifies class fields should be private. |
||
| 57 | */ |
||
| 58 | const FIELD_VISIBLE_PRIVATE = 'private'; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var bool |
||
| 62 | */ |
||
| 63 | protected $backupExisting = true; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * The extension to use for written php files. |
||
| 67 | * |
||
| 68 | * @var string |
||
| 69 | */ |
||
| 70 | protected $extension = '.php'; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Whether or not the current ClassMetadataInfo instance is new or old. |
||
| 74 | * |
||
| 75 | * @var boolean |
||
| 76 | */ |
||
| 77 | protected $isNew = true; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var array |
||
| 81 | */ |
||
| 82 | protected $staticReflection = []; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Number of spaces to use for indention in generated code. |
||
| 86 | */ |
||
| 87 | protected $numSpaces = 4; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * The actual spaces to use for indention. |
||
| 91 | * |
||
| 92 | * @var string |
||
| 93 | */ |
||
| 94 | protected $spaces = ' '; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * The class all generated entities should extend. |
||
| 98 | * |
||
| 99 | * @var string |
||
| 100 | */ |
||
| 101 | protected $classToExtend; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Whether or not to generation annotations. |
||
| 105 | * |
||
| 106 | * @var boolean |
||
| 107 | */ |
||
| 108 | protected $generateAnnotations = false; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @var string |
||
| 112 | */ |
||
| 113 | protected $annotationsPrefix = ''; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Whether or not to generate sub methods. |
||
| 117 | * |
||
| 118 | * @var boolean |
||
| 119 | */ |
||
| 120 | protected $generateEntityStubMethods = false; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Whether or not to update the entity class if it exists already. |
||
| 124 | * |
||
| 125 | * @var boolean |
||
| 126 | */ |
||
| 127 | protected $updateEntityIfExists = false; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Whether or not to re-generate entity class if it exists already. |
||
| 131 | * |
||
| 132 | * @var boolean |
||
| 133 | */ |
||
| 134 | protected $regenerateEntityIfExists = false; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Visibility of the field |
||
| 138 | * |
||
| 139 | * @var string |
||
| 140 | */ |
||
| 141 | protected $fieldVisibility = 'private'; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Whether or not to make generated embeddables immutable. |
||
| 145 | * |
||
| 146 | * @var boolean. |
||
| 147 | */ |
||
| 148 | protected $embeddablesImmutable = false; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Hash-map for handle types. |
||
| 152 | * |
||
| 153 | * @var array |
||
| 154 | */ |
||
| 155 | protected $typeAlias = [ |
||
| 156 | Type::DATETIMETZ => '\DateTime', |
||
| 157 | Type::DATETIME => '\DateTime', |
||
| 158 | Type::DATE => '\DateTime', |
||
| 159 | Type::TIME => '\DateTime', |
||
| 160 | Type::OBJECT => '\stdClass', |
||
| 161 | Type::INTEGER => 'int', |
||
| 162 | Type::BIGINT => 'int', |
||
| 163 | Type::SMALLINT => 'int', |
||
| 164 | Type::TEXT => 'string', |
||
| 165 | Type::BLOB => 'string', |
||
| 166 | Type::DECIMAL => 'string', |
||
| 167 | Type::JSON_ARRAY => 'array', |
||
| 168 | Type::SIMPLE_ARRAY => 'array', |
||
| 169 | Type::BOOLEAN => 'bool', |
||
| 170 | ]; |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Hash-map to handle generator types string. |
||
| 174 | * |
||
| 175 | * @var array |
||
| 176 | */ |
||
| 177 | protected static $generatorStrategyMap = [ |
||
| 178 | ClassMetadataInfo::GENERATOR_TYPE_AUTO => 'AUTO', |
||
| 179 | ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE => 'SEQUENCE', |
||
| 180 | ClassMetadataInfo::GENERATOR_TYPE_TABLE => 'TABLE', |
||
| 181 | ClassMetadataInfo::GENERATOR_TYPE_IDENTITY => 'IDENTITY', |
||
| 182 | ClassMetadataInfo::GENERATOR_TYPE_NONE => 'NONE', |
||
| 183 | ClassMetadataInfo::GENERATOR_TYPE_UUID => 'UUID', |
||
| 184 | ClassMetadataInfo::GENERATOR_TYPE_CUSTOM => 'CUSTOM' |
||
| 185 | ]; |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Hash-map to handle the change tracking policy string. |
||
| 189 | * |
||
| 190 | * @var array |
||
| 191 | */ |
||
| 192 | protected static $changeTrackingPolicyMap = [ |
||
| 193 | ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT => 'DEFERRED_IMPLICIT', |
||
| 194 | ClassMetadataInfo::CHANGETRACKING_DEFERRED_EXPLICIT => 'DEFERRED_EXPLICIT', |
||
| 195 | ClassMetadataInfo::CHANGETRACKING_NOTIFY => 'NOTIFY', |
||
| 196 | ]; |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Hash-map to handle the inheritance type string. |
||
| 200 | * |
||
| 201 | * @var array |
||
| 202 | */ |
||
| 203 | protected static $inheritanceTypeMap = [ |
||
| 204 | ClassMetadataInfo::INHERITANCE_TYPE_NONE => 'NONE', |
||
| 205 | ClassMetadataInfo::INHERITANCE_TYPE_JOINED => 'JOINED', |
||
| 206 | ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE => 'SINGLE_TABLE', |
||
| 207 | ClassMetadataInfo::INHERITANCE_TYPE_TABLE_PER_CLASS => 'TABLE_PER_CLASS', |
||
| 208 | ]; |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @var string |
||
| 212 | */ |
||
| 213 | protected static $classTemplate = |
||
| 214 | '<?php |
||
| 215 | |||
| 216 | <namespace> |
||
| 217 | <useStatement> |
||
| 218 | <entityAnnotation> |
||
| 219 | <entityClassName> |
||
| 220 | { |
||
| 221 | <entityBody> |
||
| 222 | } |
||
| 223 | '; |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @var string |
||
| 227 | */ |
||
| 228 | protected static $getMethodTemplate = |
||
| 229 | '/** |
||
| 230 | * <description> |
||
| 231 | * |
||
| 232 | * @return <variableType> |
||
| 233 | */ |
||
| 234 | public function <methodName>() |
||
| 235 | { |
||
| 236 | <spaces>return $this-><fieldName>; |
||
| 237 | }'; |
||
| 238 | |||
| 239 | /** |
||
| 240 | * @var string |
||
| 241 | */ |
||
| 242 | protected static $setMethodTemplate = |
||
| 243 | '/** |
||
| 244 | * <description> |
||
| 245 | * |
||
| 246 | * @param <variableType> $<variableName> |
||
| 247 | * |
||
| 248 | * @return <entity> |
||
| 249 | */ |
||
| 250 | public function <methodName>(<methodTypeHint>$<variableName><variableDefault>) |
||
| 251 | { |
||
| 252 | <spaces>$this-><fieldName> = $<variableName>; |
||
| 253 | |||
| 254 | <spaces>return $this; |
||
| 255 | }'; |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @var string |
||
| 259 | */ |
||
| 260 | protected static $addMethodTemplate = |
||
| 261 | '/** |
||
| 262 | * <description> |
||
| 263 | * |
||
| 264 | * @param <variableType> $<variableName> |
||
| 265 | * |
||
| 266 | * @return <entity> |
||
| 267 | */ |
||
| 268 | public function <methodName>(<methodTypeHint>$<variableName>) |
||
| 269 | { |
||
| 270 | <spaces>$this-><fieldName>[] = $<variableName>; |
||
| 271 | |||
| 272 | <spaces>return $this; |
||
| 273 | }'; |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @var string |
||
| 277 | */ |
||
| 278 | protected static $removeMethodTemplate = |
||
| 279 | '/** |
||
| 280 | * <description> |
||
| 281 | * |
||
| 282 | * @param <variableType> $<variableName> |
||
| 283 | * |
||
| 284 | * @return boolean TRUE if this collection contained the specified element, FALSE otherwise. |
||
| 285 | */ |
||
| 286 | public function <methodName>(<methodTypeHint>$<variableName>) |
||
| 287 | { |
||
| 288 | <spaces>return $this-><fieldName>->removeElement($<variableName>); |
||
| 289 | }'; |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @var string |
||
| 293 | */ |
||
| 294 | protected static $lifecycleCallbackMethodTemplate = |
||
| 295 | '/** |
||
| 296 | * @<name> |
||
| 297 | */ |
||
| 298 | public function <methodName>() |
||
| 299 | { |
||
| 300 | <spaces>// Add your code here |
||
| 301 | }'; |
||
| 302 | |||
| 303 | /** |
||
| 304 | * @var string |
||
| 305 | */ |
||
| 306 | protected static $constructorMethodTemplate = |
||
| 307 | '/** |
||
| 308 | * Constructor |
||
| 309 | */ |
||
| 310 | public function __construct() |
||
| 311 | { |
||
| 312 | <spaces><collections> |
||
| 313 | } |
||
| 314 | '; |
||
| 315 | |||
| 316 | /** |
||
| 317 | * @var string |
||
| 318 | */ |
||
| 319 | protected static $embeddableConstructorMethodTemplate = |
||
| 320 | '/** |
||
| 321 | * Constructor |
||
| 322 | * |
||
| 323 | * <paramTags> |
||
| 324 | */ |
||
| 325 | public function __construct(<params>) |
||
| 326 | { |
||
| 327 | <spaces><fields> |
||
| 328 | } |
||
| 329 | '; |
||
| 330 | |||
| 331 | /** |
||
| 332 | * Constructor. |
||
| 333 | */ |
||
| 334 | 40 | public function __construct() |
|
| 340 | |||
| 341 | /** |
||
| 342 | * Generates and writes entity classes for the given array of ClassMetadataInfo instances. |
||
| 343 | * |
||
| 344 | * @param array $metadatas |
||
| 345 | * @param string $outputDirectory |
||
| 346 | * |
||
| 347 | * @return void |
||
| 348 | */ |
||
| 349 | public function generate(array $metadatas, $outputDirectory): void |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Generates and writes entity class to disk for the given ClassMetadataInfo instance. |
||
| 358 | * |
||
| 359 | * @param ClassMetadataInfo $metadata |
||
| 360 | * @param string $outputDirectory |
||
| 361 | * |
||
| 362 | * @return void |
||
| 363 | * |
||
| 364 | * @throws \RuntimeException |
||
| 365 | */ |
||
| 366 | 31 | public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory): void |
|
| 367 | { |
||
| 368 | 31 | $path = $outputDirectory . '/' . str_replace('\\', DIRECTORY_SEPARATOR, $metadata->name) . $this->extension; |
|
| 369 | 31 | $dir = dirname($path); |
|
| 370 | |||
| 371 | 31 | if ( ! is_dir($dir)) { |
|
| 372 | 2 | mkdir($dir, 0775, true); |
|
| 373 | } |
||
| 374 | |||
| 375 | 31 | $this->isNew = ! file_exists($path) || $this->regenerateEntityIfExists; |
|
| 376 | |||
| 377 | 31 | if ( ! $this->isNew) { |
|
| 378 | 3 | $this->parseTokensInEntityFile(file_get_contents($path)); |
|
| 379 | } else { |
||
| 380 | 30 | $this->staticReflection[$metadata->name] = ['properties' => [], 'methods' => []]; |
|
| 381 | } |
||
| 382 | |||
| 383 | 31 | if ($this->backupExisting && file_exists($path)) { |
|
| 384 | 3 | $backupPath = dirname($path) . DIRECTORY_SEPARATOR . basename($path) . "~"; |
|
| 385 | 3 | if (!copy($path, $backupPath)) { |
|
| 386 | throw new \RuntimeException("Attempt to backup overwritten entity file but copy operation failed."); |
||
| 387 | } |
||
| 388 | } |
||
| 389 | |||
| 390 | // If entity doesn't exist or we're re-generating the entities entirely |
||
| 391 | 31 | if ($this->isNew) { |
|
| 392 | 30 | file_put_contents($path, $this->generateEntityClass($metadata)); |
|
| 393 | // If entity exists and we're allowed to update the entity class |
||
| 394 | 3 | } elseif ($this->updateEntityIfExists) { |
|
| 395 | 3 | file_put_contents($path, $this->generateUpdatedEntityClass($metadata, $path)); |
|
| 396 | } |
||
| 397 | 31 | chmod($path, 0664); |
|
| 398 | 31 | } |
|
| 399 | |||
| 400 | /** |
||
| 401 | * Generates a PHP5 Doctrine 2 entity class from the given ClassMetadataInfo instance. |
||
| 402 | * |
||
| 403 | * @param ClassMetadataInfo $metadata |
||
| 404 | * |
||
| 405 | * @return string |
||
| 406 | */ |
||
| 407 | 31 | public function generateEntityClass(ClassMetadataInfo $metadata): string |
|
| 429 | |||
| 430 | /** |
||
| 431 | * Generates the updated code for the given ClassMetadataInfo and entity at path. |
||
| 432 | * |
||
| 433 | * @param ClassMetadataInfo $metadata |
||
| 434 | * @param string $path |
||
| 435 | * |
||
| 436 | * @return string |
||
| 437 | */ |
||
| 438 | 3 | public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path): string |
|
| 448 | |||
| 449 | /** |
||
| 450 | * Sets the number of spaces the exported class should have. |
||
| 451 | * |
||
| 452 | * @param integer $numSpaces |
||
| 453 | * |
||
| 454 | * @return void |
||
| 455 | */ |
||
| 456 | public function setNumSpaces($numSpaces): void |
||
| 461 | |||
| 462 | /** |
||
| 463 | * Sets the extension to use when writing php files to disk. |
||
| 464 | * |
||
| 465 | * @param string $extension |
||
| 466 | * |
||
| 467 | * @return void |
||
| 468 | */ |
||
| 469 | public function setExtension($extension): void |
||
| 473 | |||
| 474 | /** |
||
| 475 | * Sets the name of the class the generated classes should extend from. |
||
| 476 | * |
||
| 477 | * @param string $classToExtend |
||
| 478 | * |
||
| 479 | * @return void |
||
| 480 | */ |
||
| 481 | 1 | public function setClassToExtend($classToExtend): void |
|
| 485 | |||
| 486 | /** |
||
| 487 | * Sets whether or not to generate annotations for the entity. |
||
| 488 | * |
||
| 489 | * @param bool $bool |
||
| 490 | * |
||
| 491 | * @return void |
||
| 492 | */ |
||
| 493 | 40 | public function setGenerateAnnotations($bool): void |
|
| 497 | |||
| 498 | /** |
||
| 499 | * Sets the class fields visibility for the entity (can either be private or protected). |
||
| 500 | * |
||
| 501 | * @param bool $visibility |
||
| 502 | * |
||
| 503 | * @return void |
||
| 504 | * |
||
| 505 | * @throws \InvalidArgumentException |
||
| 506 | */ |
||
| 507 | 39 | public function setFieldVisibility($visibility): void |
|
| 515 | |||
| 516 | /** |
||
| 517 | * Sets whether or not to generate immutable embeddables. |
||
| 518 | * |
||
| 519 | * @param boolean $embeddablesImmutable |
||
| 520 | */ |
||
| 521 | 1 | public function setEmbeddablesImmutable($embeddablesImmutable): void |
|
| 525 | |||
| 526 | /** |
||
| 527 | * Sets an annotation prefix. |
||
| 528 | * |
||
| 529 | * @param string $prefix |
||
| 530 | * |
||
| 531 | * @return void |
||
| 532 | */ |
||
| 533 | 40 | public function setAnnotationPrefix($prefix): void |
|
| 537 | |||
| 538 | /** |
||
| 539 | * Sets whether or not to try and update the entity if it already exists. |
||
| 540 | * |
||
| 541 | * @param bool $bool |
||
| 542 | * |
||
| 543 | * @return void |
||
| 544 | */ |
||
| 545 | 40 | public function setUpdateEntityIfExists($bool): void |
|
| 549 | |||
| 550 | /** |
||
| 551 | * Sets whether or not to regenerate the entity if it exists. |
||
| 552 | * |
||
| 553 | * @param bool $bool |
||
| 554 | * |
||
| 555 | * @return void |
||
| 556 | */ |
||
| 557 | 40 | public function setRegenerateEntityIfExists($bool): void |
|
| 561 | |||
| 562 | /** |
||
| 563 | * Sets whether or not to generate stub methods for the entity. |
||
| 564 | * |
||
| 565 | * @param bool $bool |
||
| 566 | * |
||
| 567 | * @return void |
||
| 568 | */ |
||
| 569 | 40 | public function setGenerateStubMethods($bool): void |
|
| 573 | |||
| 574 | /** |
||
| 575 | * Should an existing entity be backed up if it already exists? |
||
| 576 | * |
||
| 577 | * @param bool $bool |
||
| 578 | * |
||
| 579 | * @return void |
||
| 580 | */ |
||
| 581 | 1 | public function setBackupExisting($bool): void |
|
| 585 | |||
| 586 | /** |
||
| 587 | * @param string $type |
||
| 588 | * |
||
| 589 | * @return string |
||
| 590 | */ |
||
| 591 | 31 | protected function getType($type): string |
|
| 599 | |||
| 600 | /** |
||
| 601 | * @param ClassMetadataInfo $metadata |
||
| 602 | * |
||
| 603 | * @return string |
||
| 604 | */ |
||
| 605 | 31 | protected function generateEntityNamespace(ClassMetadataInfo $metadata): ?string |
|
| 606 | { |
||
| 607 | 31 | if (!$this->hasNamespace($metadata)) { |
|
| 608 | 2 | return null; |
|
| 609 | } |
||
| 610 | |||
| 611 | 31 | return 'namespace ' . $this->getNamespace($metadata) .';'; |
|
| 612 | } |
||
| 613 | |||
| 614 | 31 | protected function generateEntityUse(): ?string |
|
| 615 | { |
||
| 616 | 31 | if (!$this->generateAnnotations) { |
|
| 617 | return null; |
||
| 618 | } |
||
| 619 | |||
| 620 | 31 | return "\n".'use Doctrine\ORM\Mapping as ORM;'."\n"; |
|
| 621 | } |
||
| 622 | |||
| 623 | /** |
||
| 624 | * @param ClassMetadataInfo $metadata |
||
| 625 | * |
||
| 626 | * @return string |
||
| 627 | */ |
||
| 628 | 31 | protected function generateEntityClassName(ClassMetadataInfo $metadata): string |
|
| 629 | { |
||
| 630 | 31 | return 'class ' . $this->getClassName($metadata) . |
|
| 631 | 31 | ($this->extendsClass() ? ' extends ' . $this->getClassToExtendName() : null); |
|
| 632 | } |
||
| 633 | |||
| 634 | /** |
||
| 635 | * @param ClassMetadataInfo $metadata |
||
| 636 | * |
||
| 637 | * @return string |
||
| 638 | */ |
||
| 639 | 32 | protected function generateEntityBody(ClassMetadataInfo $metadata): string |
|
| 640 | { |
||
| 641 | 32 | $fieldMappingProperties = $this->generateEntityFieldMappingProperties($metadata); |
|
| 642 | 32 | $embeddedProperties = $this->generateEntityEmbeddedProperties($metadata); |
|
| 643 | 32 | $associationMappingProperties = $this->generateEntityAssociationMappingProperties($metadata); |
|
| 644 | 32 | $stubMethods = $this->generateEntityStubMethods ? $this->generateEntityStubMethods($metadata) : null; |
|
| 645 | 32 | $lifecycleCallbackMethods = $this->generateEntityLifecycleCallbackMethods($metadata); |
|
| 646 | |||
| 647 | 32 | $code = []; |
|
| 648 | |||
| 649 | 32 | if ($fieldMappingProperties) { |
|
| 650 | 29 | $code[] = $fieldMappingProperties; |
|
| 651 | } |
||
| 652 | |||
| 653 | 32 | if ($embeddedProperties) { |
|
| 654 | 10 | $code[] = $embeddedProperties; |
|
| 655 | } |
||
| 656 | |||
| 657 | 32 | if ($associationMappingProperties) { |
|
| 658 | 11 | $code[] = $associationMappingProperties; |
|
| 659 | } |
||
| 660 | |||
| 661 | 32 | $code[] = $this->generateEntityConstructor($metadata); |
|
| 662 | |||
| 663 | 32 | if ($stubMethods) { |
|
|
|
|||
| 664 | 30 | $code[] = $stubMethods; |
|
| 665 | } |
||
| 666 | |||
| 667 | 32 | if ($lifecycleCallbackMethods) { |
|
| 668 | 10 | $code[] = $lifecycleCallbackMethods; |
|
| 669 | } |
||
| 670 | |||
| 671 | 32 | return implode("\n", $code); |
|
| 672 | } |
||
| 673 | |||
| 674 | /** |
||
| 675 | * @param ClassMetadataInfo $metadata |
||
| 676 | * |
||
| 677 | * @return string |
||
| 678 | */ |
||
| 679 | 32 | protected function generateEntityConstructor(ClassMetadataInfo $metadata): string |
|
| 680 | { |
||
| 681 | 32 | if ($this->hasMethod('__construct', $metadata)) { |
|
| 682 | 2 | return ''; |
|
| 683 | } |
||
| 684 | |||
| 685 | 32 | if ($metadata->isEmbeddedClass && $this->embeddablesImmutable) { |
|
| 686 | 1 | return $this->generateEmbeddableConstructor($metadata); |
|
| 687 | } |
||
| 688 | |||
| 689 | 31 | $collections = []; |
|
| 690 | |||
| 691 | 31 | foreach ($metadata->associationMappings as $mapping) { |
|
| 692 | 13 | if ($mapping['type'] & ClassMetadataInfo::TO_MANY) { |
|
| 693 | 13 | $collections[] = '$this->'.$mapping['fieldName'].' = new \Doctrine\Common\Collections\ArrayCollection();'; |
|
| 694 | } |
||
| 695 | } |
||
| 696 | |||
| 697 | 31 | if ($collections) { |
|
| 698 | 11 | return $this->prefixCodeWithSpaces(str_replace("<collections>", implode("\n".$this->spaces, $collections), static::$constructorMethodTemplate)); |
|
| 699 | } |
||
| 700 | |||
| 701 | 27 | return ''; |
|
| 702 | } |
||
| 703 | |||
| 704 | /** |
||
| 705 | * @param ClassMetadataInfo $metadata |
||
| 706 | * |
||
| 707 | * @return string |
||
| 708 | */ |
||
| 709 | 1 | private function generateEmbeddableConstructor(ClassMetadataInfo $metadata): string |
|
| 710 | { |
||
| 711 | 1 | $paramTypes = []; |
|
| 712 | 1 | $paramVariables = []; |
|
| 713 | 1 | $params = []; |
|
| 714 | 1 | $fields = []; |
|
| 715 | |||
| 716 | // Resort fields to put optional fields at the end of the method signature. |
||
| 717 | 1 | $requiredFields = []; |
|
| 718 | 1 | $optionalFields = []; |
|
| 719 | |||
| 720 | 1 | foreach ($metadata->fieldMappings as $fieldMapping) { |
|
| 721 | 1 | if (empty($fieldMapping['nullable'])) { |
|
| 722 | 1 | $requiredFields[] = $fieldMapping; |
|
| 723 | |||
| 724 | 1 | continue; |
|
| 725 | } |
||
| 726 | |||
| 727 | 1 | $optionalFields[] = $fieldMapping; |
|
| 728 | } |
||
| 729 | |||
| 730 | 1 | $fieldMappings = array_merge($requiredFields, $optionalFields); |
|
| 731 | |||
| 732 | 1 | foreach ($metadata->embeddedClasses as $fieldName => $embeddedClass) { |
|
| 733 | 1 | $paramType = '\\' . ltrim($embeddedClass['class'], '\\'); |
|
| 734 | 1 | $paramVariable = '$' . $fieldName; |
|
| 735 | |||
| 736 | 1 | $paramTypes[] = $paramType; |
|
| 737 | 1 | $paramVariables[] = $paramVariable; |
|
| 738 | 1 | $params[] = $paramType . ' ' . $paramVariable; |
|
| 739 | 1 | $fields[] = '$this->' . $fieldName . ' = ' . $paramVariable . ';'; |
|
| 740 | } |
||
| 741 | |||
| 742 | 1 | foreach ($fieldMappings as $fieldMapping) { |
|
| 743 | 1 | if (isset($fieldMapping['declaredField'], $metadata->embeddedClasses[$fieldMapping['declaredField']])) { |
|
| 744 | continue; |
||
| 745 | } |
||
| 746 | |||
| 747 | 1 | $paramTypes[] = $this->getType($fieldMapping['type']) . (!empty($fieldMapping['nullable']) ? '|null' : ''); |
|
| 748 | 1 | $param = '$' . $fieldMapping['fieldName']; |
|
| 749 | 1 | $paramVariables[] = $param; |
|
| 750 | |||
| 751 | 1 | if ($fieldMapping['type'] === 'datetime') { |
|
| 752 | 1 | $param = $this->getType($fieldMapping['type']) . ' ' . $param; |
|
| 753 | } |
||
| 754 | |||
| 755 | 1 | if (!empty($fieldMapping['nullable'])) { |
|
| 756 | 1 | $param .= ' = null'; |
|
| 757 | } |
||
| 758 | |||
| 759 | 1 | $params[] = $param; |
|
| 760 | |||
| 761 | 1 | $fields[] = '$this->' . $fieldMapping['fieldName'] . ' = $' . $fieldMapping['fieldName'] . ';'; |
|
| 762 | } |
||
| 763 | |||
| 764 | 1 | $maxParamTypeLength = max(array_map('strlen', $paramTypes)); |
|
| 765 | 1 | $paramTags = array_map( |
|
| 766 | 1 | function ($type, $variable) use ($maxParamTypeLength) { |
|
| 767 | 1 | return '@param ' . $type . str_repeat(' ', $maxParamTypeLength - strlen($type) + 1) . $variable; |
|
| 768 | 1 | }, |
|
| 769 | 1 | $paramTypes, |
|
| 770 | 1 | $paramVariables |
|
| 771 | ); |
||
| 772 | |||
| 773 | // Generate multi line constructor if the signature exceeds 120 characters. |
||
| 774 | 1 | if (array_sum(array_map('strlen', $params)) + count($params) * 2 + 29 > 120) { |
|
| 775 | 1 | $delimiter = "\n" . $this->spaces; |
|
| 776 | 1 | $params = $delimiter . implode(',' . $delimiter, $params) . "\n"; |
|
| 777 | } else { |
||
| 778 | 1 | $params = implode(', ', $params); |
|
| 779 | } |
||
| 780 | |||
| 781 | $replacements = [ |
||
| 782 | 1 | '<paramTags>' => implode("\n * ", $paramTags), |
|
| 783 | 1 | '<params>' => $params, |
|
| 784 | 1 | '<fields>' => implode("\n" . $this->spaces, $fields), |
|
| 785 | ]; |
||
| 786 | |||
| 787 | 1 | $constructor = str_replace( |
|
| 788 | 1 | array_keys($replacements), |
|
| 789 | 1 | array_values($replacements), |
|
| 790 | 1 | static::$embeddableConstructorMethodTemplate |
|
| 791 | ); |
||
| 792 | |||
| 793 | 1 | return $this->prefixCodeWithSpaces($constructor); |
|
| 794 | } |
||
| 795 | |||
| 796 | /** |
||
| 797 | * @todo this won't work if there is a namespace in brackets and a class outside of it. |
||
| 798 | * |
||
| 799 | * @param string $src |
||
| 800 | * |
||
| 801 | * @return void |
||
| 802 | */ |
||
| 803 | 8 | protected function parseTokensInEntityFile($src): void |
|
| 804 | { |
||
| 805 | 8 | $tokens = token_get_all($src); |
|
| 806 | 8 | $tokensCount = count($tokens); |
|
| 807 | 8 | $lastSeenNamespace = ''; |
|
| 808 | 8 | $lastSeenClass = false; |
|
| 809 | |||
| 810 | 8 | $inNamespace = false; |
|
| 811 | 8 | $inClass = false; |
|
| 812 | |||
| 813 | 8 | for ($i = 0; $i < $tokensCount; $i++) { |
|
| 814 | 8 | $token = $tokens[$i]; |
|
| 815 | 8 | if (in_array($token[0], [T_WHITESPACE, T_COMMENT, T_DOC_COMMENT], true)) { |
|
| 816 | 8 | continue; |
|
| 817 | } |
||
| 818 | |||
| 819 | 8 | if ($inNamespace) { |
|
| 820 | 8 | if (in_array($token[0], [T_NS_SEPARATOR, T_STRING], true)) { |
|
| 821 | 8 | $lastSeenNamespace .= $token[1]; |
|
| 822 | 8 | } elseif (is_string($token) && in_array($token, [';', '{'], true)) { |
|
| 823 | 8 | $inNamespace = false; |
|
| 824 | } |
||
| 825 | } |
||
| 826 | |||
| 827 | 8 | if ($inClass) { |
|
| 828 | 8 | $inClass = false; |
|
| 829 | 8 | $lastSeenClass = $lastSeenNamespace . ($lastSeenNamespace ? '\\' : '') . $token[1]; |
|
| 830 | 8 | $this->staticReflection[$lastSeenClass]['properties'] = []; |
|
| 831 | 8 | $this->staticReflection[$lastSeenClass]['methods'] = []; |
|
| 832 | } |
||
| 833 | |||
| 834 | 8 | if (T_NAMESPACE === $token[0]) { |
|
| 835 | 8 | $lastSeenNamespace = ''; |
|
| 836 | 8 | $inNamespace = true; |
|
| 837 | 8 | } elseif (T_CLASS === $token[0] && T_DOUBLE_COLON !== $tokens[$i-1][0]) { |
|
| 838 | 8 | $inClass = true; |
|
| 839 | 8 | } elseif (T_FUNCTION === $token[0]) { |
|
| 840 | 3 | if (T_STRING === $tokens[$i+2][0]) { |
|
| 841 | 3 | $this->staticReflection[$lastSeenClass]['methods'][] = strtolower($tokens[$i+2][1]); |
|
| 842 | } elseif ($tokens[$i+2] == '&' && T_STRING === $tokens[$i+3][0]) { |
||
| 843 | 3 | $this->staticReflection[$lastSeenClass]['methods'][] = strtolower($tokens[$i+3][1]); |
|
| 844 | } |
||
| 845 | 8 | } elseif (in_array($token[0], [T_VAR, T_PUBLIC, T_PRIVATE, T_PROTECTED], true) && T_FUNCTION !== $tokens[$i+2][0]) { |
|
| 846 | 4 | $this->staticReflection[$lastSeenClass]['properties'][] = substr($tokens[$i+2][1], 1); |
|
| 847 | } |
||
| 848 | } |
||
| 849 | 8 | } |
|
| 850 | |||
| 851 | /** |
||
| 852 | * @param string $property |
||
| 853 | * @param ClassMetadataInfo $metadata |
||
| 854 | * |
||
| 855 | * @return bool |
||
| 856 | */ |
||
| 857 | 31 | protected function hasProperty($property, ClassMetadataInfo $metadata): bool |
|
| 858 | { |
||
| 859 | 31 | if ($this->extendsClass() || (!$this->isNew && class_exists($metadata->name))) { |
|
| 860 | // don't generate property if its already on the base class. |
||
| 861 | 2 | $reflClass = new \ReflectionClass($this->getClassToExtend() ?: $metadata->name); |
|
| 862 | 2 | if ($reflClass->hasProperty($property)) { |
|
| 863 | 1 | return true; |
|
| 864 | } |
||
| 865 | } |
||
| 866 | |||
| 867 | // check traits for existing property |
||
| 868 | 30 | foreach ($this->getTraits($metadata) as $trait) { |
|
| 869 | 2 | if ($trait->hasProperty($property)) { |
|
| 870 | 2 | return true; |
|
| 871 | } |
||
| 872 | } |
||
| 873 | |||
| 874 | return ( |
||
| 875 | 30 | isset($this->staticReflection[$metadata->name]) && |
|
| 876 | 30 | in_array($property, $this->staticReflection[$metadata->name]['properties'], true) |
|
| 877 | ); |
||
| 878 | } |
||
| 879 | |||
| 880 | /** |
||
| 881 | * @param string $method |
||
| 882 | * @param ClassMetadataInfo $metadata |
||
| 883 | * |
||
| 884 | * @return bool |
||
| 885 | */ |
||
| 886 | 32 | protected function hasMethod($method, ClassMetadataInfo $metadata): bool |
|
| 887 | { |
||
| 888 | 32 | if ($this->extendsClass() || (!$this->isNew && class_exists($metadata->name))) { |
|
| 889 | // don't generate method if its already on the base class. |
||
| 890 | 2 | $reflClass = new \ReflectionClass($this->getClassToExtend() ?: $metadata->name); |
|
| 891 | |||
| 892 | 2 | if ($reflClass->hasMethod($method)) { |
|
| 893 | 1 | return true; |
|
| 894 | } |
||
| 895 | } |
||
| 896 | |||
| 897 | // check traits for existing method |
||
| 898 | 32 | foreach ($this->getTraits($metadata) as $trait) { |
|
| 899 | 2 | if ($trait->hasMethod($method)) { |
|
| 900 | 2 | return true; |
|
| 901 | } |
||
| 902 | } |
||
| 903 | |||
| 904 | return ( |
||
| 905 | 32 | isset($this->staticReflection[$metadata->name]) && |
|
| 906 | 32 | in_array(strtolower($method), $this->staticReflection[$metadata->name]['methods'], true) |
|
| 907 | ); |
||
| 908 | } |
||
| 909 | |||
| 910 | /** |
||
| 911 | * @param ClassMetadataInfo $metadata |
||
| 912 | * |
||
| 913 | * @return array |
||
| 914 | */ |
||
| 915 | 32 | protected function getTraits(ClassMetadataInfo $metadata): array |
|
| 916 | { |
||
| 917 | 32 | if (! ($metadata->reflClass !== null || class_exists($metadata->name))) { |
|
| 918 | 26 | return []; |
|
| 919 | } |
||
| 920 | |||
| 921 | 7 | $reflClass = $metadata->reflClass === null |
|
| 922 | 1 | ? new \ReflectionClass($metadata->name) |
|
| 923 | 7 | : $metadata->reflClass; |
|
| 924 | |||
| 925 | 7 | $traits = []; |
|
| 926 | |||
| 927 | 7 | while ($reflClass !== false) { |
|
| 928 | 7 | $traits = array_merge($traits, $reflClass->getTraits()); |
|
| 929 | |||
| 930 | 7 | $reflClass = $reflClass->getParentClass(); |
|
| 931 | } |
||
| 932 | |||
| 933 | 7 | return $traits; |
|
| 934 | } |
||
| 935 | |||
| 936 | /** |
||
| 937 | * @param ClassMetadataInfo $metadata |
||
| 938 | * |
||
| 939 | * @return bool |
||
| 940 | */ |
||
| 941 | 31 | protected function hasNamespace(ClassMetadataInfo $metadata): bool |
|
| 942 | { |
||
| 943 | 31 | return (bool) strpos($metadata->name, '\\'); |
|
| 944 | } |
||
| 945 | |||
| 946 | /** |
||
| 947 | * @return bool |
||
| 948 | */ |
||
| 949 | 32 | protected function extendsClass(): bool |
|
| 950 | { |
||
| 951 | 32 | return (bool) $this->classToExtend; |
|
| 952 | } |
||
| 953 | |||
| 954 | /** |
||
| 955 | * @return string |
||
| 956 | */ |
||
| 957 | 2 | protected function getClassToExtend(): ?string |
|
| 958 | { |
||
| 959 | 2 | return $this->classToExtend; |
|
| 960 | } |
||
| 961 | |||
| 962 | /** |
||
| 963 | * @return string |
||
| 964 | */ |
||
| 965 | 1 | protected function getClassToExtendName(): string |
|
| 966 | { |
||
| 967 | 1 | $refl = new \ReflectionClass($this->getClassToExtend()); |
|
| 968 | |||
| 969 | 1 | return '\\' . $refl->getName(); |
|
| 970 | } |
||
| 971 | |||
| 972 | /** |
||
| 973 | * @param ClassMetadataInfo $metadata |
||
| 974 | * |
||
| 975 | * @return string |
||
| 976 | */ |
||
| 977 | 32 | protected function getClassName(ClassMetadataInfo $metadata): string |
|
| 978 | { |
||
| 979 | 32 | return ($pos = strrpos($metadata->name, '\\')) |
|
| 980 | 32 | ? substr($metadata->name, $pos + 1, strlen($metadata->name)) : $metadata->name; |
|
| 981 | } |
||
| 982 | |||
| 983 | /** |
||
| 984 | * @param ClassMetadataInfo $metadata |
||
| 985 | * |
||
| 986 | * @return string |
||
| 987 | */ |
||
| 988 | 31 | protected function getNamespace(ClassMetadataInfo $metadata): string |
|
| 989 | { |
||
| 990 | 31 | return substr($metadata->name, 0, strrpos($metadata->name, '\\')); |
|
| 991 | } |
||
| 992 | |||
| 993 | /** |
||
| 994 | * @param ClassMetadataInfo $metadata |
||
| 995 | * |
||
| 996 | * @return string |
||
| 997 | */ |
||
| 998 | 31 | protected function generateEntityDocBlock(ClassMetadataInfo $metadata): string |
|
| 999 | { |
||
| 1000 | 31 | $lines = []; |
|
| 1001 | 31 | $lines[] = '/**'; |
|
| 1002 | 31 | $lines[] = ' * ' . $this->getClassName($metadata); |
|
| 1003 | |||
| 1004 | 31 | if ($this->generateAnnotations) { |
|
| 1005 | 31 | $lines[] = ' *'; |
|
| 1006 | |||
| 1007 | $methods = [ |
||
| 1008 | 31 | 'generateTableAnnotation', |
|
| 1009 | 'generateInheritanceAnnotation', |
||
| 1010 | 'generateDiscriminatorColumnAnnotation', |
||
| 1011 | 'generateDiscriminatorMapAnnotation', |
||
| 1012 | 'generateEntityAnnotation', |
||
| 1013 | 'generateEntityListenerAnnotation', |
||
| 1014 | ]; |
||
| 1015 | |||
| 1016 | 31 | foreach ($methods as $method) { |
|
| 1017 | 31 | if ($code = $this->$method($metadata)) { |
|
| 1018 | 31 | $lines[] = ' * ' . $code; |
|
| 1019 | } |
||
| 1020 | } |
||
| 1021 | |||
| 1022 | 31 | if (isset($metadata->lifecycleCallbacks) && $metadata->lifecycleCallbacks) { |
|
| 1023 | 10 | $lines[] = ' * @' . $this->annotationsPrefix . 'HasLifecycleCallbacks'; |
|
| 1024 | } |
||
| 1025 | } |
||
| 1026 | |||
| 1027 | 31 | $lines[] = ' */'; |
|
| 1028 | |||
| 1029 | 31 | return implode("\n", $lines); |
|
| 1030 | } |
||
| 1031 | |||
| 1032 | /** |
||
| 1033 | * @param ClassMetadataInfo $metadata |
||
| 1034 | * |
||
| 1035 | * @return string |
||
| 1036 | */ |
||
| 1037 | 31 | protected function generateEntityAnnotation(ClassMetadataInfo $metadata): string |
|
| 1051 | |||
| 1052 | /** |
||
| 1053 | * @param ClassMetadataInfo $metadata |
||
| 1054 | * |
||
| 1055 | * @return string |
||
| 1056 | */ |
||
| 1057 | 31 | protected function generateTableAnnotation(ClassMetadataInfo $metadata): string |
|
| 1089 | |||
| 1090 | /** |
||
| 1091 | * @param string $constraintName |
||
| 1092 | * @param array $constraints |
||
| 1093 | * |
||
| 1094 | * @return string |
||
| 1095 | */ |
||
| 1096 | 9 | protected function generateTableConstraints($constraintName, array $constraints): string |
|
| 1097 | { |
||
| 1098 | 9 | $annotations = []; |
|
| 1099 | 9 | foreach ($constraints as $name => $constraint) { |
|
| 1100 | 9 | $columns = []; |
|
| 1101 | 9 | foreach ($constraint['columns'] as $column) { |
|
| 1109 | |||
| 1110 | /** |
||
| 1111 | * @param ClassMetadataInfo $metadata |
||
| 1112 | * |
||
| 1113 | * @return string |
||
| 1114 | */ |
||
| 1115 | 31 | protected function generateInheritanceAnnotation(ClassMetadataInfo $metadata): ?string |
|
| 1123 | |||
| 1124 | /** |
||
| 1125 | * @param ClassMetadataInfo $metadata |
||
| 1126 | * |
||
| 1127 | * @return string |
||
| 1128 | */ |
||
| 1129 | 31 | protected function generateDiscriminatorColumnAnnotation(ClassMetadataInfo $metadata): ?string |
|
| 1142 | |||
| 1143 | /** |
||
| 1144 | * @param ClassMetadataInfo $metadata |
||
| 1145 | * |
||
| 1146 | * @return string |
||
| 1147 | */ |
||
| 1148 | 31 | protected function generateDiscriminatorMapAnnotation(ClassMetadataInfo $metadata): ?string |
|
| 1162 | |||
| 1163 | /** |
||
| 1164 | * @param ClassMetadataInfo $metadata |
||
| 1165 | * |
||
| 1166 | * @return string |
||
| 1167 | */ |
||
| 1168 | 31 | protected function generateEntityStubMethods(ClassMetadataInfo $metadata): string |
|
| 1233 | |||
| 1234 | /** |
||
| 1235 | * @param array $associationMapping |
||
| 1236 | * |
||
| 1237 | * @return bool |
||
| 1238 | */ |
||
| 1239 | 11 | protected function isAssociationIsNullable(array $associationMapping): bool |
|
| 1260 | |||
| 1261 | /** |
||
| 1262 | * @param ClassMetadataInfo $metadata |
||
| 1263 | * |
||
| 1264 | * @return string |
||
| 1265 | */ |
||
| 1266 | 32 | protected function generateEntityLifecycleCallbackMethods(ClassMetadataInfo $metadata): string |
|
| 1282 | |||
| 1283 | /** |
||
| 1284 | * @param ClassMetadataInfo $metadata |
||
| 1285 | * |
||
| 1286 | * @return string |
||
| 1287 | */ |
||
| 1288 | 32 | protected function generateEntityAssociationMappingProperties(ClassMetadataInfo $metadata): string |
|
| 1304 | |||
| 1305 | /** |
||
| 1306 | * @param ClassMetadataInfo $metadata |
||
| 1307 | * |
||
| 1308 | * @return string |
||
| 1309 | */ |
||
| 1310 | 32 | protected function generateEntityFieldMappingProperties(ClassMetadataInfo $metadata): string |
|
| 1332 | |||
| 1333 | /** |
||
| 1334 | * @param ClassMetadataInfo $metadata |
||
| 1335 | * |
||
| 1336 | * @return string |
||
| 1337 | */ |
||
| 1338 | 32 | protected function generateEntityEmbeddedProperties(ClassMetadataInfo $metadata): string |
|
| 1353 | |||
| 1354 | /** |
||
| 1355 | * @param ClassMetadataInfo $metadata |
||
| 1356 | * @param string $type |
||
| 1357 | * @param string $fieldName |
||
| 1358 | * @param string|null $typeHint |
||
| 1359 | * @param string|null $defaultValue |
||
| 1360 | * |
||
| 1361 | * @return string |
||
| 1362 | */ |
||
| 1363 | 30 | protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null): string |
|
| 1408 | |||
| 1409 | /** |
||
| 1410 | * @param string $name |
||
| 1411 | * @param string $methodName |
||
| 1412 | * @param ClassMetadataInfo $metadata |
||
| 1413 | * |
||
| 1414 | * @return string |
||
| 1415 | */ |
||
| 1416 | 10 | protected function generateLifecycleCallbackMethod($name, $methodName, ClassMetadataInfo $metadata): string |
|
| 1436 | |||
| 1437 | /** |
||
| 1438 | * @param array $joinColumn |
||
| 1439 | * |
||
| 1440 | * @return string |
||
| 1441 | */ |
||
| 1442 | 11 | protected function generateJoinColumnAnnotation(array $joinColumn): string |
|
| 1472 | |||
| 1473 | /** |
||
| 1474 | * @param array $associationMapping |
||
| 1475 | * @param ClassMetadataInfo $metadata |
||
| 1476 | * |
||
| 1477 | * @return string |
||
| 1478 | */ |
||
| 1479 | 11 | protected function generateAssociationMappingPropertyDocBlock(array $associationMapping, ClassMetadataInfo $metadata): string |
|
| 1624 | |||
| 1625 | /** |
||
| 1626 | * @param array $fieldMapping |
||
| 1627 | * @param ClassMetadataInfo $metadata |
||
| 1628 | * |
||
| 1629 | * @return string |
||
| 1630 | */ |
||
| 1631 | 29 | protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, ClassMetadataInfo $metadata): string |
|
| 1722 | |||
| 1723 | /** |
||
| 1724 | * @param array $embeddedClass |
||
| 1725 | * |
||
| 1726 | * @return string |
||
| 1727 | */ |
||
| 1728 | 10 | protected function generateEmbeddedPropertyDocBlock(array $embeddedClass): string |
|
| 1755 | |||
| 1756 | /** |
||
| 1757 | * @param ClassMetadataInfo $metadata |
||
| 1758 | * |
||
| 1759 | * @return string |
||
| 1760 | */ |
||
| 1761 | 31 | protected function generateEntityListenerAnnotation(ClassMetadataInfo $metadata): string |
|
| 1781 | |||
| 1782 | /** |
||
| 1783 | * @param string $code |
||
| 1784 | * @param int $num |
||
| 1785 | * |
||
| 1786 | * @return string |
||
| 1787 | */ |
||
| 1788 | 31 | protected function prefixCodeWithSpaces($code, $num = 1): string |
|
| 1800 | |||
| 1801 | /** |
||
| 1802 | * @param integer $type The inheritance type used by the class and its subclasses. |
||
| 1803 | * |
||
| 1804 | * @return string The literal string for the inheritance type. |
||
| 1805 | * |
||
| 1806 | * @throws \InvalidArgumentException When the inheritance type does not exist. |
||
| 1807 | */ |
||
| 1808 | 1 | protected function getInheritanceTypeString($type): string |
|
| 1816 | |||
| 1817 | /** |
||
| 1818 | * @param integer $type The policy used for change-tracking for the mapped class. |
||
| 1819 | * |
||
| 1820 | * @return string The literal string for the change-tracking type. |
||
| 1821 | * |
||
| 1822 | * @throws \InvalidArgumentException When the change-tracking type does not exist. |
||
| 1823 | */ |
||
| 1824 | 1 | protected function getChangeTrackingPolicyString($type): string |
|
| 1832 | |||
| 1833 | /** |
||
| 1834 | * @param integer $type The generator to use for the mapped class. |
||
| 1835 | * |
||
| 1836 | * @return string The literal string for the generator type. |
||
| 1837 | * |
||
| 1838 | * @throws \InvalidArgumentException When the generator type does not exist. |
||
| 1839 | */ |
||
| 1840 | 26 | protected function getIdGeneratorTypeString($type): string |
|
| 1848 | |||
| 1849 | /** |
||
| 1850 | * @param array $fieldMapping |
||
| 1851 | * |
||
| 1852 | * @return string|null |
||
| 1853 | */ |
||
| 1854 | 31 | private function nullableFieldExpression(array $fieldMapping): ?string |
|
| 1862 | |||
| 1863 | /** |
||
| 1864 | * Exports (nested) option elements. |
||
| 1865 | * |
||
| 1866 | * @param array $options |
||
| 1867 | * |
||
| 1868 | * @return string |
||
| 1869 | */ |
||
| 1870 | 1 | private function exportTableOptions(array $options): string |
|
| 1884 | } |
||
| 1885 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: