Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
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 | * Whether or not to add PHP strict types. |
||
| 152 | * |
||
| 153 | * @var boolean |
||
| 154 | */ |
||
| 155 | protected $strictTypes = false; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Whether or not to force type hinting for method result and scalar parameters. |
||
| 159 | * |
||
| 160 | * @var boolean |
||
| 161 | */ |
||
| 162 | protected $generateMethodsTypeHinting = false; |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Hash-map for handle types. |
||
| 166 | * |
||
| 167 | * @var array |
||
| 168 | */ |
||
| 169 | protected $typeAlias = [ |
||
| 170 | Type::DATETIMETZ => '\DateTime', |
||
| 171 | Type::DATETIME => '\DateTime', |
||
| 172 | Type::DATE => '\DateTime', |
||
| 173 | Type::TIME => '\DateTime', |
||
| 174 | Type::OBJECT => '\stdClass', |
||
| 175 | Type::INTEGER => 'int', |
||
| 176 | Type::BIGINT => 'int', |
||
| 177 | Type::SMALLINT => 'int', |
||
| 178 | Type::TEXT => 'string', |
||
| 179 | Type::BLOB => 'string', |
||
| 180 | Type::DECIMAL => 'string', |
||
| 181 | Type::JSON_ARRAY => 'array', |
||
| 182 | Type::SIMPLE_ARRAY => 'array', |
||
| 183 | Type::BOOLEAN => 'bool', |
||
| 184 | ]; |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Hash-map for handle strict types |
||
| 188 | * |
||
| 189 | * @var array |
||
| 190 | */ |
||
| 191 | protected $typeHintingAlias = array( |
||
| 192 | Type::TARRAY => 'array', |
||
| 193 | Type::SIMPLE_ARRAY => 'array', |
||
| 194 | Type::JSON_ARRAY => 'array', |
||
| 195 | Type::STRING => 'string', |
||
| 196 | Type::FLOAT => 'float', |
||
| 197 | Type::GUID => 'string', |
||
| 198 | ); |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Hash-map to handle generator types string. |
||
| 202 | * |
||
| 203 | * @var array |
||
| 204 | */ |
||
| 205 | protected static $generatorStrategyMap = [ |
||
| 206 | ClassMetadataInfo::GENERATOR_TYPE_AUTO => 'AUTO', |
||
| 207 | ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE => 'SEQUENCE', |
||
| 208 | ClassMetadataInfo::GENERATOR_TYPE_TABLE => 'TABLE', |
||
| 209 | ClassMetadataInfo::GENERATOR_TYPE_IDENTITY => 'IDENTITY', |
||
| 210 | ClassMetadataInfo::GENERATOR_TYPE_NONE => 'NONE', |
||
| 211 | ClassMetadataInfo::GENERATOR_TYPE_UUID => 'UUID', |
||
| 212 | ClassMetadataInfo::GENERATOR_TYPE_CUSTOM => 'CUSTOM' |
||
| 213 | ]; |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Hash-map to handle the change tracking policy string. |
||
| 217 | * |
||
| 218 | * @var array |
||
| 219 | */ |
||
| 220 | protected static $changeTrackingPolicyMap = [ |
||
| 221 | ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT => 'DEFERRED_IMPLICIT', |
||
| 222 | ClassMetadataInfo::CHANGETRACKING_DEFERRED_EXPLICIT => 'DEFERRED_EXPLICIT', |
||
| 223 | ClassMetadataInfo::CHANGETRACKING_NOTIFY => 'NOTIFY', |
||
| 224 | ]; |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Hash-map to handle the inheritance type string. |
||
| 228 | * |
||
| 229 | * @var array |
||
| 230 | */ |
||
| 231 | protected static $inheritanceTypeMap = [ |
||
| 232 | ClassMetadataInfo::INHERITANCE_TYPE_NONE => 'NONE', |
||
| 233 | ClassMetadataInfo::INHERITANCE_TYPE_JOINED => 'JOINED', |
||
| 234 | ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE => 'SINGLE_TABLE', |
||
| 235 | ClassMetadataInfo::INHERITANCE_TYPE_TABLE_PER_CLASS => 'TABLE_PER_CLASS', |
||
| 236 | ]; |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @var string |
||
| 240 | */ |
||
| 241 | protected static $classTemplate = |
||
| 242 | '<?php |
||
| 243 | <strictTypes> |
||
| 244 | <namespace> |
||
| 245 | <useStatement> |
||
| 246 | <entityAnnotation> |
||
| 247 | <entityClassName> |
||
| 248 | { |
||
| 249 | <entityBody> |
||
| 250 | } |
||
| 251 | '; |
||
| 252 | |||
| 253 | /** |
||
| 254 | * @var string |
||
| 255 | */ |
||
| 256 | protected static $getMethodTemplate = |
||
| 257 | '/** |
||
| 258 | * <description> |
||
| 259 | * |
||
| 260 | * @return <variableType> |
||
| 261 | */ |
||
| 262 | public function <methodName>() <methodTypeReturn> |
||
| 263 | { |
||
| 264 | <spaces>return $this-><fieldName>; |
||
| 265 | }'; |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @var string |
||
| 269 | */ |
||
| 270 | protected static $setMethodTemplate = |
||
| 271 | '/** |
||
| 272 | * <description> |
||
| 273 | * |
||
| 274 | * @param <variableType> $<variableName> |
||
| 275 | * |
||
| 276 | * @return <entity> |
||
| 277 | */ |
||
| 278 | public function <methodName>(<methodTypeHint>$<variableName><variableDefault>) <methodTypeReturn> |
||
| 279 | { |
||
| 280 | <spaces>$this-><fieldName> = $<variableName>; |
||
| 281 | |||
| 282 | <spaces>return $this; |
||
| 283 | }'; |
||
| 284 | |||
| 285 | /** |
||
| 286 | * @var string |
||
| 287 | */ |
||
| 288 | protected static $addMethodTemplate = |
||
| 289 | '/** |
||
| 290 | * <description> |
||
| 291 | * |
||
| 292 | * @param <variableType> $<variableName> |
||
| 293 | * |
||
| 294 | * @return <entity> |
||
| 295 | */ |
||
| 296 | public function <methodName>(<methodTypeHint>$<variableName>) <methodTypeReturn> |
||
| 297 | { |
||
| 298 | <spaces>$this-><fieldName>[] = $<variableName>; |
||
| 299 | |||
| 300 | <spaces>return $this; |
||
| 301 | }'; |
||
| 302 | |||
| 303 | /** |
||
| 304 | * @var string |
||
| 305 | */ |
||
| 306 | protected static $removeMethodTemplate = |
||
| 307 | '/** |
||
| 308 | * <description> |
||
| 309 | * |
||
| 310 | * @param <variableType> $<variableName> |
||
| 311 | * |
||
| 312 | * @return boolean TRUE if this collection contained the specified element, FALSE otherwise. |
||
| 313 | */ |
||
| 314 | public function <methodName>(<methodTypeHint>$<variableName>) <methodTypeReturn> |
||
| 315 | { |
||
| 316 | <spaces>return $this-><fieldName>->removeElement($<variableName>); |
||
| 317 | }'; |
||
| 318 | |||
| 319 | /** |
||
| 320 | * @var string |
||
| 321 | */ |
||
| 322 | protected static $lifecycleCallbackMethodTemplate = |
||
| 323 | '/** |
||
| 324 | * @<name> |
||
| 325 | */ |
||
| 326 | public function <methodName>() |
||
| 327 | { |
||
| 328 | <spaces>// Add your code here |
||
| 329 | }'; |
||
| 330 | |||
| 331 | /** |
||
| 332 | * @var string |
||
| 333 | */ |
||
| 334 | protected static $constructorMethodTemplate = |
||
| 335 | '/** |
||
| 336 | * Constructor |
||
| 337 | */ |
||
| 338 | public function __construct() |
||
| 339 | { |
||
| 340 | <spaces><collections> |
||
| 341 | } |
||
| 342 | '; |
||
| 343 | |||
| 344 | /** |
||
| 345 | * @var string |
||
| 346 | */ |
||
| 347 | protected static $embeddableConstructorMethodTemplate = |
||
| 348 | '/** |
||
| 349 | * Constructor |
||
| 350 | * |
||
| 351 | * <paramTags> |
||
| 352 | */ |
||
| 353 | public function __construct(<params>) |
||
| 354 | { |
||
| 355 | <spaces><fields> |
||
| 356 | } |
||
| 357 | '; |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Constructor. |
||
| 361 | */ |
||
| 362 | 51 | public function __construct() |
|
| 368 | |||
| 369 | /** |
||
| 370 | * Generates and writes entity classes for the given array of ClassMetadataInfo instances. |
||
| 371 | * |
||
| 372 | * @param array $metadatas |
||
| 373 | * @param string $outputDirectory |
||
| 374 | * |
||
| 375 | * @return void |
||
| 376 | */ |
||
| 377 | public function generate(array $metadatas, $outputDirectory) |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Generates and writes entity class to disk for the given ClassMetadataInfo instance. |
||
| 386 | * |
||
| 387 | * @param ClassMetadataInfo $metadata |
||
| 388 | * @param string $outputDirectory |
||
| 389 | * |
||
| 390 | * @return void |
||
| 391 | * |
||
| 392 | * @throws \RuntimeException |
||
| 393 | */ |
||
| 394 | 42 | public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory) |
|
| 427 | |||
| 428 | /** |
||
| 429 | * Generates a PHP5 Doctrine 2 entity class from the given ClassMetadataInfo instance. |
||
| 430 | * |
||
| 431 | * @param ClassMetadataInfo $metadata |
||
| 432 | * |
||
| 433 | * @return string |
||
| 434 | */ |
||
| 435 | 42 | public function generateEntityClass(ClassMetadataInfo $metadata) |
|
| 459 | |||
| 460 | /** |
||
| 461 | * Generates the updated code for the given ClassMetadataInfo and entity at path. |
||
| 462 | * |
||
| 463 | * @param ClassMetadataInfo $metadata |
||
| 464 | * @param string $path |
||
| 465 | * |
||
| 466 | * @return string |
||
| 467 | */ |
||
| 468 | 3 | public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path) |
|
| 478 | |||
| 479 | /** |
||
| 480 | * Sets the number of spaces the exported class should have. |
||
| 481 | * |
||
| 482 | * @param integer $numSpaces |
||
| 483 | * |
||
| 484 | * @return void |
||
| 485 | */ |
||
| 486 | public function setNumSpaces($numSpaces) |
||
| 491 | |||
| 492 | /** |
||
| 493 | * Sets the extension to use when writing php files to disk. |
||
| 494 | * |
||
| 495 | * @param string $extension |
||
| 496 | * |
||
| 497 | * @return void |
||
| 498 | */ |
||
| 499 | public function setExtension($extension) |
||
| 503 | |||
| 504 | /** |
||
| 505 | * Sets the name of the class the generated classes should extend from. |
||
| 506 | * |
||
| 507 | * @param string $classToExtend |
||
| 508 | * |
||
| 509 | * @return void |
||
| 510 | */ |
||
| 511 | 1 | public function setClassToExtend($classToExtend) |
|
| 515 | |||
| 516 | /** |
||
| 517 | * Sets whether or not to generate annotations for the entity. |
||
| 518 | * |
||
| 519 | * @param bool $bool |
||
| 520 | * |
||
| 521 | * @return void |
||
| 522 | */ |
||
| 523 | 51 | public function setGenerateAnnotations($bool) |
|
| 527 | |||
| 528 | /** |
||
| 529 | * Sets the class fields visibility for the entity (can either be private or protected). |
||
| 530 | * |
||
| 531 | * @param bool $visibility |
||
| 532 | * |
||
| 533 | * @return void |
||
| 534 | * |
||
| 535 | * @throws \InvalidArgumentException |
||
| 536 | */ |
||
| 537 | 50 | public function setFieldVisibility($visibility) |
|
| 545 | |||
| 546 | /** |
||
| 547 | * Sets whether or not to generate immutable embeddables. |
||
| 548 | * |
||
| 549 | * @param boolean $embeddablesImmutable |
||
| 550 | */ |
||
| 551 | 1 | public function setEmbeddablesImmutable($embeddablesImmutable) |
|
| 555 | |||
| 556 | /** |
||
| 557 | * Sets an annotation prefix. |
||
| 558 | * |
||
| 559 | * @param string $prefix |
||
| 560 | * |
||
| 561 | * @return void |
||
| 562 | */ |
||
| 563 | 51 | public function setAnnotationPrefix($prefix) |
|
| 567 | |||
| 568 | /** |
||
| 569 | * Sets whether or not to try and update the entity if it already exists. |
||
| 570 | * |
||
| 571 | * @param bool $bool |
||
| 572 | * |
||
| 573 | * @return void |
||
| 574 | */ |
||
| 575 | 51 | public function setUpdateEntityIfExists($bool) |
|
| 579 | |||
| 580 | /** |
||
| 581 | * Sets whether or not to regenerate the entity if it exists. |
||
| 582 | * |
||
| 583 | * @param bool $bool |
||
| 584 | * |
||
| 585 | * @return void |
||
| 586 | */ |
||
| 587 | 51 | public function setRegenerateEntityIfExists($bool) |
|
| 591 | |||
| 592 | /** |
||
| 593 | * Sets whether or not to generate stub methods for the entity. |
||
| 594 | * |
||
| 595 | * @param bool $bool |
||
| 596 | * |
||
| 597 | * @return void |
||
| 598 | */ |
||
| 599 | 51 | public function setGenerateStubMethods($bool) |
|
| 603 | |||
| 604 | /** |
||
| 605 | * Should an existing entity be backed up if it already exists? |
||
| 606 | * |
||
| 607 | * @param bool $bool |
||
| 608 | * |
||
| 609 | * @return void |
||
| 610 | */ |
||
| 611 | 1 | public function setBackupExisting($bool) |
|
| 615 | |||
| 616 | /** |
||
| 617 | * Set whether or not to add PHP strict types. |
||
| 618 | * |
||
| 619 | * @param bool $bool |
||
| 620 | * |
||
| 621 | * @return void |
||
| 622 | */ |
||
| 623 | 48 | public function setStrictTypes($bool) |
|
| 627 | |||
| 628 | /** |
||
| 629 | * Set whether or not to force type hinting for method result and scalar parameters. |
||
| 630 | * |
||
| 631 | * @param bool $bool |
||
| 632 | * |
||
| 633 | * @param void |
||
| 634 | */ |
||
| 635 | 48 | public function setGenerateMethodsTypeHinting($bool) |
|
| 639 | |||
| 640 | /** |
||
| 641 | * @param string $type |
||
| 642 | * |
||
| 643 | * @return string |
||
| 644 | */ |
||
| 645 | 42 | protected function getType($type) |
|
| 653 | |||
| 654 | /** |
||
| 655 | * @return string |
||
| 656 | */ |
||
| 657 | 42 | protected function generateEntityStrictTypes() |
|
| 665 | |||
| 666 | /** |
||
| 667 | * @param ClassMetadataInfo $metadata |
||
| 668 | * |
||
| 669 | * @return string |
||
| 670 | */ |
||
| 671 | 42 | protected function generateEntityNamespace(ClassMetadataInfo $metadata) |
|
| 679 | |||
| 680 | /** |
||
| 681 | * @return string |
||
| 682 | */ |
||
| 683 | 42 | protected function generateEntityUse() |
|
| 691 | |||
| 692 | /** |
||
| 693 | * @param ClassMetadataInfo $metadata |
||
| 694 | * |
||
| 695 | * @return string |
||
| 696 | */ |
||
| 697 | 42 | protected function generateEntityClassName(ClassMetadataInfo $metadata) |
|
| 702 | |||
| 703 | /** |
||
| 704 | * @param ClassMetadataInfo $metadata |
||
| 705 | * |
||
| 706 | * @return string |
||
| 707 | */ |
||
| 708 | 43 | protected function generateEntityBody(ClassMetadataInfo $metadata) |
|
| 742 | |||
| 743 | /** |
||
| 744 | * @param ClassMetadataInfo $metadata |
||
| 745 | * |
||
| 746 | * @return string |
||
| 747 | */ |
||
| 748 | 43 | protected function generateEntityConstructor(ClassMetadataInfo $metadata) |
|
| 772 | |||
| 773 | /** |
||
| 774 | * @param ClassMetadataInfo $metadata |
||
| 775 | * |
||
| 776 | * @return string |
||
| 777 | */ |
||
| 778 | 1 | private function generateEmbeddableConstructor(ClassMetadataInfo $metadata) |
|
| 864 | |||
| 865 | /** |
||
| 866 | * @todo this won't work if there is a namespace in brackets and a class outside of it. |
||
| 867 | * |
||
| 868 | * @param string $src |
||
| 869 | * |
||
| 870 | * @return void |
||
| 871 | */ |
||
| 872 | 8 | protected function parseTokensInEntityFile($src) |
|
| 919 | |||
| 920 | /** |
||
| 921 | * @param string $property |
||
| 922 | * @param ClassMetadataInfo $metadata |
||
| 923 | * |
||
| 924 | * @return bool |
||
| 925 | */ |
||
| 926 | 42 | View Code Duplication | protected function hasProperty($property, ClassMetadataInfo $metadata) |
| 948 | |||
| 949 | /** |
||
| 950 | * @param string $method |
||
| 951 | * @param ClassMetadataInfo $metadata |
||
| 952 | * |
||
| 953 | * @return bool |
||
| 954 | */ |
||
| 955 | 43 | View Code Duplication | protected function hasMethod($method, ClassMetadataInfo $metadata) |
| 978 | |||
| 979 | /** |
||
| 980 | * @param ClassMetadataInfo $metadata |
||
| 981 | * |
||
| 982 | * @return array |
||
| 983 | * |
||
| 984 | * @throws \ReflectionException |
||
| 985 | */ |
||
| 986 | 43 | protected function getTraits(ClassMetadataInfo $metadata) |
|
| 1004 | |||
| 1005 | /** |
||
| 1006 | * @param ClassMetadataInfo $metadata |
||
| 1007 | * |
||
| 1008 | * @return bool |
||
| 1009 | */ |
||
| 1010 | 42 | protected function hasNamespace(ClassMetadataInfo $metadata) |
|
| 1014 | |||
| 1015 | /** |
||
| 1016 | * @return bool |
||
| 1017 | */ |
||
| 1018 | 43 | protected function extendsClass() |
|
| 1022 | |||
| 1023 | /** |
||
| 1024 | * @return string |
||
| 1025 | */ |
||
| 1026 | 2 | protected function getClassToExtend() |
|
| 1030 | |||
| 1031 | /** |
||
| 1032 | * @return string |
||
| 1033 | */ |
||
| 1034 | 1 | protected function getClassToExtendName() |
|
| 1040 | |||
| 1041 | /** |
||
| 1042 | * @param ClassMetadataInfo $metadata |
||
| 1043 | * |
||
| 1044 | * @return string |
||
| 1045 | */ |
||
| 1046 | 43 | protected function getClassName(ClassMetadataInfo $metadata) |
|
| 1051 | |||
| 1052 | /** |
||
| 1053 | * @param ClassMetadataInfo $metadata |
||
| 1054 | * |
||
| 1055 | * @return string |
||
| 1056 | */ |
||
| 1057 | 42 | protected function getNamespace(ClassMetadataInfo $metadata) |
|
| 1061 | |||
| 1062 | /** |
||
| 1063 | * @param ClassMetadataInfo $metadata |
||
| 1064 | * |
||
| 1065 | * @return string |
||
| 1066 | */ |
||
| 1067 | 42 | protected function generateEntityDocBlock(ClassMetadataInfo $metadata) |
|
| 1100 | |||
| 1101 | /** |
||
| 1102 | * @param ClassMetadataInfo $metadata |
||
| 1103 | * |
||
| 1104 | * @return string |
||
| 1105 | */ |
||
| 1106 | 42 | protected function generateEntityAnnotation(ClassMetadataInfo $metadata) |
|
| 1120 | |||
| 1121 | /** |
||
| 1122 | * @param ClassMetadataInfo $metadata |
||
| 1123 | * |
||
| 1124 | * @return string |
||
| 1125 | */ |
||
| 1126 | 42 | protected function generateTableAnnotation(ClassMetadataInfo $metadata) |
|
| 1158 | |||
| 1159 | /** |
||
| 1160 | * @param string $constraintName |
||
| 1161 | * @param array $constraints |
||
| 1162 | * |
||
| 1163 | * @return string |
||
| 1164 | */ |
||
| 1165 | 10 | protected function generateTableConstraints($constraintName, array $constraints) |
|
| 1178 | |||
| 1179 | /** |
||
| 1180 | * @param ClassMetadataInfo $metadata |
||
| 1181 | * |
||
| 1182 | * @return string |
||
| 1183 | */ |
||
| 1184 | 42 | protected function generateInheritanceAnnotation(ClassMetadataInfo $metadata) |
|
| 1192 | |||
| 1193 | /** |
||
| 1194 | * @param ClassMetadataInfo $metadata |
||
| 1195 | * |
||
| 1196 | * @return string |
||
| 1197 | */ |
||
| 1198 | 42 | protected function generateDiscriminatorColumnAnnotation(ClassMetadataInfo $metadata) |
|
| 1211 | |||
| 1212 | /** |
||
| 1213 | * @param ClassMetadataInfo $metadata |
||
| 1214 | * |
||
| 1215 | * @return string |
||
| 1216 | */ |
||
| 1217 | 42 | protected function generateDiscriminatorMapAnnotation(ClassMetadataInfo $metadata) |
|
| 1231 | |||
| 1232 | /** |
||
| 1233 | * @param ClassMetadataInfo $metadata |
||
| 1234 | * |
||
| 1235 | * @return string |
||
| 1236 | */ |
||
| 1237 | 42 | protected function generateEntityStubMethods(ClassMetadataInfo $metadata) |
|
| 1300 | |||
| 1301 | /** |
||
| 1302 | * @param array $associationMapping |
||
| 1303 | * |
||
| 1304 | * @return bool |
||
| 1305 | */ |
||
| 1306 | 12 | protected function isAssociationIsNullable(array $associationMapping) |
|
| 1327 | |||
| 1328 | /** |
||
| 1329 | * @param ClassMetadataInfo $metadata |
||
| 1330 | * |
||
| 1331 | * @return string |
||
| 1332 | */ |
||
| 1333 | 43 | protected function generateEntityLifecycleCallbackMethods(ClassMetadataInfo $metadata) |
|
| 1349 | |||
| 1350 | /** |
||
| 1351 | * @param ClassMetadataInfo $metadata |
||
| 1352 | * |
||
| 1353 | * @return string |
||
| 1354 | */ |
||
| 1355 | 43 | protected function generateEntityAssociationMappingProperties(ClassMetadataInfo $metadata) |
|
| 1371 | |||
| 1372 | /** |
||
| 1373 | * @param ClassMetadataInfo $metadata |
||
| 1374 | * |
||
| 1375 | * @return string |
||
| 1376 | */ |
||
| 1377 | 43 | protected function generateEntityFieldMappingProperties(ClassMetadataInfo $metadata) |
|
| 1396 | |||
| 1397 | /** |
||
| 1398 | * @param ClassMetadataInfo $metadata |
||
| 1399 | * |
||
| 1400 | * @return string |
||
| 1401 | */ |
||
| 1402 | 43 | protected function generateEntityEmbeddedProperties(ClassMetadataInfo $metadata) |
|
| 1417 | |||
| 1418 | /** |
||
| 1419 | * @param ClassMetadataInfo $metadata |
||
| 1420 | * @param string $type |
||
| 1421 | * @param string $fieldName |
||
| 1422 | * @param string|null $typeHint |
||
| 1423 | * @param string|null $defaultValue |
||
| 1424 | * |
||
| 1425 | * @return string |
||
| 1426 | */ |
||
| 1427 | 41 | protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null) |
|
| 1483 | |||
| 1484 | /** |
||
| 1485 | * @param string $name |
||
| 1486 | * @param string $methodName |
||
| 1487 | * @param ClassMetadataInfo $metadata |
||
| 1488 | * |
||
| 1489 | * @return string |
||
| 1490 | */ |
||
| 1491 | 11 | protected function generateLifecycleCallbackMethod($name, $methodName, ClassMetadataInfo $metadata) |
|
| 1512 | |||
| 1513 | /** |
||
| 1514 | * @param array $joinColumn |
||
| 1515 | * |
||
| 1516 | * @return string |
||
| 1517 | */ |
||
| 1518 | 12 | protected function generateJoinColumnAnnotation(array $joinColumn) |
|
| 1548 | |||
| 1549 | /** |
||
| 1550 | * @param array $associationMapping |
||
| 1551 | * @param ClassMetadataInfo $metadata |
||
| 1552 | * |
||
| 1553 | * @return string |
||
| 1554 | */ |
||
| 1555 | 12 | protected function generateAssociationMappingPropertyDocBlock(array $associationMapping, ClassMetadataInfo $metadata) |
|
| 1700 | |||
| 1701 | /** |
||
| 1702 | * @param array $fieldMapping |
||
| 1703 | * @param ClassMetadataInfo $metadata |
||
| 1704 | * |
||
| 1705 | * @return string |
||
| 1706 | */ |
||
| 1707 | 40 | protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, ClassMetadataInfo $metadata) |
|
| 1798 | |||
| 1799 | /** |
||
| 1800 | * @param array $embeddedClass |
||
| 1801 | * |
||
| 1802 | * @return string |
||
| 1803 | */ |
||
| 1804 | 10 | protected function generateEmbeddedPropertyDocBlock(array $embeddedClass) |
|
| 1831 | |||
| 1832 | 42 | private function generateEntityListenerAnnotation(ClassMetadataInfo $metadata): string |
|
| 1852 | |||
| 1853 | /** |
||
| 1854 | * @param string $code |
||
| 1855 | * @param int $num |
||
| 1856 | * |
||
| 1857 | * @return string |
||
| 1858 | */ |
||
| 1859 | 42 | protected function prefixCodeWithSpaces($code, $num = 1) |
|
| 1871 | |||
| 1872 | /** |
||
| 1873 | * @param integer $type The inheritance type used by the class and its subclasses. |
||
| 1874 | * |
||
| 1875 | * @return string The literal string for the inheritance type. |
||
| 1876 | * |
||
| 1877 | * @throws \InvalidArgumentException When the inheritance type does not exist. |
||
| 1878 | */ |
||
| 1879 | 1 | protected function getInheritanceTypeString($type) |
|
| 1887 | |||
| 1888 | /** |
||
| 1889 | * @param integer $type The policy used for change-tracking for the mapped class. |
||
| 1890 | * |
||
| 1891 | * @return string The literal string for the change-tracking type. |
||
| 1892 | * |
||
| 1893 | * @throws \InvalidArgumentException When the change-tracking type does not exist. |
||
| 1894 | */ |
||
| 1895 | 1 | protected function getChangeTrackingPolicyString($type) |
|
| 1903 | |||
| 1904 | /** |
||
| 1905 | * @param integer $type The generator to use for the mapped class. |
||
| 1906 | * |
||
| 1907 | * @return string The literal string for the generator type. |
||
| 1908 | * |
||
| 1909 | * @throws \InvalidArgumentException When the generator type does not exist. |
||
| 1910 | */ |
||
| 1911 | 37 | protected function getIdGeneratorTypeString($type) |
|
| 1919 | |||
| 1920 | /** |
||
| 1921 | * @param array $fieldMapping |
||
| 1922 | * |
||
| 1923 | * @return string|null |
||
| 1924 | */ |
||
| 1925 | 42 | private function nullableFieldExpression(array $fieldMapping) |
|
| 1933 | |||
| 1934 | /** |
||
| 1935 | * Exports (nested) option elements. |
||
| 1936 | * |
||
| 1937 | * @param array $options |
||
| 1938 | * |
||
| 1939 | * @return string |
||
| 1940 | */ |
||
| 1941 | 1 | private function exportTableOptions(array $options) |
|
| 1955 | |||
| 1956 | /** |
||
| 1957 | * @param ClassMetadataInfo $metadata |
||
| 1958 | * @param string $type |
||
| 1959 | * @param string $fieldName |
||
| 1960 | * @param string $variableType |
||
| 1961 | * @return string |
||
| 1962 | */ |
||
| 1963 | 11 | private function getMethodReturnType(ClassMetadataInfo $metadata, $type, $fieldName, $variableType) |
|
| 1987 | } |
||
| 1988 |
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: