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 | * 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) |
||
| 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) |
|
| 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) |
|
| 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) |
|
| 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) |
||
| 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) |
||
| 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) |
|
| 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) |
|
| 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) |
|
| 515 | |||
| 516 | /** |
||
| 517 | * Sets whether or not to generate immutable embeddables. |
||
| 518 | * |
||
| 519 | * @param boolean $embeddablesImmutable |
||
| 520 | */ |
||
| 521 | 1 | public function setEmbeddablesImmutable($embeddablesImmutable) |
|
| 525 | |||
| 526 | /** |
||
| 527 | * Sets an annotation prefix. |
||
| 528 | * |
||
| 529 | * @param string $prefix |
||
| 530 | * |
||
| 531 | * @return void |
||
| 532 | */ |
||
| 533 | 40 | public function setAnnotationPrefix($prefix) |
|
| 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) |
|
| 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) |
|
| 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) |
|
| 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) |
|
| 585 | |||
| 586 | /** |
||
| 587 | * @param string $type |
||
| 588 | * |
||
| 589 | * @return string |
||
| 590 | */ |
||
| 591 | 31 | protected function getType($type) |
|
| 599 | |||
| 600 | /** |
||
| 601 | * @param ClassMetadataInfo $metadata |
||
| 602 | * |
||
| 603 | * @return string |
||
| 604 | */ |
||
| 605 | 31 | protected function generateEntityNamespace(ClassMetadataInfo $metadata) |
|
| 613 | |||
| 614 | 31 | /** |
|
| 615 | 31 | * @return string |
|
| 616 | */ |
||
| 617 | protected function generateEntityUse() |
||
| 625 | |||
| 626 | 31 | /** |
|
| 627 | * @param ClassMetadataInfo $metadata |
||
| 628 | 31 | * |
|
| 629 | 31 | * @return string |
|
| 630 | */ |
||
| 631 | protected function generateEntityClassName(ClassMetadataInfo $metadata) |
||
| 636 | |||
| 637 | 32 | /** |
|
| 638 | * @param ClassMetadataInfo $metadata |
||
| 639 | 32 | * |
|
| 640 | 32 | * @return string |
|
| 641 | 32 | */ |
|
| 642 | 32 | protected function generateEntityBody(ClassMetadataInfo $metadata) |
|
| 676 | |||
| 677 | 32 | /** |
|
| 678 | * @param ClassMetadataInfo $metadata |
||
| 679 | 32 | * |
|
| 680 | 2 | * @return string |
|
| 681 | */ |
||
| 682 | protected function generateEntityConstructor(ClassMetadataInfo $metadata) |
||
| 706 | |||
| 707 | 1 | /** |
|
| 708 | * @param ClassMetadataInfo $metadata |
||
| 709 | 1 | * |
|
| 710 | 1 | * @return string |
|
| 711 | 1 | */ |
|
| 712 | 1 | private function generateEmbeddableConstructor(ClassMetadataInfo $metadata) |
|
| 798 | |||
| 799 | /** |
||
| 800 | * @todo this won't work if there is a namespace in brackets and a class outside of it. |
||
| 801 | * |
||
| 802 | * @param string $src |
||
| 803 | 8 | * |
|
| 804 | * @return void |
||
| 805 | 8 | */ |
|
| 806 | 8 | protected function parseTokensInEntityFile($src) |
|
| 853 | |||
| 854 | /** |
||
| 855 | * @param string $property |
||
| 856 | * @param ClassMetadataInfo $metadata |
||
| 857 | 31 | * |
|
| 858 | * @return bool |
||
| 859 | 31 | */ |
|
| 860 | View Code Duplication | protected function hasProperty($property, ClassMetadataInfo $metadata) |
|
| 882 | |||
| 883 | /** |
||
| 884 | * @param string $method |
||
| 885 | * @param ClassMetadataInfo $metadata |
||
| 886 | 32 | * |
|
| 887 | * @return bool |
||
| 888 | 32 | */ |
|
| 889 | View Code Duplication | protected function hasMethod($method, ClassMetadataInfo $metadata) |
|
| 912 | |||
| 913 | /** |
||
| 914 | * @param ClassMetadataInfo $metadata |
||
| 915 | 32 | * |
|
| 916 | * @return array |
||
| 917 | 32 | * |
|
| 918 | 26 | * @throws \ReflectionException |
|
| 919 | */ |
||
| 920 | protected function getTraits(ClassMetadataInfo $metadata) |
||
| 938 | |||
| 939 | /** |
||
| 940 | * @param ClassMetadataInfo $metadata |
||
| 941 | 31 | * |
|
| 942 | * @return bool |
||
| 943 | 31 | */ |
|
| 944 | protected function hasNamespace(ClassMetadataInfo $metadata) |
||
| 948 | |||
| 949 | 32 | /** |
|
| 950 | * @return bool |
||
| 951 | 32 | */ |
|
| 952 | protected function extendsClass() |
||
| 956 | |||
| 957 | 2 | /** |
|
| 958 | * @return string |
||
| 959 | 2 | */ |
|
| 960 | protected function getClassToExtend() |
||
| 964 | |||
| 965 | 1 | /** |
|
| 966 | * @return string |
||
| 967 | 1 | */ |
|
| 968 | protected function getClassToExtendName() |
||
| 974 | |||
| 975 | /** |
||
| 976 | * @param ClassMetadataInfo $metadata |
||
| 977 | 32 | * |
|
| 978 | * @return string |
||
| 979 | 32 | */ |
|
| 980 | 32 | protected function getClassName(ClassMetadataInfo $metadata) |
|
| 985 | |||
| 986 | /** |
||
| 987 | * @param ClassMetadataInfo $metadata |
||
| 988 | 31 | * |
|
| 989 | * @return string |
||
| 990 | 31 | */ |
|
| 991 | protected function getNamespace(ClassMetadataInfo $metadata) |
||
| 995 | |||
| 996 | /** |
||
| 997 | * @param ClassMetadataInfo $metadata |
||
| 998 | 31 | * |
|
| 999 | * @return string |
||
| 1000 | 31 | */ |
|
| 1001 | 31 | protected function generateEntityDocBlock(ClassMetadataInfo $metadata) |
|
| 1034 | |||
| 1035 | /** |
||
| 1036 | 31 | * @param ClassMetadataInfo $metadata |
|
| 1037 | * |
||
| 1038 | 31 | * @return string |
|
| 1039 | */ |
||
| 1040 | 31 | protected function generateEntityAnnotation(ClassMetadataInfo $metadata) |
|
| 1054 | |||
| 1055 | /** |
||
| 1056 | 31 | * @param ClassMetadataInfo $metadata |
|
| 1057 | * |
||
| 1058 | 31 | * @return string |
|
| 1059 | 11 | */ |
|
| 1060 | protected function generateTableAnnotation(ClassMetadataInfo $metadata) |
||
| 1092 | |||
| 1093 | /** |
||
| 1094 | * @param string $constraintName |
||
| 1095 | 9 | * @param array $constraints |
|
| 1096 | * |
||
| 1097 | 9 | * @return string |
|
| 1098 | 9 | */ |
|
| 1099 | 9 | protected function generateTableConstraints($constraintName, array $constraints) |
|
| 1112 | |||
| 1113 | /** |
||
| 1114 | 31 | * @param ClassMetadataInfo $metadata |
|
| 1115 | * |
||
| 1116 | 31 | * @return string |
|
| 1117 | */ |
||
| 1118 | protected function generateInheritanceAnnotation(ClassMetadataInfo $metadata) |
||
| 1126 | 31 | ||
| 1127 | /** |
||
| 1128 | 31 | * @param ClassMetadataInfo $metadata |
|
| 1129 | * |
||
| 1130 | * @return string |
||
| 1131 | */ |
||
| 1132 | protected function generateDiscriminatorColumnAnnotation(ClassMetadataInfo $metadata) |
||
| 1145 | 31 | ||
| 1146 | /** |
||
| 1147 | * @param ClassMetadataInfo $metadata |
||
| 1148 | * |
||
| 1149 | * @return string |
||
| 1150 | */ |
||
| 1151 | protected function generateDiscriminatorMapAnnotation(ClassMetadataInfo $metadata) |
||
| 1165 | 31 | ||
| 1166 | 30 | /** |
|
| 1167 | 30 | * @param ClassMetadataInfo $metadata |
|
| 1168 | * |
||
| 1169 | * @return string |
||
| 1170 | */ |
||
| 1171 | protected function generateEntityStubMethods(ClassMetadataInfo $metadata) |
||
| 1234 | 11 | ||
| 1235 | /** |
||
| 1236 | 11 | * @param array $associationMapping |
|
| 1237 | * |
||
| 1238 | * @return bool |
||
| 1239 | */ |
||
| 1240 | 11 | protected function isAssociationIsNullable(array $associationMapping) |
|
| 1261 | 32 | ||
| 1262 | /** |
||
| 1263 | 32 | * @param ClassMetadataInfo $metadata |
|
| 1264 | 29 | * |
|
| 1265 | * @return string |
||
| 1266 | */ |
||
| 1267 | 10 | protected function generateEntityLifecycleCallbackMethods(ClassMetadataInfo $metadata) |
|
| 1283 | 32 | ||
| 1284 | /** |
||
| 1285 | 32 | * @param ClassMetadataInfo $metadata |
|
| 1286 | * |
||
| 1287 | 32 | * @return string |
|
| 1288 | 13 | */ |
|
| 1289 | 4 | protected function generateEntityAssociationMappingProperties(ClassMetadataInfo $metadata) |
|
| 1305 | 32 | ||
| 1306 | /** |
||
| 1307 | 32 | * @param ClassMetadataInfo $metadata |
|
| 1308 | * |
||
| 1309 | 32 | * @return string |
|
| 1310 | 31 | */ |
|
| 1311 | 30 | protected function generateEntityFieldMappingProperties(ClassMetadataInfo $metadata) |
|
| 1330 | |||
| 1331 | /** |
||
| 1332 | * @param ClassMetadataInfo $metadata |
||
| 1333 | 32 | * |
|
| 1334 | * @return string |
||
| 1335 | 32 | */ |
|
| 1336 | protected function generateEntityEmbeddedProperties(ClassMetadataInfo $metadata) |
||
| 1351 | |||
| 1352 | /** |
||
| 1353 | * @param ClassMetadataInfo $metadata |
||
| 1354 | * @param string $type |
||
| 1355 | * @param string $fieldName |
||
| 1356 | * @param string|null $typeHint |
||
| 1357 | * @param string|null $defaultValue |
||
| 1358 | 30 | * |
|
| 1359 | * @return string |
||
| 1360 | 30 | */ |
|
| 1361 | 30 | protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null) |
|
| 1406 | |||
| 1407 | /** |
||
| 1408 | * @param string $name |
||
| 1409 | * @param string $methodName |
||
| 1410 | * @param ClassMetadataInfo $metadata |
||
| 1411 | 10 | * |
|
| 1412 | * @return string |
||
| 1413 | 10 | */ |
|
| 1414 | 2 | protected function generateLifecycleCallbackMethod($name, $methodName, ClassMetadataInfo $metadata) |
|
| 1435 | |||
| 1436 | /** |
||
| 1437 | 11 | * @param array $joinColumn |
|
| 1438 | * |
||
| 1439 | 11 | * @return string |
|
| 1440 | */ |
||
| 1441 | 11 | protected function generateJoinColumnAnnotation(array $joinColumn) |
|
| 1471 | |||
| 1472 | /** |
||
| 1473 | * @param array $associationMapping |
||
| 1474 | 11 | * @param ClassMetadataInfo $metadata |
|
| 1475 | * |
||
| 1476 | 11 | * @return string |
|
| 1477 | 11 | */ |
|
| 1478 | protected function generateAssociationMappingPropertyDocBlock(array $associationMapping, ClassMetadataInfo $metadata) |
||
| 1623 | |||
| 1624 | /** |
||
| 1625 | * @param array $fieldMapping |
||
| 1626 | 29 | * @param ClassMetadataInfo $metadata |
|
| 1627 | * |
||
| 1628 | 29 | * @return string |
|
| 1629 | 29 | */ |
|
| 1630 | 29 | protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, ClassMetadataInfo $metadata) |
|
| 1721 | |||
| 1722 | /** |
||
| 1723 | 10 | * @param array $embeddedClass |
|
| 1724 | * |
||
| 1725 | 10 | * @return string |
|
| 1726 | 10 | */ |
|
| 1727 | 10 | protected function generateEmbeddedPropertyDocBlock(array $embeddedClass) |
|
| 1754 | |||
| 1755 | private function generateEntityListenerAnnotation(ClassMetadataInfo $metadata): string |
||
| 1775 | |||
| 1776 | /** |
||
| 1777 | 1 | * @param string $code |
|
| 1778 | * @param int $num |
||
| 1779 | 1 | * |
|
| 1780 | 1 | * @return string |
|
| 1781 | */ |
||
| 1782 | protected function prefixCodeWithSpaces($code, $num = 1) |
||
| 1794 | |||
| 1795 | 1 | /** |
|
| 1796 | 1 | * @param integer $type The inheritance type used by the class and its subclasses. |
|
| 1797 | * |
||
| 1798 | * @return string The literal string for the inheritance type. |
||
| 1799 | 1 | * |
|
| 1800 | * @throws \InvalidArgumentException When the inheritance type does not exist. |
||
| 1801 | */ |
||
| 1802 | protected function getInheritanceTypeString($type) |
||
| 1810 | |||
| 1811 | 26 | /** |
|
| 1812 | 1 | * @param integer $type The policy used for change-tracking for the mapped class. |
|
| 1813 | * |
||
| 1814 | * @return string The literal string for the change-tracking type. |
||
| 1815 | 26 | * |
|
| 1816 | * @throws \InvalidArgumentException When the change-tracking type does not exist. |
||
| 1817 | */ |
||
| 1818 | protected function getChangeTrackingPolicyString($type) |
||
| 1826 | 7 | ||
| 1827 | /** |
||
| 1828 | * @param integer $type The generator to use for the mapped class. |
||
| 1829 | 31 | * |
|
| 1830 | * @return string The literal string for the generator type. |
||
| 1831 | * |
||
| 1832 | * @throws \InvalidArgumentException When the generator type does not exist. |
||
| 1833 | */ |
||
| 1834 | protected function getIdGeneratorTypeString($type) |
||
| 1842 | |||
| 1843 | 1 | /** |
|
| 1844 | 1 | * @param array $fieldMapping |
|
| 1845 | 1 | * |
|
| 1846 | * @return string|null |
||
| 1847 | 1 | */ |
|
| 1848 | private function nullableFieldExpression(array $fieldMapping) |
||
| 1856 | |||
| 1857 | /** |
||
| 1858 | * Exports (nested) option elements. |
||
| 1859 | * |
||
| 1860 | * @param array $options |
||
| 1861 | * |
||
| 1862 | * @return string |
||
| 1863 | */ |
||
| 1864 | private function exportTableOptions(array $options) |
||
| 1878 | } |
||
| 1879 |
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: