0

I have an array that represents some mapping between strings. The key and the value both have (business) meaning. For example, in the array:

[
    '10000' => 'f4970340-9cb7-4380-948c-54e0d1556d58',
    '20000' => '665cdd7d-dbef-4c0a-963e-467a68fa097f',
    '84000' => '5b7f0abc-a515-4409-8b70-f1aafeef5038',
    … # more entries
]

10000, 20000 and 84000 represent customers. The UUIDs represent groups to which the customers belong.

Is there any convention / best-practice of how to document the meaning of the strings? I am not talking about documenting the types (=strings).

Something like:

    /**
     * @return string[]
     * [
     *     customerId => groupId,
     *     …
     * ]
     */
    public function getCustomerIdGroupIdMap(): array
    {}

1 Answer 1

1

In all the cases I've seen and used, the text description is the best place to add specific notes to clarify the details.

<?php

/**
 * Returns an array keyed by the customer ID. The values represent the group ID. 
 * @return array
 */
public function getCustomerIdGroupIdMap(): array
{}

Alternatively, using the description of the return type can be used.

<?php

/**
 * @return array Keyed by the customer ID. The values represent the group ID. 
 */
public function getCustomerIdGroupIdMap(): array
{}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.