[php] All possible combinations of function arguments
#1

Hi guys, I'm building cool tool (which I'll be releasing on github soon), and I need some help with catching all corner cases.

PHP код:
protected function setDefaultOptions(OptionsResolverInterface $resolver)
{
    
$resolver->setRequired(array(
        
'name',
    ));
    
$resolver->setDefaults(array(
        
'tag' => null,
        
'reference' => false,
        
'arrayDimension' => 0,
        
'arrayEnumerator' => array(),
        
'default' => null,
        
'operator' => null,
    ));
    
$resolver->setAllowedTypes(array(
        
'reference' => 'boolean',
        
//'tag' => '', @TODO
        
'arrayDimension' => 'int',
        
'arrayEnumerator' => 'array',
        
'operator' => 'array',
    ));
    
$resolver->setAllowedValues(array(
        
'arrayDimension' => range(03),
        
//'arrayEnumerator' => array(), @TODO
        
'operator' => array('const''sizeof''tagof'),
    ));
    
$resolver->setNormalizers(array(
        
'reference' => function (Options $options$value) {
            
//If array dimensions are passed, it's a constant, or sizeof/tagof, the value is or cannot be passed by reference
            
return empty($options['operator']);
        },
        
'arrayDimension'  => function (Options $options$value) {
            
$numberOfEnumerators count($options['arrayEnumerator']);
            return 
max(array($numberOfEnumerators$value));
        },
    ));

This code tries to check all possible argument combinations.

pawn Код:
Float:Value = 5.0
CUSTOM_TAG:Something[CUSTOM_SOMETHING][][]
&number
const somestring[]
tagof something
We are talking about valid pawn code, and not about macro substitutions (using <> and other things).
Now, except for elipsis, I think that covers a most of possible stuff. Did I miss something?
Reply


Messages In This Thread
[php] All possible combinations of function arguments - by Misiur - 18.07.2013, 17:50

Forum Jump:


Users browsing this thread: 1 Guest(s)