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 |
||
| 47 | class EntityGenerator |
||
| 48 | { |
||
| 49 | /** |
||
| 50 | * Specifies class fields should be protected. |
||
| 51 | */ |
||
| 52 | const FIELD_VISIBLE_PROTECTED = 'protected'; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Specifies class fields should be private. |
||
| 56 | */ |
||
| 57 | const FIELD_VISIBLE_PRIVATE = 'private'; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var bool |
||
| 61 | */ |
||
| 62 | protected $backupExisting = true; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * The extension to use for written php files. |
||
| 66 | * |
||
| 67 | * @var string |
||
| 68 | */ |
||
| 69 | protected $extension = '.php'; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Whether or not the current ClassMetadataInfo instance is new or old. |
||
| 73 | * |
||
| 74 | * @var boolean |
||
| 75 | */ |
||
| 76 | protected $isNew = true; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @var array |
||
| 80 | */ |
||
| 81 | protected $staticReflection = array(); |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Number of spaces to use for indention in generated code. |
||
| 85 | */ |
||
| 86 | protected $numSpaces = 4; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * The actual spaces to use for indention. |
||
| 90 | * |
||
| 91 | * @var string |
||
| 92 | */ |
||
| 93 | protected $spaces = ' '; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * The class all generated entities should extend. |
||
| 97 | * |
||
| 98 | * @var string |
||
| 99 | */ |
||
| 100 | protected $classToExtend; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Whether or not to generation annotations. |
||
| 104 | * |
||
| 105 | * @var boolean |
||
| 106 | */ |
||
| 107 | protected $generateAnnotations = false; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @var string |
||
| 111 | */ |
||
| 112 | protected $annotationsPrefix = ''; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Whether or not to generate sub methods. |
||
| 116 | * |
||
| 117 | * @var boolean |
||
| 118 | */ |
||
| 119 | protected $generateEntityStubMethods = false; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Whether or not to update the entity class if it exists already. |
||
| 123 | * |
||
| 124 | * @var boolean |
||
| 125 | */ |
||
| 126 | protected $updateEntityIfExists = false; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Whether or not to re-generate entity class if it exists already. |
||
| 130 | * |
||
| 131 | * @var boolean |
||
| 132 | */ |
||
| 133 | protected $regenerateEntityIfExists = false; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Visibility of the field |
||
| 137 | * |
||
| 138 | * @var string |
||
| 139 | */ |
||
| 140 | protected $fieldVisibility = 'private'; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Whether or not to make generated embeddables immutable. |
||
| 144 | * |
||
| 145 | * @var boolean. |
||
| 146 | */ |
||
| 147 | protected $embeddablesImmutable = false; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Whether or not to add PHP strict types. |
||
| 151 | * |
||
| 152 | * @var boolean |
||
| 153 | */ |
||
| 154 | protected $strictTypes = false; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Whether or not to force type hinting for method result and scalar parameters. |
||
| 158 | * |
||
| 159 | * @var boolean |
||
| 160 | */ |
||
| 161 | protected $generateMethodsTypeHinting = false; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Hash-map for handle types. |
||
| 165 | * |
||
| 166 | * @var array |
||
| 167 | */ |
||
| 168 | protected $typeAlias = array( |
||
| 169 | Type::DATETIMETZ => '\DateTime', |
||
| 170 | Type::DATETIME => '\DateTime', |
||
| 171 | Type::DATE => '\DateTime', |
||
| 172 | Type::TIME => '\DateTime', |
||
| 173 | Type::OBJECT => '\stdClass', |
||
| 174 | Type::INTEGER => 'int', |
||
| 175 | Type::BIGINT => 'int', |
||
| 176 | Type::SMALLINT => 'int', |
||
| 177 | Type::TEXT => 'string', |
||
| 178 | Type::BLOB => 'string', |
||
| 179 | Type::DECIMAL => 'string', |
||
| 180 | Type::JSON_ARRAY => 'array', |
||
| 181 | Type::SIMPLE_ARRAY => 'array', |
||
| 182 | Type::BOOLEAN => 'bool', |
||
| 183 | ); |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Hash-map for handle strict types |
||
| 187 | * |
||
| 188 | * @var array |
||
| 189 | */ |
||
| 190 | protected $typeHintingAlias = array( |
||
| 191 | Type::TARRAY => 'array', |
||
| 192 | Type::SIMPLE_ARRAY => 'array', |
||
| 193 | Type::JSON_ARRAY => 'array', |
||
| 194 | Type::STRING => 'string', |
||
| 195 | Type::FLOAT => 'float', |
||
| 196 | Type::GUID => 'string', |
||
| 197 | ); |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Hash-map to handle generator types string. |
||
| 201 | * |
||
| 202 | * @var array |
||
| 203 | */ |
||
| 204 | protected static $generatorStrategyMap = array( |
||
| 205 | ClassMetadataInfo::GENERATOR_TYPE_AUTO => 'AUTO', |
||
| 206 | ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE => 'SEQUENCE', |
||
| 207 | ClassMetadataInfo::GENERATOR_TYPE_TABLE => 'TABLE', |
||
| 208 | ClassMetadataInfo::GENERATOR_TYPE_IDENTITY => 'IDENTITY', |
||
| 209 | ClassMetadataInfo::GENERATOR_TYPE_NONE => 'NONE', |
||
| 210 | ClassMetadataInfo::GENERATOR_TYPE_UUID => 'UUID', |
||
| 211 | ClassMetadataInfo::GENERATOR_TYPE_CUSTOM => 'CUSTOM' |
||
| 212 | ); |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Hash-map to handle the change tracking policy string. |
||
| 216 | * |
||
| 217 | * @var array |
||
| 218 | */ |
||
| 219 | protected static $changeTrackingPolicyMap = array( |
||
| 220 | ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT => 'DEFERRED_IMPLICIT', |
||
| 221 | ClassMetadataInfo::CHANGETRACKING_DEFERRED_EXPLICIT => 'DEFERRED_EXPLICIT', |
||
| 222 | ClassMetadataInfo::CHANGETRACKING_NOTIFY => 'NOTIFY', |
||
| 223 | ); |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Hash-map to handle the inheritance type string. |
||
| 227 | * |
||
| 228 | * @var array |
||
| 229 | */ |
||
| 230 | protected static $inheritanceTypeMap = array( |
||
| 231 | ClassMetadataInfo::INHERITANCE_TYPE_NONE => 'NONE', |
||
| 232 | ClassMetadataInfo::INHERITANCE_TYPE_JOINED => 'JOINED', |
||
| 233 | ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE => 'SINGLE_TABLE', |
||
| 234 | ClassMetadataInfo::INHERITANCE_TYPE_TABLE_PER_CLASS => 'TABLE_PER_CLASS', |
||
| 235 | ); |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @var string |
||
| 239 | */ |
||
| 240 | protected static $classTemplate = |
||
| 241 | '<?php |
||
| 242 | <strictTypes> |
||
| 243 | <namespace> |
||
| 244 | <useStatement> |
||
| 245 | <entityAnnotation> |
||
| 246 | <entityClassName> |
||
| 247 | { |
||
| 248 | <entityBody> |
||
| 249 | } |
||
| 250 | '; |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @var string |
||
| 254 | */ |
||
| 255 | protected static $getMethodTemplate = |
||
| 256 | '/** |
||
| 257 | * <description> |
||
| 258 | * |
||
| 259 | * @return <variableType> |
||
| 260 | */ |
||
| 261 | public function <methodName>() <methodTypeReturn> |
||
| 262 | { |
||
| 263 | <spaces>return $this-><fieldName>; |
||
| 264 | }'; |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @var string |
||
| 268 | */ |
||
| 269 | protected static $setMethodTemplate = |
||
| 270 | '/** |
||
| 271 | * <description> |
||
| 272 | * |
||
| 273 | * @param <variableType> $<variableName> |
||
| 274 | * |
||
| 275 | * @return <entity> |
||
| 276 | */ |
||
| 277 | public function <methodName>(<methodTypeHint>$<variableName><variableDefault>) <methodTypeReturn> |
||
| 278 | { |
||
| 279 | <spaces>$this-><fieldName> = $<variableName>; |
||
| 280 | |||
| 281 | <spaces>return $this; |
||
| 282 | }'; |
||
| 283 | |||
| 284 | /** |
||
| 285 | * @var string |
||
| 286 | */ |
||
| 287 | protected static $addMethodTemplate = |
||
| 288 | '/** |
||
| 289 | * <description> |
||
| 290 | * |
||
| 291 | * @param <variableType> $<variableName> |
||
| 292 | * |
||
| 293 | * @return <entity> |
||
| 294 | */ |
||
| 295 | public function <methodName>(<methodTypeHint>$<variableName>) <methodTypeReturn> |
||
| 296 | { |
||
| 297 | <spaces>$this-><fieldName>[] = $<variableName>; |
||
| 298 | |||
| 299 | <spaces>return $this; |
||
| 300 | }'; |
||
| 301 | |||
| 302 | /** |
||
| 303 | * @var string |
||
| 304 | */ |
||
| 305 | protected static $removeMethodTemplate = |
||
| 306 | '/** |
||
| 307 | * <description> |
||
| 308 | * |
||
| 309 | * @param <variableType> $<variableName> |
||
| 310 | * |
||
| 311 | * @return boolean TRUE if this collection contained the specified element, FALSE otherwise. |
||
| 312 | */ |
||
| 313 | public function <methodName>(<methodTypeHint>$<variableName>) <methodTypeReturn> |
||
| 314 | { |
||
| 315 | <spaces>return $this-><fieldName>->removeElement($<variableName>); |
||
| 316 | }'; |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @var string |
||
| 320 | */ |
||
| 321 | protected static $lifecycleCallbackMethodTemplate = |
||
| 322 | '/** |
||
| 323 | * @<name> |
||
| 324 | */ |
||
| 325 | public function <methodName>() |
||
| 326 | { |
||
| 327 | <spaces>// Add your code here |
||
| 328 | }'; |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @var string |
||
| 332 | */ |
||
| 333 | protected static $constructorMethodTemplate = |
||
| 334 | '/** |
||
| 335 | * Constructor |
||
| 336 | */ |
||
| 337 | public function __construct() |
||
| 338 | { |
||
| 339 | <spaces><collections> |
||
| 340 | } |
||
| 341 | '; |
||
| 342 | |||
| 343 | /** |
||
| 344 | * @var string |
||
| 345 | */ |
||
| 346 | protected static $embeddableConstructorMethodTemplate = |
||
| 347 | '/** |
||
| 348 | * Constructor |
||
| 349 | * |
||
| 350 | * <paramTags> |
||
| 351 | */ |
||
| 352 | public function __construct(<params>) |
||
| 353 | { |
||
| 354 | <spaces><fields> |
||
| 355 | } |
||
| 356 | '; |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Constructor. |
||
| 360 | */ |
||
| 361 | 50 | public function __construct() |
|
| 367 | |||
| 368 | /** |
||
| 369 | * Generates and writes entity classes for the given array of ClassMetadataInfo instances. |
||
| 370 | * |
||
| 371 | * @param array $metadatas |
||
| 372 | * @param string $outputDirectory |
||
| 373 | * |
||
| 374 | * @return void |
||
| 375 | */ |
||
| 376 | public function generate(array $metadatas, $outputDirectory) |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Generates and writes entity class to disk for the given ClassMetadataInfo instance. |
||
| 385 | * |
||
| 386 | * @param ClassMetadataInfo $metadata |
||
| 387 | * @param string $outputDirectory |
||
| 388 | * |
||
| 389 | * @return void |
||
| 390 | * |
||
| 391 | * @throws \RuntimeException |
||
| 392 | */ |
||
| 393 | 40 | public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory) |
|
| 426 | |||
| 427 | /** |
||
| 428 | * Generates a PHP5 Doctrine 2 entity class from the given ClassMetadataInfo instance. |
||
| 429 | * |
||
| 430 | * @param ClassMetadataInfo $metadata |
||
| 431 | * |
||
| 432 | * @return string |
||
| 433 | */ |
||
| 434 | 40 | public function generateEntityClass(ClassMetadataInfo $metadata) |
|
| 458 | |||
| 459 | /** |
||
| 460 | * Generates the updated code for the given ClassMetadataInfo and entity at path. |
||
| 461 | * |
||
| 462 | * @param ClassMetadataInfo $metadata |
||
| 463 | * @param string $path |
||
| 464 | * |
||
| 465 | * @return string |
||
| 466 | */ |
||
| 467 | 3 | public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path) |
|
| 477 | |||
| 478 | /** |
||
| 479 | * Sets the number of spaces the exported class should have. |
||
| 480 | * |
||
| 481 | * @param integer $numSpaces |
||
| 482 | * |
||
| 483 | * @return void |
||
| 484 | */ |
||
| 485 | public function setNumSpaces($numSpaces) |
||
| 490 | |||
| 491 | /** |
||
| 492 | * Sets the extension to use when writing php files to disk. |
||
| 493 | * |
||
| 494 | * @param string $extension |
||
| 495 | * |
||
| 496 | * @return void |
||
| 497 | */ |
||
| 498 | public function setExtension($extension) |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Sets the name of the class the generated classes should extend from. |
||
| 505 | * |
||
| 506 | * @param string $classToExtend |
||
| 507 | * |
||
| 508 | * @return void |
||
| 509 | */ |
||
| 510 | 1 | public function setClassToExtend($classToExtend) |
|
| 514 | |||
| 515 | /** |
||
| 516 | * Sets whether or not to generate annotations for the entity. |
||
| 517 | * |
||
| 518 | * @param bool $bool |
||
| 519 | * |
||
| 520 | * @return void |
||
| 521 | */ |
||
| 522 | 49 | public function setGenerateAnnotations($bool) |
|
| 526 | |||
| 527 | /** |
||
| 528 | * Sets the class fields visibility for the entity (can either be private or protected). |
||
| 529 | * |
||
| 530 | * @param bool $visibility |
||
| 531 | * |
||
| 532 | * @return void |
||
| 533 | * |
||
| 534 | * @throws \InvalidArgumentException |
||
| 535 | */ |
||
| 536 | 48 | public function setFieldVisibility($visibility) |
|
| 544 | |||
| 545 | /** |
||
| 546 | * Sets whether or not to generate immutable embeddables. |
||
| 547 | * |
||
| 548 | * @param boolean $embeddablesImmutable |
||
| 549 | */ |
||
| 550 | 1 | public function setEmbeddablesImmutable($embeddablesImmutable) |
|
| 554 | |||
| 555 | /** |
||
| 556 | * Sets an annotation prefix. |
||
| 557 | * |
||
| 558 | * @param string $prefix |
||
| 559 | * |
||
| 560 | * @return void |
||
| 561 | */ |
||
| 562 | 49 | public function setAnnotationPrefix($prefix) |
|
| 566 | |||
| 567 | /** |
||
| 568 | * Sets whether or not to try and update the entity if it already exists. |
||
| 569 | * |
||
| 570 | * @param bool $bool |
||
| 571 | * |
||
| 572 | * @return void |
||
| 573 | */ |
||
| 574 | 49 | public function setUpdateEntityIfExists($bool) |
|
| 578 | |||
| 579 | /** |
||
| 580 | * Sets whether or not to regenerate the entity if it exists. |
||
| 581 | * |
||
| 582 | * @param bool $bool |
||
| 583 | * |
||
| 584 | * @return void |
||
| 585 | */ |
||
| 586 | 49 | public function setRegenerateEntityIfExists($bool) |
|
| 590 | |||
| 591 | /** |
||
| 592 | * Sets whether or not to generate stub methods for the entity. |
||
| 593 | * |
||
| 594 | * @param bool $bool |
||
| 595 | * |
||
| 596 | * @return void |
||
| 597 | */ |
||
| 598 | 49 | public function setGenerateStubMethods($bool) |
|
| 602 | |||
| 603 | /** |
||
| 604 | * Should an existing entity be backed up if it already exists? |
||
| 605 | * |
||
| 606 | * @param bool $bool |
||
| 607 | * |
||
| 608 | * @return void |
||
| 609 | */ |
||
| 610 | 1 | public function setBackupExisting($bool) |
|
| 614 | |||
| 615 | /** |
||
| 616 | * Set whether or not to add PHP strict types. |
||
| 617 | * |
||
| 618 | * @param bool $bool |
||
| 619 | * |
||
| 620 | * @return void |
||
| 621 | */ |
||
| 622 | 46 | public function setStrictTypes($bool) |
|
| 626 | |||
| 627 | /** |
||
| 628 | * Set whether or not to force type hinting for method result and scalar parameters. |
||
| 629 | * |
||
| 630 | * @param bool $bool |
||
| 631 | * |
||
| 632 | * @param void |
||
| 633 | */ |
||
| 634 | 46 | public function setGenerateMethodsTypeHinting($bool) |
|
| 638 | |||
| 639 | /** |
||
| 640 | * @param string $type |
||
| 641 | * |
||
| 642 | * @return string |
||
| 643 | */ |
||
| 644 | 40 | protected function getType($type) |
|
| 652 | |||
| 653 | /** |
||
| 654 | * @return string |
||
| 655 | */ |
||
| 656 | 40 | protected function generateEntityStrictTypes() |
|
| 664 | |||
| 665 | /** |
||
| 666 | * @param ClassMetadataInfo $metadata |
||
| 667 | * |
||
| 668 | * @return string |
||
| 669 | */ |
||
| 670 | 40 | protected function generateEntityNamespace(ClassMetadataInfo $metadata) |
|
| 676 | |||
| 677 | 40 | protected function generateEntityUse() |
|
| 685 | |||
| 686 | /** |
||
| 687 | * @param ClassMetadataInfo $metadata |
||
| 688 | * |
||
| 689 | * @return string |
||
| 690 | */ |
||
| 691 | 40 | protected function generateEntityClassName(ClassMetadataInfo $metadata) |
|
| 696 | |||
| 697 | /** |
||
| 698 | * @param ClassMetadataInfo $metadata |
||
| 699 | * |
||
| 700 | * @return string |
||
| 701 | */ |
||
| 702 | 41 | protected function generateEntityBody(ClassMetadataInfo $metadata) |
|
| 736 | |||
| 737 | /** |
||
| 738 | * @param ClassMetadataInfo $metadata |
||
| 739 | * |
||
| 740 | * @return string |
||
| 741 | */ |
||
| 742 | 41 | protected function generateEntityConstructor(ClassMetadataInfo $metadata) |
|
| 766 | |||
| 767 | /** |
||
| 768 | * @param ClassMetadataInfo $metadata |
||
| 769 | * |
||
| 770 | * @return string |
||
| 771 | */ |
||
| 772 | 1 | private function generateEmbeddableConstructor(ClassMetadataInfo $metadata) |
|
| 860 | |||
| 861 | /** |
||
| 862 | * @todo this won't work if there is a namespace in brackets and a class outside of it. |
||
| 863 | * |
||
| 864 | * @param string $src |
||
| 865 | * |
||
| 866 | * @return void |
||
| 867 | */ |
||
| 868 | 8 | protected function parseTokensInEntityFile($src) |
|
| 914 | |||
| 915 | /** |
||
| 916 | * @param string $property |
||
| 917 | * @param ClassMetadataInfo $metadata |
||
| 918 | * |
||
| 919 | * @return bool |
||
| 920 | */ |
||
| 921 | 40 | protected function hasProperty($property, ClassMetadataInfo $metadata) |
|
| 943 | |||
| 944 | /** |
||
| 945 | * @param string $method |
||
| 946 | * @param ClassMetadataInfo $metadata |
||
| 947 | * |
||
| 948 | * @return bool |
||
| 949 | */ |
||
| 950 | 41 | protected function hasMethod($method, ClassMetadataInfo $metadata) |
|
| 973 | |||
| 974 | /** |
||
| 975 | * @param ClassMetadataInfo $metadata |
||
| 976 | * |
||
| 977 | * @return array |
||
| 978 | */ |
||
| 979 | 41 | protected function getTraits(ClassMetadataInfo $metadata) |
|
| 999 | |||
| 1000 | /** |
||
| 1001 | * @param ClassMetadataInfo $metadata |
||
| 1002 | * |
||
| 1003 | * @return bool |
||
| 1004 | */ |
||
| 1005 | 40 | protected function hasNamespace(ClassMetadataInfo $metadata) |
|
| 1009 | |||
| 1010 | /** |
||
| 1011 | * @return bool |
||
| 1012 | */ |
||
| 1013 | 41 | protected function extendsClass() |
|
| 1017 | |||
| 1018 | /** |
||
| 1019 | * @return string |
||
| 1020 | */ |
||
| 1021 | 2 | protected function getClassToExtend() |
|
| 1025 | |||
| 1026 | /** |
||
| 1027 | * @return string |
||
| 1028 | */ |
||
| 1029 | 1 | protected function getClassToExtendName() |
|
| 1035 | |||
| 1036 | /** |
||
| 1037 | * @param ClassMetadataInfo $metadata |
||
| 1038 | * |
||
| 1039 | * @return string |
||
| 1040 | */ |
||
| 1041 | 41 | protected function getClassName(ClassMetadataInfo $metadata) |
|
| 1046 | |||
| 1047 | /** |
||
| 1048 | * @param ClassMetadataInfo $metadata |
||
| 1049 | * |
||
| 1050 | * @return string |
||
| 1051 | */ |
||
| 1052 | 40 | protected function getNamespace(ClassMetadataInfo $metadata) |
|
| 1056 | |||
| 1057 | /** |
||
| 1058 | * @param ClassMetadataInfo $metadata |
||
| 1059 | * |
||
| 1060 | * @return string |
||
| 1061 | */ |
||
| 1062 | 40 | protected function generateEntityDocBlock(ClassMetadataInfo $metadata) |
|
| 1094 | |||
| 1095 | /** |
||
| 1096 | * @param ClassMetadataInfo $metadata |
||
| 1097 | * |
||
| 1098 | * @return string |
||
| 1099 | */ |
||
| 1100 | 40 | protected function generateEntityAnnotation(ClassMetadataInfo $metadata) |
|
| 1114 | |||
| 1115 | /** |
||
| 1116 | * @param ClassMetadataInfo $metadata |
||
| 1117 | * |
||
| 1118 | * @return string |
||
| 1119 | */ |
||
| 1120 | 40 | protected function generateTableAnnotation($metadata) |
|
| 1152 | |||
| 1153 | /** |
||
| 1154 | * @param string $constraintName |
||
| 1155 | * @param array $constraints |
||
| 1156 | * |
||
| 1157 | * @return string |
||
| 1158 | */ |
||
| 1159 | 10 | protected function generateTableConstraints($constraintName, $constraints) |
|
| 1172 | |||
| 1173 | /** |
||
| 1174 | * @param ClassMetadataInfo $metadata |
||
| 1175 | * |
||
| 1176 | * @return string |
||
| 1177 | */ |
||
| 1178 | 40 | protected function generateInheritanceAnnotation($metadata) |
|
| 1184 | |||
| 1185 | /** |
||
| 1186 | * @param ClassMetadataInfo $metadata |
||
| 1187 | * |
||
| 1188 | * @return string |
||
| 1189 | */ |
||
| 1190 | 40 | protected function generateDiscriminatorColumnAnnotation($metadata) |
|
| 1201 | |||
| 1202 | /** |
||
| 1203 | * @param ClassMetadataInfo $metadata |
||
| 1204 | * |
||
| 1205 | * @return string |
||
| 1206 | */ |
||
| 1207 | 40 | protected function generateDiscriminatorMapAnnotation($metadata) |
|
| 1219 | |||
| 1220 | /** |
||
| 1221 | * @param ClassMetadataInfo $metadata |
||
| 1222 | * |
||
| 1223 | * @return string |
||
| 1224 | */ |
||
| 1225 | 40 | protected function generateEntityStubMethods(ClassMetadataInfo $metadata) |
|
| 1291 | |||
| 1292 | /** |
||
| 1293 | * @param array $associationMapping |
||
| 1294 | * |
||
| 1295 | * @return bool |
||
| 1296 | */ |
||
| 1297 | 12 | protected function isAssociationIsNullable($associationMapping) |
|
| 1318 | |||
| 1319 | /** |
||
| 1320 | * @param ClassMetadataInfo $metadata |
||
| 1321 | * |
||
| 1322 | * @return string |
||
| 1323 | */ |
||
| 1324 | 41 | protected function generateEntityLifecycleCallbackMethods(ClassMetadataInfo $metadata) |
|
| 1342 | |||
| 1343 | /** |
||
| 1344 | * @param ClassMetadataInfo $metadata |
||
| 1345 | * |
||
| 1346 | * @return string |
||
| 1347 | */ |
||
| 1348 | 41 | protected function generateEntityAssociationMappingProperties(ClassMetadataInfo $metadata) |
|
| 1364 | |||
| 1365 | /** |
||
| 1366 | * @param ClassMetadataInfo $metadata |
||
| 1367 | * |
||
| 1368 | * @return string |
||
| 1369 | */ |
||
| 1370 | 41 | protected function generateEntityFieldMappingProperties(ClassMetadataInfo $metadata) |
|
| 1392 | |||
| 1393 | /** |
||
| 1394 | * @param ClassMetadataInfo $metadata |
||
| 1395 | * |
||
| 1396 | * @return string |
||
| 1397 | */ |
||
| 1398 | 41 | protected function generateEntityEmbeddedProperties(ClassMetadataInfo $metadata) |
|
| 1413 | |||
| 1414 | /** |
||
| 1415 | * @param ClassMetadataInfo $metadata |
||
| 1416 | * @param string $type |
||
| 1417 | * @param string $fieldName |
||
| 1418 | * @param string|null $typeHint |
||
| 1419 | * @param string|null $defaultValue |
||
| 1420 | * |
||
| 1421 | * @return string |
||
| 1422 | */ |
||
| 1423 | 39 | protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null) |
|
| 1479 | |||
| 1480 | /** |
||
| 1481 | * @param string $name |
||
| 1482 | * @param string $methodName |
||
| 1483 | * @param ClassMetadataInfo $metadata |
||
| 1484 | * |
||
| 1485 | * @return string |
||
| 1486 | */ |
||
| 1487 | 11 | protected function generateLifecycleCallbackMethod($name, $methodName, $metadata) |
|
| 1507 | |||
| 1508 | /** |
||
| 1509 | * @param array $joinColumn |
||
| 1510 | * |
||
| 1511 | * @return string |
||
| 1512 | */ |
||
| 1513 | 12 | protected function generateJoinColumnAnnotation(array $joinColumn) |
|
| 1543 | |||
| 1544 | /** |
||
| 1545 | * @param array $associationMapping |
||
| 1546 | * @param ClassMetadataInfo $metadata |
||
| 1547 | * |
||
| 1548 | * @return string |
||
| 1549 | */ |
||
| 1550 | 12 | protected function generateAssociationMappingPropertyDocBlock(array $associationMapping, ClassMetadataInfo $metadata) |
|
| 1695 | |||
| 1696 | /** |
||
| 1697 | * @param array $fieldMapping |
||
| 1698 | * @param ClassMetadataInfo $metadata |
||
| 1699 | * |
||
| 1700 | * @return string |
||
| 1701 | */ |
||
| 1702 | 38 | protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, ClassMetadataInfo $metadata) |
|
| 1791 | |||
| 1792 | /** |
||
| 1793 | * @param array $embeddedClass |
||
| 1794 | * |
||
| 1795 | * @return string |
||
| 1796 | */ |
||
| 1797 | 8 | protected function generateEmbeddedPropertyDocBlock(array $embeddedClass) |
|
| 1820 | |||
| 1821 | /** |
||
| 1822 | * @param string $code |
||
| 1823 | * @param int $num |
||
| 1824 | * |
||
| 1825 | * @return string |
||
| 1826 | */ |
||
| 1827 | 40 | protected function prefixCodeWithSpaces($code, $num = 1) |
|
| 1839 | |||
| 1840 | /** |
||
| 1841 | * @param integer $type The inheritance type used by the class and its subclasses. |
||
| 1842 | * |
||
| 1843 | * @return string The literal string for the inheritance type. |
||
| 1844 | * |
||
| 1845 | * @throws \InvalidArgumentException When the inheritance type does not exist. |
||
| 1846 | */ |
||
| 1847 | 1 | protected function getInheritanceTypeString($type) |
|
| 1855 | |||
| 1856 | /** |
||
| 1857 | * @param integer $type The policy used for change-tracking for the mapped class. |
||
| 1858 | * |
||
| 1859 | * @return string The literal string for the change-tracking type. |
||
| 1860 | * |
||
| 1861 | * @throws \InvalidArgumentException When the change-tracking type does not exist. |
||
| 1862 | */ |
||
| 1863 | 1 | protected function getChangeTrackingPolicyString($type) |
|
| 1871 | |||
| 1872 | /** |
||
| 1873 | * @param integer $type The generator to use for the mapped class. |
||
| 1874 | * |
||
| 1875 | * @return string The literal string for the generator type. |
||
| 1876 | * |
||
| 1877 | * @throws \InvalidArgumentException When the generator type does not exist. |
||
| 1878 | */ |
||
| 1879 | 37 | protected function getIdGeneratorTypeString($type) |
|
| 1887 | |||
| 1888 | /** |
||
| 1889 | * Exports (nested) option elements. |
||
| 1890 | * |
||
| 1891 | * @param array $options |
||
| 1892 | * |
||
| 1893 | * @return string |
||
| 1894 | */ |
||
| 1895 | 1 | private function exportTableOptions(array $options) |
|
| 1909 | |||
| 1910 | /** |
||
| 1911 | * @param ClassMetadataInfo $metadata |
||
| 1912 | * @param string $type |
||
| 1913 | * @param string $fieldName |
||
| 1914 | * @param string $variableType |
||
| 1915 | * @return string |
||
| 1916 | */ |
||
| 1917 | 11 | private function getMethodReturnType(ClassMetadataInfo $metadata, $type, $fieldName, $variableType) |
|
| 1941 | } |
||
| 1942 |
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: