Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 301314

Use $this in @return PhpDoc comments instead of the name of the current class or interface

$
0
0

Problem

Modern IDEs (Netbeans, Phpstorm) can provide intelligent autocomplete functions based on the PhpDoc.
The problem is that if a type hint in the @return defined with the fully qualified name of an interface and that method return with the called object (return $this;) then one can't use all the method from the original object just those methods which are come from the interface.

For example:
The ->condition() method is unknown because the ->->addTag() -
according to the Phpdoc - returns an \Drupal\Core\Database\Query\AlterableInterface instance, and it has no condition() method.

/** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
$storage
  ->getQuery()
  ->addTag('xxx')
  ->condition();

Other example:

/** @var \Drupal\Core\Database\Query\SelectInterface $select */
$select
  ->condition()
  ->groupBy();

These are the methods where the @return type hint could be replaced with $this.

  1. interface Drupal\Component\Plugin\ContextAwarePluginInterface::setContextValue
  2. class Drupal\Core\Access\AccessResultAllowed::allowed
  3. class Drupal\Core\Access\AccessResultForbidden::forbidden
  4. class Drupal\Core\Access\AccessResultNeutral::neutral
  5. interface Drupal\Core\Asset\AttachedAssetsInterface::createFromRenderArray
  6. interface Drupal\Core\Config\StorageComparerInterface::reset
  7. interface Drupal\Core\Config\StorageInterface::createCollection
  8. class Drupal\Core\Config\Config::setSettingsOverride
  9. class Drupal\Core\Config\Config::setModuleOverride
  10. class Drupal\Core\Config\Config::setOverriddenData
  11. class Drupal\Core\Config\Config::resetOverriddenData
  12. class Drupal\Core\Config\Config::delete
  13. class Drupal\Core\Config\ConfigImporter::reset
  14. class Drupal\Core\Config\ConfigImporter::import
  15. class Drupal\Core\Config\PreExistingConfigException::create
  16. interface Drupal\Core\Database\Query\ExtendableInterface::extend
  17. interface Drupal\Core\Database\Query\ConditionInterface::condition
  18. interface Drupal\Core\Database\Query\ConditionInterface::where
  19. interface Drupal\Core\Database\Query\ConditionInterface::isNull
  20. interface Drupal\Core\Database\Query\ConditionInterface::isNotNull
  21. interface Drupal\Core\Database\Query\ConditionInterface::exists
  22. interface Drupal\Core\Database\Query\ConditionInterface::notExists
  23. interface Drupal\Core\Database\Query\ConditionInterface::conditionGroupFactory
  24. interface Drupal\Core\Database\Query\ConditionInterface::andConditionGroup
  25. interface Drupal\Core\Database\Query\ConditionInterface::orConditionGroup
  26. class Drupal\Core\Database\Query\Insert::from
  27. class Drupal\Core\Database\Query\Merge::conditionTable
  28. class Drupal\Core\Database\Query\Merge::updateFields
  29. class Drupal\Core\Database\Query\Merge::expression
  30. class Drupal\Core\Database\Query\Merge::insertFields
  31. class Drupal\Core\Database\Query\Merge::useDefaults
  32. class Drupal\Core\Database\Query\Merge::fields
  33. class Drupal\Core\Database\Query\Update::fields
  34. class Drupal\Core\Database\Query\Update::expression
  35. class Drupal\Core\Database\Query\Select::prepareCountQuery
  36. interface Drupal\Core\Database\Query\SelectInterface::distinct
  37. interface Drupal\Core\Database\Query\SelectInterface::fields
  38. interface Drupal\Core\Database\Query\SelectInterface::orderBy
  39. interface Drupal\Core\Database\Query\SelectInterface::orderRandom
  40. interface Drupal\Core\Database\Query\SelectInterface::range
  41. interface Drupal\Core\Database\Query\SelectInterface::union
  42. interface Drupal\Core\Database\Query\SelectInterface::groupBy
  43. interface Drupal\Core\Database\Query\SelectInterface::countQuery
  44. interface Drupal\Core\Database\Query\AlterableInterface::addMetaData
  45. class Drupal\Core\Entity\Query\Sql\QueryAggregate::addAggregate
  46. class Drupal\Core\Entity\Query\Sql\QueryAggregate::compileAggregate
  47. class Drupal\Core\Entity\Query\Sql\QueryAggregate::addGroupBy
  48. class Drupal\Core\Entity\Query\Sql\QueryAggregate::addSortAggregate
  49. class Drupal\Core\Entity\Query\Sql\Query::prepare
  50. class Drupal\Core\Entity\Query\Sql\Query::compile
  51. class Drupal\Core\Entity\Query\Sql\Query::addSort
  52. class Drupal\Core\Entity\Query\Sql\Query::finish
  53. interface Drupal\Core\Entity\Query\ConditionAggregateInterface::condition
  54. interface Drupal\Core\Entity\Query\QueryAggregateInterface::aggregate
  55. interface Drupal\Core\Entity\Query\QueryAggregateInterface::groupBy
  56. interface Drupal\Core\Entity\Query\QueryAggregateInterface::conditionAggregate
  57. interface Drupal\Core\Entity\Query\QueryAggregateInterface::existsAggregate
  58. interface Drupal\Core\Entity\Query\QueryAggregateInterface::notExistsAggregate
  59. interface Drupal\Core\Entity\Query\QueryAggregateInterface::sortAggregate
  60. interface Drupal\Core\Entity\Query\QueryInterface::condition
  61. interface Drupal\Core\Entity\Query\QueryInterface::exists
  62. interface Drupal\Core\Entity\Query\QueryInterface::notExists
  63. interface Drupal\Core\Entity\Query\QueryInterface::pager
  64. interface Drupal\Core\Entity\Query\QueryInterface::range
  65. interface Drupal\Core\Entity\Query\QueryInterface::sort
  66. interface Drupal\Core\Entity\Query\QueryInterface::count
  67. interface Drupal\Core\Entity\Query\QueryInterface::tableSort
  68. interface Drupal\Core\Entity\Query\QueryInterface::accessCheck
  69. interface Drupal\Core\Entity\EntityConstraintViolationListInterface::getEntityViolations
  70. interface Drupal\Core\Entity\EntityConstraintViolationListInterface::getByFields
  71. class Drupal\Core\Field\Entity\BaseFieldOverride::createFromBaseFieldDefinition
  72. interface Drupal\Core\Field\FieldConfigInterface::getConfig
  73. class Drupal\Core\Form\EnforcedResponse::createFromException
  74. interface Drupal\Core\Archiver\ArchiverInterface::add
  75. interface Drupal\Core\Archiver\ArchiverInterface::remove
  76. interface Drupal\Core\Archiver\ArchiverInterface::extract
  77. class Drupal\Core\Cache\BackendChain::appendBackend
  78. class Drupal\Core\Cache\BackendChain::prependBackend
  79. interface Drupal\Core\ImageToolkit\ImageToolkitInterface::setSource
  80. interface Drupal\Core\Language\LanguageManagerInterface::reset
  81. interface Drupal\Core\Menu\LocalTaskInterface::setActive
  82. interface Drupal\Core\Session\AccountSwitcherInterface::switchTo
  83. interface Drupal\Core\Session\AccountSwitcherInterface::switchBack
  84. class Drupal\Core\StringTranslation\PluralTranslatableMarkup::createFromTranslatedString
  85. interface Drupal\Core\TypedData\TraversableTypedDataInterface::getParent
  86. interface Drupal\Core\TypedData\TraversableTypedDataInterface::getRoot
  87. interface Drupal\Core\TypedData\TypedDataInterface::applyDefaultValue
  88. class Drupal\Core\TypedData\ListDataDefinition::create
  89. class Drupal\Core\Updater\Updater::factory
  90. class Drupal\Core\Url::fromRoute
  91. class Drupal\Core\Url::fromUri
  92. class Drupal\Core\Url::fromEntityUri
  93. class Drupal\Core\Url::fromInternalUri
  94. class Drupal\Core\Url::fromRouteUri
  95. interface Drupal\block_content\BlockContentInterface::setInfo
  96. interface Drupal\block_content\BlockContentInterface::setRevisionLog
  97. interface Drupal\block_content\BlockContentInterface::setTheme
  98. interface Drupal\comment\CommentInterface::getParentComment
  99. interface Drupal\image\ImageStyleInterface::setName
  100. interface Drupal\locale\StringStorageInterface::save
  101. interface Drupal\locale\StringStorageInterface::delete
  102. class Drupal\locale\TranslationString::setCustomized
  103. interface Drupal\node\NodeInterface::setTitle
  104. interface Drupal\node\NodeInterface::setCreatedTime
  105. interface Drupal\node\NodeInterface::setPromoted
  106. interface Drupal\node\NodeInterface::setSticky
  107. interface Drupal\node\NodeInterface::setRevisionCreationTime
  108. interface Drupal\node\NodeInterface::setRevisionAuthorId
  109. interface Drupal\search\Plugin\SearchInterface::setSearch
  110. interface Drupal\shortcut\ShortcutInterface::setTitle
  111. interface Drupal\shortcut\ShortcutInterface::setWeight
  112. interface Drupal\shortcut\ShortcutSetInterface::resetLinkWeights
  113. class Drupal\system\Plugin\ImageToolkit\GDToolkit::setResource
  114. interface Drupal\user\UserInterface::setUsername
  115. interface Drupal\user\UserInterface::setPassword
  116. interface Drupal\user\UserInterface::setEmail
  117. interface Drupal\user\UserInterface::setLastAccessTime
  118. interface Drupal\user\UserInterface::setLastLoginTime
  119. interface Drupal\user\UserInterface::activate
  120. interface Drupal\user\UserInterface::block
  121. interface Drupal\views\Plugin\views\display\DisplayRouterInterface::getRoutedDisplay

Viewing all articles
Browse latest Browse all 301314

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>