Previous General Totara Learn discussions (read only)

Codechecker and member variables

 
Easter Island / Rapa Nui
Codechecker and member variables
door Russell England - Thursday, 19 June 2014, 05:20 AM
 

If I have something like this in a lib.php

global $BLOCK_MYBLOCK_STATUS;
$BLOCK_MYBLOCK_STATUS = array(
    BLOCK_MYBLOCK_REQUESTED => 'status_requested',
    BLOCK_MYBLOCK_STATUS_APPROVED => 'status_approved',
    BLOCK_MYBLOCK_STATUS_REJECTED => 'status_rejected',
    BLOCK_MYBLOCK_STATUS_ENDED => 'status_ended'
);

Then have a function like this

function block_myblock_getstatus($status) {
    global $BLOCK_MYBLOCK_STATUS;
    return $BLOCK_MYBLOCK_STATUS[$status];
}

Then run the Totara codecheck, I get this error

error line xxx col xx Member variable \"BLOCK_MYBLOCK_STATUS\" must be all lower-case

Anyway around this?

Cheers, Russ

Simon Coggins
Re: Codechecker and member variables
door Simon Coggins - Thursday, 19 June 2014, 20:52 PM
Groep Totara

Hi Russ,

We normally just ignore those errors, it's just because moodle coding style requires lower-case variables, but in cases where you are defining globals it is better to use uppercase.

I suppose you could change the codesniffer library rules but then you would miss warnings when you have incorrectly used upper-case in variable names.

Simon

Easter Island / Rapa Nui
Re: Codechecker and member variables
door Russell England - Sunday, 22 June 2014, 23:58 PM
 

Cheers Simon :)