Exemplo n.º 1
0
 /**
  * Checks the parameters of the call against the given ones
  *
  * @param PC_Obj_Call $call the call
  * @param PC_Obj_Method $method the method
  */
 private function check_params($call, $method)
 {
     $arguments = $call->get_arguments();
     $nparams = $method->get_required_param_count();
     $nmaxparams = $method->get_param_count();
     if (count($arguments) < $nparams || $nmaxparams >= 0 && count($arguments) > $nmaxparams) {
         if ($nparams != $nmaxparams) {
             $reqparams = $nparams . ' to ' . ($nmaxparams == -1 ? '*' : $nmaxparams);
         } else {
             $reqparams = $nparams;
         }
         $this->report($call, 'The function/method called by "' . $this->get_call_link($call) . '" requires ' . $reqparams . ' arguments but you have given ' . count($arguments), PC_Obj_Error::E_S_WRONG_ARGUMENT_COUNT);
     } else {
         $i = 0;
         foreach ($method->get_params() as $param) {
             /* @var $param PC_Obj_Parameter */
             $arg = isset($arguments[$i]) ? $arguments[$i] : null;
             // arg- or param-type unknown?
             if ($arg === null || $arg->is_unknown() || $param->get_mtype()->is_unknown()) {
                 $i++;
                 continue;
             }
             if (!$this->is_argument_ok($call, $arg, $param)) {
                 $trequired = $param->get_mtype();
                 $tactual = $arg;
                 $this->report($call, 'The parameter ' . ($i + 1) . ' in "' . $this->get_call_link($call) . '" requires ' . $this->get_article($trequired) . ' "' . $trequired . '" but you have given ' . $this->get_article($tactual) . ' "' . ($tactual === null ? "<i>NULL</i>" : $tactual) . '"', PC_Obj_Error::E_S_WRONG_ARGUMENT_TYPE);
             }
             $i++;
         }
     }
 }