I'd like to learn how to do this for my projects as well, if nothing else for my own sanity when using VSCode, do you have any resources for the correct way to implement this?Any chance the entities could be anointed with @property phpdocs so all the various magic methods show up via various IDE's auto-complete?
This is likely a large, but simple, task.
https://docs.phpdoc.org/references/phpdoc/tags/property.htmlI'd like to learn how to do this for my projects as well, if nothing else for my own sanity when using VSCode, do you have any resources for the correct way to implement this?
Fillip
/**
* @property string $myProperty
*/
class class
{
public function __get()
{
<...>
}
}
getTitle()
function, I should add @property string $title
to the top docblock?Yup, exactly.Do you mean to say that if I have an entity with a getTitle() function, I should add @property string $title to the top docblock?
XF\Widget\Entity
class where we've type hinted a known column (options), a getter (handler) and a relation (WidgetDefinition)./**
* @property int $user_id
* @property string $username
* @property string $email
* @property int $style_id
* @property int $language_id
* @property string $timezone
* @property bool $visible
* @property bool $activity_visible
* @property int $user_group_id
* @property array $secondary_group_ids
* @property int $display_style_group_id
* @property int $permission_combination_id
* @property int $message_count
* @property int $alerts_unread
* @property int $conversations_unread
* @property int $register_date
* @property int $last_activity
* @property int $trophy_points
* @property int $avatar_date
* @property int $avatar_width
* @property int $avatar_height
* @property bool $avatar_highdpi
* @property string $gravatar
* @property string $user_state
* @property bool $is_moderator
* @property bool $is_admin
* @property bool $is_staff
* @property bool $is_banned
* @property int $like_count
* @property string $custom_title
* @property int $warning_points
* @property string $secret_key
* @property int $xfrm_resource_count
* @property int $xfmg_album_count
* @property int $xfmg_media_count
* @property int $xfmg_media_quota
* @property string $vanity_name
* @property int $liamw_threadsolutions_solution_count
* @property mixed PermissionSet
* @property mixed is_super_admin
* @property mixed email_confirm_key
* @property mixed warning_count
* @property \XF\Entity\Admin Admin
* @property \XF\Entity\UserAuth Auth
* @property \XF\Entity\UserConnectedAccount ConnectedAccounts
* @property \XF\Entity\UserOption Option
* @property \XF\Entity\PermissionCombination PermissionCombination
* @property \XF\Entity\UserProfile Profile
* @property \XF\Entity\UserPrivacy Privacy
* @property \XF\Entity\UserBan Ban
* @property \XF\Entity\UserReject Reject
* @property \XF\Entity\SessionActivity Activity
* @property \XF\Entity\ApprovalQueue ApprovalQueue
* @property \XF\Entity\UserFollow Following
*/
/**
* COLUMNS
* @property int|null $user_id
* @property string $username
* @property string $email
* @property int $style_id
* @property int $language_id
* @property string $timezone
* @property bool $visible
* @property bool $activity_visible
* @property int $user_group_id
* @property array $secondary_group_ids
* @property int $display_style_group_id
* @property int $permission_combination_id
* @property int $message_count
* @property int $alerts_unread
* @property int $conversations_unread
* @property int $register_date
* @property int $last_activity
* @property int $trophy_points
* @property int $avatar_date
* @property int $avatar_width
* @property int $avatar_height
* @property bool $avatar_highdpi
* @property string $gravatar
* @property string $user_state
* @property bool $is_moderator
* @property bool $is_admin
* @property bool $is_staff
* @property bool $is_banned
* @property int $like_count
* @property string $custom_title
* @property int $warning_points
* @property string $secret_key
* @property int $permission_combination_id_
* @property int $last_activity_
*
* GETTERS
* @property \XF\PermissionSet $PermissionSet
* @property bool $is_super_admin
* @property string $email_confirm_key
* @property int $warning_count
*
* RELATIONS
* @property \XF\Entity\Admin $Admin
* @property \XF\Entity\UserAuth $Auth
* @property \XF\Entity\UserConnectedAccount[] $ConnectedAccounts
* @property \XF\Entity\UserOption $Option
* @property \XF\Entity\PermissionCombination $PermissionCombination
* @property \XF\Entity\UserProfile $Profile
* @property \XF\Entity\UserPrivacy $Privacy
* @property \XF\Entity\UserBan $Ban
* @property \XF\Entity\UserReject $Reject
* @property \XF\Entity\SessionActivity $Activity
* @property \XF\Entity\ApprovalQueue $ApprovalQueue
* @property \XF\Entity\UserFollow[] $Following
*/
I was bored last night too...
Obviously this was an open bug report so until we say otherwise there's every danger that we'd have implemented it (which we have for the next release).PHP:/** * COLUMNS * @property int|null $user_id * @property string $username * @property string $email * @property int $style_id * @property int $language_id * @property string $timezone * @property bool $visible * @property bool $activity_visible * @property int $user_group_id * @property array $secondary_group_ids * @property int $display_style_group_id * @property int $permission_combination_id * @property int $message_count * @property int $alerts_unread * @property int $conversations_unread * @property int $register_date * @property int $last_activity * @property int $trophy_points * @property int $avatar_date * @property int $avatar_width * @property int $avatar_height * @property bool $avatar_highdpi * @property string $gravatar * @property string $user_state * @property bool $is_moderator * @property bool $is_admin * @property bool $is_staff * @property bool $is_banned * @property int $like_count * @property string $custom_title * @property int $warning_points * @property string $secret_key * @property int $permission_combination_id_ * @property int $last_activity_ * * GETTERS * @property \XF\PermissionSet $PermissionSet * @property bool $is_super_admin * @property string $email_confirm_key * @property int $warning_count * * RELATIONS * @property \XF\Entity\Admin $Admin * @property \XF\Entity\UserAuth $Auth * @property \XF\Entity\UserConnectedAccount[] $ConnectedAccounts * @property \XF\Entity\UserOption $Option * @property \XF\Entity\PermissionCombination $PermissionCombination * @property \XF\Entity\UserProfile $Profile * @property \XF\Entity\UserPrivacy $Privacy * @property \XF\Entity\UserBan $Ban * @property \XF\Entity\UserReject $Reject * @property \XF\Entity\SessionActivity $Activity * @property \XF\Entity\ApprovalQueue $ApprovalQueue * @property \XF\Entity\UserFollow[] $Following */
You may still want to use your own version, though. Ours, by design, only adds class properties for the structure of the original class (so it bypasses structure extensions). There's a few other improvements in that it attempts to type hint getter function types and maintains the original column type if a getter overlaps it.
@property \XF\Entity\UserProfile Profile
@property \XF\Entity\UserProfile $Profile
The documentation doesn't actually describe it as required. Even the eventually linked to php-fig document doesn't either; https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc-tags.md#510-propertyI've noticed that PHPStan expects property names to be prefixed with a dollar sign which is how @property is documented on the PHPDoc website, too. XenForo's PHPDoc syntax seems to be wrong at first glance (I'm not an expert on this subject).
@property[<-read|-write>] ["Type"] [name] [<description>]
It was already done as of this message yesterdayThat said, this isn't a huge change as the properties are written automatically. I don't see a particular reason not to do it if it helps other software parse the properties correctly.
We use essential cookies to make this site work, and optional cookies to enhance your experience.