Complex classes like AbstractObject 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 AbstractObject, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 57 | abstract class AbstractObject implements ObjectInterface |
||
| 58 | { |
||
| 59 | /** |
||
| 60 | * Clean state |
||
| 61 | * |
||
| 62 | * @var int |
||
| 63 | */ |
||
| 64 | const STATE_CLEAN = 0; |
||
| 65 | /** |
||
| 66 | * Dirty state |
||
| 67 | * |
||
| 68 | * @var int |
||
| 69 | */ |
||
| 70 | const STATE_DIRTY = 1; |
||
| 71 | /** |
||
| 72 | * Mutated state |
||
| 73 | * |
||
| 74 | * @var int |
||
| 75 | */ |
||
| 76 | const STATE_MUTATED = 2; |
||
| 77 | /** |
||
| 78 | * Published state |
||
| 79 | * |
||
| 80 | * @var int |
||
| 81 | */ |
||
| 82 | const STATE_PUBLISHED = 4; |
||
| 83 | /** |
||
| 84 | * System properties |
||
| 85 | * |
||
| 86 | * @var SystemProperties |
||
| 87 | */ |
||
| 88 | protected $systemProperties; |
||
| 89 | /** |
||
| 90 | * Meta properties |
||
| 91 | * |
||
| 92 | * @var MetaProperties |
||
| 93 | */ |
||
| 94 | protected $metaProperties; |
||
| 95 | /** |
||
| 96 | * Domain properties |
||
| 97 | * |
||
| 98 | * @var AbstractDomainProperties |
||
| 99 | */ |
||
| 100 | protected $domainProperties; |
||
| 101 | /** |
||
| 102 | * Object payload |
||
| 103 | * |
||
| 104 | * @var string |
||
| 105 | */ |
||
| 106 | protected $payload; |
||
| 107 | /** |
||
| 108 | * Repository path |
||
| 109 | * |
||
| 110 | * @var RepositoryPathInterface |
||
| 111 | */ |
||
| 112 | protected $path; |
||
| 113 | /** |
||
| 114 | * Domain property collection class |
||
| 115 | * |
||
| 116 | * @var string |
||
| 117 | */ |
||
| 118 | protected $domainPropertyCClass = AbstractDomainProperties::class; |
||
| 119 | /** |
||
| 120 | * Object relations |
||
| 121 | * |
||
| 122 | * @var Relations |
||
| 123 | */ |
||
| 124 | protected $relations; |
||
| 125 | /** |
||
| 126 | * Processing instructions |
||
| 127 | * |
||
| 128 | * @var ProcessingInstructions |
||
| 129 | */ |
||
| 130 | protected $processingInstructions; |
||
| 131 | /** |
||
| 132 | * Latest revision index |
||
| 133 | * |
||
| 134 | * @var Revision |
||
| 135 | */ |
||
| 136 | protected $latestRevision; |
||
| 137 | /** |
||
| 138 | * Object state |
||
| 139 | * |
||
| 140 | * @var int |
||
| 141 | */ |
||
| 142 | protected $state = self::STATE_CLEAN; |
||
| 143 | /** |
||
| 144 | * Property collection states |
||
| 145 | * |
||
| 146 | * @var array |
||
| 147 | */ |
||
| 148 | protected $collectionStates = []; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Object constructor |
||
| 152 | * |
||
| 153 | * @param string $payload Object payload |
||
| 154 | * @param array $propertyData Property data |
||
| 155 | * @param RepositoryPathInterface $path Object repository path |
||
| 156 | */ |
||
| 157 | 20 | public function __construct($payload = '', array $propertyData = [], RepositoryPathInterface $path = null) |
|
| 158 | { |
||
| 159 | // If the domain property collection class is invalid |
||
| 160 | 20 | if (!$this->domainPropertyCClass |
|
| 161 | 20 | || !class_exists($this->domainPropertyCClass) |
|
| 162 | 20 | || !(new \ReflectionClass($this->domainPropertyCClass))->isSubclassOf(AbstractDomainProperties::class) |
|
| 163 | 20 | ) { |
|
| 164 | 1 | throw new PropertyInvalidArgumentException( |
|
| 165 | 1 | sprintf( |
|
| 166 | 1 | 'Invalid domain property collection class "%s"', |
|
| 167 | 1 | $this->domainPropertyCClass |
|
| 168 | 1 | ), |
|
| 169 | PropertyInvalidArgumentException::INVALID_DOMAIN_PROPERTY_COLLECTION_CLASS |
||
| 170 | 1 | ); |
|
| 171 | } |
||
| 172 | |||
| 173 | // Right after instantiation it's always the current revision |
||
| 174 | 19 | $this->path = $path->setRevision(Revision::current()); |
|
|
|
|||
| 175 | |||
| 176 | // Load the current revision data |
||
| 177 | 19 | $this->loadRevisionData($payload, $propertyData); |
|
| 178 | |||
| 179 | // Save the latest revision index |
||
| 180 | 18 | $this->latestRevision = $this->getRevision(); |
|
| 181 | 18 | } |
|
| 182 | |||
| 183 | /** |
||
| 184 | * Load object revision data |
||
| 185 | * |
||
| 186 | * @param string $payload Object payload |
||
| 187 | * @param array $propertyData Property data |
||
| 188 | */ |
||
| 189 | 19 | protected function loadRevisionData($payload = '', array $propertyData = []) |
|
| 239 | |||
| 240 | /** |
||
| 241 | * Set the meta properties collection |
||
| 242 | * |
||
| 243 | * @param MetaProperties $metaProperties Meta property collection |
||
| 244 | * @param bool $overwrite Overwrite the existing collection (if present) |
||
| 245 | */ |
||
| 246 | 18 | protected function setMetaProperties(MetaProperties $metaProperties, $overwrite = false) |
|
| 247 | { |
||
| 248 | 18 | $this->metaProperties = $metaProperties; |
|
| 249 | 18 | $metaPropertiesState = spl_object_hash($this->metaProperties); |
|
| 250 | |||
| 251 | // If the meta property collection state has changed |
||
| 252 | if (!$overwrite |
||
| 253 | 18 | && !empty($this->collectionStates[MetaProperties::COLLECTION]) |
|
| 254 | 18 | && ($metaPropertiesState !== $this->collectionStates[MetaProperties::COLLECTION]) |
|
| 255 | 18 | ) { |
|
| 256 | // Flag this object as mutated |
||
| 257 | 1 | $this->setMutatedState(); |
|
| 258 | 1 | } |
|
| 259 | |||
| 260 | 18 | $this->collectionStates[MetaProperties::COLLECTION] = $metaPropertiesState; |
|
| 261 | 18 | } |
|
| 262 | |||
| 263 | /** |
||
| 264 | * Set the object state to mutated |
||
| 265 | */ |
||
| 266 | 3 | protected function setMutatedState() |
|
| 267 | { |
||
| 268 | // If this object is not in mutated state yet |
||
| 269 | 3 | if (!($this->state & self::STATE_MUTATED) && !$this->isDraft()) { |
|
| 270 | // TODO: Send signal |
||
| 271 | 3 | $this->convertToDraft(); |
|
| 272 | 3 | } |
|
| 273 | |||
| 274 | // Enable the mutated (and dirty) state |
||
| 275 | 3 | $this->state |= (self::STATE_DIRTY | self::STATE_MUTATED); |
|
| 276 | 3 | } |
|
| 277 | |||
| 278 | /** |
||
| 279 | * Return the object draft mode |
||
| 280 | * |
||
| 281 | * @return boolean Object draft mode |
||
| 282 | */ |
||
| 283 | 4 | public function isDraft() |
|
| 287 | |||
| 288 | /** |
||
| 289 | * Return whether the object is in published state |
||
| 290 | * |
||
| 291 | * @return boolean Published state |
||
| 292 | */ |
||
| 293 | 4 | public function isPublished() |
|
| 297 | |||
| 298 | /** |
||
| 299 | * Convert this object revision into a draft |
||
| 300 | */ |
||
| 301 | 3 | protected function convertToDraft() |
|
| 328 | |||
| 329 | /** |
||
| 330 | * Set the domain properties collection |
||
| 331 | * |
||
| 332 | * @param GenericPropertiesInterface $domainProperties Domain property collection |
||
| 333 | * @param bool $overwrite Overwrite the existing collection (if present) |
||
| 334 | */ |
||
| 335 | 18 | protected function setDomainProperties(GenericPropertiesInterface $domainProperties, $overwrite = false) |
|
| 336 | { |
||
| 337 | 18 | $this->domainProperties = $domainProperties; |
|
| 338 | 18 | $domainPropertiesState = spl_object_hash($this->domainProperties); |
|
| 339 | |||
| 340 | // If the domain property collection state has changed |
||
| 341 | if (!$overwrite |
||
| 342 | 18 | && !empty($this->collectionStates[AbstractDomainProperties::COLLECTION]) |
|
| 343 | 18 | && ($domainPropertiesState !== $this->collectionStates[AbstractDomainProperties::COLLECTION]) |
|
| 344 | 18 | ) { |
|
| 345 | // Flag this object as mutated |
||
| 346 | 1 | $this->setMutatedState(); |
|
| 347 | 1 | } |
|
| 348 | |||
| 349 | 18 | $this->collectionStates[AbstractDomainProperties::COLLECTION] = $domainPropertiesState; |
|
| 350 | 18 | } |
|
| 351 | |||
| 352 | /** |
||
| 353 | * Set the processing instruction collection |
||
| 354 | * |
||
| 355 | * @param GenericPropertiesInterface $processingInstructions Processing instruction collection |
||
| 356 | * @param bool $overwrite Overwrite the existing collection (if present) |
||
| 357 | */ |
||
| 358 | 18 | protected function setProcessingInstructions(GenericPropertiesInterface $processingInstructions, $overwrite = false) |
|
| 359 | { |
||
| 360 | 18 | $this->processingInstructions = $processingInstructions; |
|
| 361 | 18 | $processingInstructionsState = spl_object_hash($this->processingInstructions); |
|
| 362 | |||
| 363 | // If the domain property collection state has changed |
||
| 364 | if (!$overwrite |
||
| 365 | 18 | && !empty($this->collectionStates[ProcessingInstructions::COLLECTION]) |
|
| 366 | 18 | && ($processingInstructionsState !== $this->collectionStates[ProcessingInstructions::COLLECTION]) |
|
| 367 | 18 | ) { |
|
| 368 | // Flag this object as dirty |
||
| 369 | 1 | $this->setDirtyState(); |
|
| 370 | 1 | } |
|
| 371 | |||
| 372 | 18 | $this->collectionStates[ProcessingInstructions::COLLECTION] = $processingInstructionsState; |
|
| 373 | 18 | } |
|
| 374 | |||
| 375 | /** |
||
| 376 | * Set the object state to dirty |
||
| 377 | */ |
||
| 378 | 1 | protected function setDirtyState() |
|
| 379 | { |
||
| 380 | // If this object is not in dirty state yet |
||
| 381 | 1 | if (!($this->state & self::STATE_DIRTY)) { |
|
| 382 | // TODO: Send signal |
||
| 383 | 1 | } |
|
| 384 | |||
| 385 | // Enable the dirty state |
||
| 386 | 1 | $this->state |= self::STATE_DIRTY; |
|
| 387 | 1 | } |
|
| 388 | |||
| 389 | /** |
||
| 390 | * Set the relations collection |
||
| 391 | * |
||
| 392 | * @param Relations $relations Relations collection |
||
| 393 | * @param bool $overwrite Overwrite the existing collection (if present) |
||
| 394 | */ |
||
| 395 | 18 | protected function setRelations(Relations $relations, $overwrite = false) |
|
| 396 | { |
||
| 397 | 18 | $this->relations = $relations; |
|
| 398 | 18 | $relationsState = spl_object_hash($this->relations); |
|
| 399 | |||
| 400 | // If the domain property collection state has changed |
||
| 401 | if (!$overwrite |
||
| 402 | 18 | && !empty($this->collectionStates[Relations::COLLECTION]) |
|
| 403 | 18 | && ($relationsState !== $this->collectionStates[Relations::COLLECTION]) |
|
| 404 | 18 | ) { |
|
| 405 | // Flag this object as dirty |
||
| 406 | $this->setDirtyState(); |
||
| 407 | } |
||
| 408 | |||
| 409 | 18 | $this->collectionStates[Relations::COLLECTION] = $relationsState; |
|
| 410 | 18 | } |
|
| 411 | |||
| 412 | /** |
||
| 413 | * Return the object revision |
||
| 414 | * |
||
| 415 | * @return Revision Object revision |
||
| 416 | */ |
||
| 417 | 18 | public function getRevision() |
|
| 421 | |||
| 422 | /** |
||
| 423 | * Return whether the object is in mutated state |
||
| 424 | * |
||
| 425 | * @return boolean Mutated state |
||
| 426 | */ |
||
| 427 | 3 | public function isMutated() |
|
| 431 | |||
| 432 | /** |
||
| 433 | * Use a specific object revision |
||
| 434 | * |
||
| 435 | * @param Revision $revision Revision to be used |
||
| 436 | * @return ObjectInterface Object |
||
| 437 | * @throws OutOfBoundsException If the requested revision is invalid |
||
| 438 | */ |
||
| 439 | 17 | public function useRevision(Revision $revision) |
|
| 440 | { |
||
| 441 | 17 | $isCurrentRevision = false; |
|
| 442 | |||
| 443 | // If the requested revision is invalid |
||
| 444 | 17 | if (!$revision->isCurrent() && |
|
| 445 | (($revision->getRevision() < 1) || ($revision->getRevision() > $this->latestRevision->getRevision())) |
||
| 446 | 17 | ) { |
|
| 447 | throw new OutOfBoundsException(sprintf('Invalid object revision "%s"', $revision->getRevision()), |
||
| 448 | OutOfBoundsException::INVALID_OBJECT_REVISION); |
||
| 449 | } |
||
| 450 | |||
| 451 | // If the current revision got requested |
||
| 452 | 17 | if ($revision->isCurrent()) { |
|
| 453 | 17 | $isCurrentRevision = true; |
|
| 454 | 17 | $revision = $this->latestRevision; |
|
| 455 | 17 | } |
|
| 456 | |||
| 457 | // If the requested revision is not already used |
||
| 458 | 17 | if ($revision != $this->getRevision()) { |
|
| 459 | /** @var ManagerInterface $objectManager */ |
||
| 460 | $objectManager = Kernel::create(Service::class)->getObjectManager(); |
||
| 461 | |||
| 462 | // Load the requested object revision resource |
||
| 463 | /** @var Revision $newRevision */ |
||
| 464 | $newRevision = $isCurrentRevision ? Revision::current() : $revision; |
||
| 465 | /** @var RepositoryPath $newRevisionPath */ |
||
| 466 | $newRevisionPath = $this->path->setRevision($newRevision); |
||
| 467 | $revisionResource = $objectManager->loadObject($newRevisionPath); |
||
| 468 | |||
| 469 | // Load the revision resource data |
||
| 470 | $this->loadRevisionData($revisionResource->getPayload(), $revisionResource->getPropertyData()); |
||
| 471 | |||
| 472 | // Set the current revision path |
||
| 473 | $this->path = $newRevisionPath; |
||
| 474 | } |
||
| 475 | |||
| 476 | 17 | return $this; |
|
| 477 | } |
||
| 478 | |||
| 479 | /** |
||
| 480 | * Return the object ID |
||
| 481 | * |
||
| 482 | * @return Id Object ID |
||
| 483 | */ |
||
| 484 | 5 | public function getId() |
|
| 488 | |||
| 489 | /** |
||
| 490 | * Return the object type |
||
| 491 | * |
||
| 492 | * @return Type Object type |
||
| 493 | */ |
||
| 494 | 1 | public function getType() |
|
| 498 | |||
| 499 | /** |
||
| 500 | * Return the creation date & time |
||
| 501 | * |
||
| 502 | * @return \DateTimeImmutable Creation date & time |
||
| 503 | */ |
||
| 504 | 1 | public function getCreated() |
|
| 508 | |||
| 509 | /** |
||
| 510 | * Return the publication date & time |
||
| 511 | * |
||
| 512 | * @return \DateTimeImmutable|null Publication date & time |
||
| 513 | */ |
||
| 514 | 1 | public function getPublished() |
|
| 518 | |||
| 519 | /** |
||
| 520 | * Return the object hash |
||
| 521 | * |
||
| 522 | * @return string Object hash |
||
| 523 | */ |
||
| 524 | 1 | public function getHash() |
|
| 528 | |||
| 529 | /** |
||
| 530 | * Return the object title |
||
| 531 | * |
||
| 532 | * @return string Object title |
||
| 533 | */ |
||
| 534 | 1 | public function getTitle() |
|
| 538 | |||
| 539 | /** |
||
| 540 | * Set the title |
||
| 541 | * |
||
| 542 | * @param string $title Title |
||
| 543 | * @return ObjectInterface Self reference |
||
| 544 | */ |
||
| 545 | 1 | public function setTitle($title) |
|
| 550 | |||
| 551 | /** |
||
| 552 | * Return the object slug |
||
| 553 | * |
||
| 554 | * @return string Object slug |
||
| 555 | */ |
||
| 556 | 1 | public function getSlug() |
|
| 560 | |||
| 561 | /** |
||
| 562 | * Set the slug |
||
| 563 | * |
||
| 564 | * @param string $slug Slug |
||
| 565 | * @return ObjectInterface Self reference |
||
| 566 | */ |
||
| 567 | 1 | public function setSlug($slug) |
|
| 572 | |||
| 573 | /** |
||
| 574 | * Return the object description |
||
| 575 | * |
||
| 576 | * @return string Object description |
||
| 577 | */ |
||
| 578 | 2 | public function getDescription() |
|
| 582 | |||
| 583 | /** |
||
| 584 | * Set the description |
||
| 585 | * |
||
| 586 | * @param string $description Description |
||
| 587 | * @return ObjectInterface Self reference |
||
| 588 | */ |
||
| 589 | 1 | public function setDescription($description) |
|
| 594 | |||
| 595 | /** |
||
| 596 | * Return the object abstract |
||
| 597 | * |
||
| 598 | * @return string Object abstract |
||
| 599 | */ |
||
| 600 | 2 | public function getAbstract() |
|
| 604 | |||
| 605 | /** |
||
| 606 | * Set the abstract |
||
| 607 | * |
||
| 608 | * @param string $abstract Abstract |
||
| 609 | * @return ObjectInterface Self reference |
||
| 610 | */ |
||
| 611 | 1 | public function setAbstract($abstract) |
|
| 616 | |||
| 617 | /** |
||
| 618 | * Return the license |
||
| 619 | * |
||
| 620 | * @return string License |
||
| 621 | */ |
||
| 622 | 1 | public function getLicense() |
|
| 623 | { |
||
| 624 | 1 | return $this->metaProperties->getLicense(); |
|
| 626 | |||
| 627 | /** |
||
| 628 | * Set the license |
||
| 629 | * |
||
| 630 | * @param string $license License |
||
| 631 | * @return MetaProperties Self reference |
||
| 632 | */ |
||
| 633 | 1 | public function setLicense($license) |
|
| 638 | |||
| 639 | /** |
||
| 640 | * Return the privacy |
||
| 641 | * |
||
| 642 | * @return string Privacy |
||
| 643 | */ |
||
| 644 | 1 | public function getPrivacy() |
|
| 648 | |||
| 649 | /** |
||
| 650 | * Set the privacy |
||
| 651 | * |
||
| 652 | * @param string $privacy Privacy |
||
| 653 | * @return MetaProperties Self reference |
||
| 654 | */ |
||
| 655 | 1 | public function setPrivacy($privacy) |
|
| 660 | |||
| 661 | /** |
||
| 662 | * Return all object keywords |
||
| 663 | * |
||
| 664 | * @return array Object keywords |
||
| 665 | */ |
||
| 666 | 2 | public function getKeywords() |
|
| 670 | |||
| 671 | /** |
||
| 672 | * Set the keywords |
||
| 673 | * |
||
| 674 | * @param array $keywords Keywords |
||
| 675 | * @return ObjectInterface Self reference |
||
| 676 | */ |
||
| 677 | 1 | public function setKeywords(array $keywords) |
|
| 682 | |||
| 683 | /** |
||
| 684 | * Return all object categories |
||
| 685 | * |
||
| 686 | * @return array Object categories |
||
| 687 | */ |
||
| 688 | 2 | public function getCategories() |
|
| 692 | |||
| 693 | /** |
||
| 694 | * Set the categories |
||
| 695 | * |
||
| 696 | * @param array $categories Categories |
||
| 697 | * @return ObjectInterface Self reference |
||
| 698 | */ |
||
| 699 | 1 | public function setCategories(array $categories) |
|
| 704 | |||
| 705 | /** |
||
| 706 | * Return the object repository path |
||
| 707 | * |
||
| 708 | * @return RepositoryPathInterface Object repository path |
||
| 709 | */ |
||
| 710 | 18 | public function getRepositoryPath() |
|
| 714 | |||
| 715 | /** |
||
| 716 | * Return the object property data |
||
| 717 | * |
||
| 718 | * @return array Object property data |
||
| 719 | */ |
||
| 720 | 5 | public function getPropertyData() |
|
| 734 | |||
| 735 | /** |
||
| 736 | * Return the object payload |
||
| 737 | * |
||
| 738 | * @return string Object payload |
||
| 739 | */ |
||
| 740 | 2 | public function getPayload() |
|
| 744 | |||
| 745 | /** |
||
| 746 | * Set the payload |
||
| 747 | * |
||
| 748 | * @param string $payload Payload |
||
| 749 | * @return ObjectInterface Self reference |
||
| 750 | */ |
||
| 751 | 1 | public function setPayload($payload) |
|
| 761 | |||
| 762 | /** |
||
| 763 | * Return the absolute object URL |
||
| 764 | * |
||
| 765 | * @return string |
||
| 766 | */ |
||
| 767 | 4 | public function getAbsoluteUrl() |
|
| 771 | |||
| 772 | /** |
||
| 773 | * Get a domain property value |
||
| 774 | * |
||
| 775 | * Multi-level properties might be traversed by property name paths separated with colons (":"). |
||
| 776 | * |
||
| 777 | * @param string $property Property name |
||
| 778 | * @return mixed Property value |
||
| 779 | */ |
||
| 780 | 2 | public function getDomainProperty($property) |
|
| 784 | |||
| 785 | /** |
||
| 786 | * Set a domain property value |
||
| 787 | * |
||
| 788 | * @param string $property Property name |
||
| 789 | * @param mixed $value Property value |
||
| 790 | * @return ObjectInterface Self reference |
||
| 791 | */ |
||
| 792 | 1 | public function setDomainProperty($property, $value) |
|
| 797 | |||
| 798 | /** |
||
| 799 | * Get a processing instruction |
||
| 800 | * |
||
| 801 | * @param string $procInst Processing instruction name |
||
| 802 | * @return mixed Processing instruction |
||
| 803 | */ |
||
| 804 | public function getProcessingInstruction($procInst) |
||
| 808 | |||
| 809 | /** |
||
| 810 | * Set a processing instruction |
||
| 811 | * |
||
| 812 | * @param string $procInst Processing instruction name |
||
| 813 | * @param mixed $value Processing instruction |
||
| 814 | * @return ObjectInterface Self reference |
||
| 815 | */ |
||
| 816 | 1 | public function setProcessingInstruction($procInst, $value) |
|
| 821 | |||
| 822 | /** |
||
| 823 | * Persist the current object revision |
||
| 824 | * |
||
| 825 | * @return ObjectInterface Object |
||
| 826 | */ |
||
| 827 | 1 | public function persist() |
|
| 849 | |||
| 850 | /** |
||
| 851 | * Publish the current object revision |
||
| 852 | * |
||
| 853 | * @return ObjectInterface Object |
||
| 854 | */ |
||
| 855 | 1 | public function publish() |
|
| 876 | |||
| 877 | /** |
||
| 878 | * Set the object state to published |
||
| 879 | */ |
||
| 880 | 1 | protected function setPublishedState() |
|
| 890 | |||
| 891 | /** |
||
| 892 | * Return whether the object is in dirty state |
||
| 893 | * |
||
| 894 | * @return boolean Dirty state |
||
| 895 | */ |
||
| 896 | 3 | public function isDirty() |
|
| 900 | } |
||
| 901 |
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: