cloudflare-php icon indicating copy to clipboard operation
cloudflare-php copied to clipboard

Strict PHP Return types not correct for DNS getRecordID()

Open paulgoodchild opened this issue 5 years ago • 2 comments

In DNS.php, the function getRecordID is declared with return type string, but returns false.

Can we change this to either empty string, or throw and exception instead of having conflicting return types?

    public function getRecordID(string $zoneID, string $type = '', string $name = ''): string
    {
        $records = $this->listRecords($zoneID, $type, $name);
        if (isset($records->result[0]->id)) {
            return $records->result[0]->id;
        }
        return false;
    }

could change final lines to:

            return $records->result[0]->id ?? : '';

paulgoodchild avatar Jul 04 '20 10:07 paulgoodchild

Hello @paulgoodchild The type error is not a fatal if not in strict mode. However, I agree there should be an exception instead, so I created pull request: https://github.com/cloudflare/cloudflare-php/pull/146

I would like consistency on the SDK since this method seems to not follow the pattern.

spenserhale avatar Oct 01 '20 19:10 spenserhale

Hi @phily245 Can you please check https://github.com/cloudflare/cloudflare-php/pull/146

The Cloudflare\API\Endpoints\DNS class has serval return type issues.

For example getRecordDetails should return an stdClass but if the $recordID is a empty string it returns an array.

It should perform a GET request on https://api.cloudflare.com/client/v4/zones/{zone_identifier}/dns_records/{identifier} to get the DNS Record Details. Without the recordID the request goes to https://api.cloudflare.com/client/v4/zones/{zone_identifier}/dns_records/ (List DNS Records) which returns an array.

DimaVIII avatar Jul 20 '23 11:07 DimaVIII