Esempio n. 1
0
 /**
  * Casts given value from a PHP type to one acceptable by database
  *
  * @param mixed $value value to be converted to database equivalent
  * @return mixed
  */
 public function toDatabase($value)
 {
     if ($value === null || $value === '') {
         return null;
     }
     return parent::toDatabase($value);
 }
Esempio n. 2
0
 public function testFromStringWithStringArrayArray()
 {
     $arrayType = MixedType::fromString("string[][]");
     $this->assertInstanceOf("Skrz\\Meta\\Reflection\\ArrayType", $arrayType);
     $this->assertInstanceOf("Skrz\\Meta\\Reflection\\ArrayType", $arrayType->getBaseType());
     /** @var ArrayType $baseType */
     $baseType = $arrayType->getBaseType();
     $this->assertSame(StringType::getInstance(), $baseType->getBaseType());
     $this->assertSame($arrayType, MixedType::fromString("string[][]"));
 }
Esempio n. 3
0
 /**
  * @param Node $node
  * A node to check types on
  *
  * @return UnionType
  * The resulting type(s) of the binary operation
  */
 public function visitBinaryConcat(Node $node) : UnionType
 {
     return StringType::instance()->asUnionType();
 }
Esempio n. 4
0
 /**
  * @dataProvider providerForNotString
  */
 public function testNotString($input)
 {
     $rule = new StringType();
     $this->assertFalse($rule->validate($input));
 }
Esempio n. 5
0
 /**
  * Checks if a number is in a range
  *
  * @param integer $num   number to check for
  * @param integer $lower lower bound
  * @param integer $upper upper bound
  *
  * @return boolean  whether the number is in the range or not
  */
 public function numberInRangeInclusive($num, $lower, $upper)
 {
     return $this->_type->numberInRangeInclusive($num, $lower, $upper);
 }
Esempio n. 6
0
 /**
  * Visit a node with kind `\ast\AST_CLASS_CONST`
  *
  * @param Node $node
  * A node of the type indicated by the method name that we'd
  * like to figure out the type that it produces.
  *
  * @return UnionType
  * The set of types that are possibly produced by the
  * given node
  */
 public function visitClassConst(Node $node) : UnionType
 {
     $constant_name = $node->children['const'];
     if ($constant_name == 'class') {
         return StringType::instance()->asUnionType();
         // class name fetch
     }
     try {
         $defining_clazz = AST::classFromNodeInContext($node, $this->context, $this->code_base, false);
     } catch (CodeBaseException $exception) {
         $class_name = $node->children['class']->children['name'] ?? '';
         Log::err(Log::EUNDEF, "Can't access constant {$constant_name} from undeclared class {$class_name}", $this->context->getFile(), $node->lineno);
         return new UnionType();
     } catch (NodeException $exception) {
         $class_name = $node->children['class']->children['name'] ?? '';
         Log::err(Log::EUNDEF, "Can't access constant {$constant_name} from undeclared class {$class_name}", $this->context->getFile(), $node->lineno);
         // If we can't figure out what kind of a call
         // this is, don't worry about it
         return new UnionType();
     }
     if (!$defining_clazz->hasConstantWithName($this->code_base, $constant_name)) {
         Log::err(Log::EUNDEF, "Can't access undeclared constant {$defining_clazz->getName()}::{$constant_name}", $this->context->getFile(), $node->lineno);
         return new UnionType();
     }
     return $defining_clazz->getConstantWithName($this->code_base, $constant_name)->getUnionType();
 }
 public function highlightCode($cppCodeString, $title = "")
 {
     $braceTracer = new BraceTrace();
     $cppCode = new CppCode($cppCodeString, $title);
     if ($this->buildLines) {
         $cppCode->lines = array();
     }
     if ($this->buildFormattedLines) {
         $cppCode->formattedLines = array();
     }
     // Following variables are declared in settings.php file
     global $fontSizeInPt;
     global $MAXIMUM_CHARS_PER_LINE;
     global $cppKeywords;
     //refers to C++ standard keywordr
     global $nokiaQtClasses;
     //refers to Nokia Qt classes
     global $gtkPlusClasses;
     //refers to GTK+ classes
     global $wxWidgetsClasses;
     //refers to wxWidgets classes
     global $braceTraceStart;
     global $braceTraceEnd;
     global $ignoreMaxCharsForStrings;
     $showLineNumber = $this->showLineNumber;
     $supportNokiaQtClasses = $this->supportNokiaQtClasses;
     $supportGtkPlusClasses = $this->supportGtkPlusClasses;
     $supportWxWidgetsClasses = $this->supportWxWidgetsClasses;
     $supportBraceTrace = $this->supportBraceTrace;
     $in_char_block = false;
     //identifies if current character is inside single quote block
     $in_comment_block = false;
     //identifies if current character is inside /**/  block
     $in_single_line_comment = false;
     //identifies if current character is inside //  block
     $in_string_block = false;
     //identifies if current character is inside double quote block
     $output = "<pre class='Code'>";
     //initialize output
     if ($cppCode->title != "") {
         $output .= "<center><table class='Title'><tr><td align=center>{$cppCode->title}</td></tr></table></center>";
     }
     $output .= "<table><tr><td><table border=0>";
     $lines = explode("\n", $cppCodeString);
     //break cppCodeString by lines
     $currLine = 1;
     foreach ($lines as &$thisLine) {
         //you may use buildLines to not push $thisLine to $cppCode->lines in order to save memory if you like
         if ($this->buildLines) {
             array_push($cppCode->lines, $thisLine);
         }
         $spaceAdded = false;
         $currFormattedLine = "<tr id='" . substr(md5($title), 0, 4) . "-line{$currLine}-c'>";
         if ($showLineNumber) {
             $currFormattedLine .= "<td class='Line-TD' align='right'><span class='Line'><font size={$fontSizeInPt}><a name='" . substr(md5($title), 0, 4) . "-line{$currLine}'>" . $currLine . "</a></font></span></td>";
             //Add an extra space for better code reading
             $currFormattedLine .= "<td>&nbsp;</td>";
         }
         $currFormattedLine .= "<td align='left'><font size={$fontSizeInPt}>";
         if (!$showLineNumber) {
             $currFormattedLine .= "<a name='" . substr(md5($title), 0, 4) . "-line{$currLine}'>";
         }
         if (trim($thisLine) == "") {
             $currFormattedLine .= "&nbsp;";
         }
         if ($in_comment_block) {
             $currFormattedLine .= "<span class='Comment'>";
         }
         $i = 0;
         $n = 0;
         $nCol = 0;
         for ($i = 0; $i < strlen($thisLine); $i++) {
             if ($nCol > $MAXIMUM_CHARS_PER_LINE) {
                 if (($in_string_block || $in_char_block) && $ignoreMaxCharsForStrings) {
                     //we are in string block and ignoring condition because of ignoreMaxCharsForStrings flag
                 } else {
                     //break line if maximum characters reached
                     $currFormattedLine .= '<br/>';
                     $nCol = 0;
                 }
             }
             //checks each character in line and transform every character accordingly
             switch ($thisLine[$i]) {
                 case ' ':
                     $currFormattedLine .= "&nbsp;";
                     //converts each <space> with &nbsp;
                     $nCol++;
                     //next column
                     break;
                 case '<':
                     $currFormattedLine .= "&lt;";
                     //converts < to &lt;
                     $nCol++;
                     //next column
                     break;
                 case '>':
                     $currFormattedLine .= "&gt;";
                     //converts > to &gt;
                     $nCol++;
                     //next column
                     break;
                 case '&':
                     $currFormattedLine .= "&amp;";
                     //converts & to &amp;
                     $nCol++;
                     //next column
                     break;
                 case '\\t':
                     $n = 4;
                     //converts \t to 4 &nbsp;
                     $nCol += $n;
                     //4 columns added
                     for (; $n > 0; $n--) {
                         $currFormattedLine .= "&nbsp;";
                     }
                     break;
                 case '\\':
                     if ($i > 0 && $thisLine[$i - 1] == '\\') {
                         $thisLine[$i] = " ";
                     }
                     $currFormattedLine .= "\\";
                     $nCol++;
                     break;
                 case '/':
                     /*this is complex case. we have mulitple conditions.
                           1. /*
                           2. //
                           3. "something/with/slash/in/quotes"
                           4. '/'
                       */
                     if (!$in_comment_block && !$in_string_block && !$in_single_line_comment && !$in_char_block) {
                         //if none of above condition is not true then check next character, if it is "/" then it is single line comment
                         if ($thisLine[$i + 1] == '/') {
                             $in_single_line_comment = true;
                             $currFormattedLine .= "<span class='Comment'>";
                         } else {
                             if ($thisLine[$i + 1] == '*') {
                                 $currFormattedLine .= "<span class='Comment'>";
                                 $in_comment_block = true;
                             }
                         }
                     } else {
                         if ($in_comment_block) {
                             //if it was in comment block i.e, /* then ignore everything until we found *
                             if ($i > 0 && $thisLine[$i - 1] == '*') {
                                 //close comment block because we are in / switch case
                                 $currFormattedLine .= "/</span>";
                                 $nCol++;
                                 $in_comment_block = false;
                                 break;
                             }
                         }
                     }
                     //add / to output
                     $currFormattedLine .= "/";
                     //next column
                     $nCol++;
                     break;
                 case '\'':
                     if (!$in_string_block && !$in_comment_block && !$in_single_line_comment) {
                         //if above flags are not set then check to see if previous character was \ if yes then simply add single quote to output
                         //example:        'test comment \' and this '
                         //in above example \' has to be inside quotes and should not break highlighting
                         if ($i > 0 && $thisLine[$i - 1] == '\\') {
                             $currFormattedLine .= "&#39;";
                         } else {
                             //reverse it, because it means end the quote
                             $in_char_block = !$in_char_block;
                             //if now character block has started add "span" for string
                             if ($in_char_block) {
                                 $currFormattedLine .= "<span class='String'>&#39;";
                                 //notice &#39; that means add ' inside span
                             } else {
                                 //otherwise end span, notice &#39; just before </span>
                                 $currFormattedLine .= "&#39;</span>";
                             }
                         }
                     } else {
                         //if it's in string block " or comment block /* or single line comment // then simply add single quote
                         $currFormattedLine .= "&#39;";
                     }
                     $nCol++;
                     //next column
                     break;
                 case "\"":
                     if (!$in_char_block && !$in_comment_block && !$in_single_line_comment) {
                         //if its not in character block ' not in comment block /* or not in single line comment //
                         //then do the same thing as above, check the previous character.
                         //example, "test\"this"
                         //in above example, it will print "test\"this" as is
                         if ($i > 0 && $thisLine[$i - 1] == '\\') {
                             $currFormattedLine .= "&quot;";
                         } else {
                             //reverse the flag
                             $in_string_block = !$in_string_block;
                             if ($in_string_block) {
                                 //if after reverse, its in its in string block, then add <span>
                                 $currFormattedLine .= "<span class='String'>&quot;";
                             } else {
                                 //otherwise end the span
                                 $currFormattedLine .= "&quot;</span>";
                             }
                         }
                     } else {
                         $currFormattedLine .= "&quot;";
                         //if its in char block or comment block or single line block then simply add quote
                     }
                     $nCol++;
                     break;
                 default:
                     //for all other cases there are posibilities:
                     //next chracter is digit
                     //next chracter or letter is special class
                     //next character or letter is special keywords (C++ keyword)
                     if (!$in_char_block && !$in_comment_block && !$in_single_line_comment && !$in_string_block) {
                         if ($supportBraceTrace) {
                             if (in_array($thisLine[$i], $braceTraceStart)) {
                                 $nCol++;
                                 $currFormattedLine .= $braceTracer->getStartMarkup(substr(md5($title), 0, 4), $currLine, $nCol, $thisLine[$i]);
                                 break;
                             }
                             if (in_array($thisLine[$i], $braceTraceEnd)) {
                                 $nCol++;
                                 $currFormattedLine .= $braceTracer->getEndMarkup($thisLine[$i]);
                                 break;
                             }
                         }
                         if (StringType::isdigit($thisLine[$i])) {
                             //if it's digit
                             $word_arr = array();
                             for ($j = 0; StringType::isalnum($thisLine[$i + $j]) || $thisLine[$i + $j] == '.'; $j++) {
                                 $word_arr[$j] = $thisLine[$i + $j];
                             }
                             $i += $j - 1;
                             $nCol += $j;
                             $wd = implode("", $word_arr);
                             $currFormattedLine .= "<span class='Number'>{$wd}</span>";
                             break;
                         }
                         if (StringType::isalpha($thisLine[$i]) || $thisLine[$i] == '#' || $thisLine[$i] == '_') {
                             $word_arr = array();
                             for ($j = 0; StringType::isalnum($thisLine[$i + $j]) || $thisLine[$i + $j] == '#' || $thisLine[$i + $j] == '_'; $j++) {
                                 $word_arr[$j] = $thisLine[$i + $j];
                             }
                             $i += $j - 1;
                             $nCol += $j;
                             $wd = implode("", $word_arr);
                             //if word is one of $keywords array
                             if (in_array($wd, $cppKeywords)) {
                                 $currFormattedLine .= "<span class='Keyword'>" . htmlentities($wd) . "</span>";
                             } else {
                                 //if word is one of $nokiaQtClasses array
                                 if (in_array($wd, $nokiaQtClasses)) {
                                     if ($supportNokiaQtClasses) {
                                         $currFormattedLine .= "<span class='SpecialClass'><a href='" . getNokiaQtClassUrl($wd) . "' class='SpecialClass'>" . htmlentities($wd) . "</a></span>";
                                     } else {
                                         $currFormattedLine .= htmlentities("{$wd}");
                                     }
                                 } else {
                                     if (in_array($wd, $gtkPlusClasses)) {
                                         if ($supportGtkPlusClasses) {
                                             $currFormattedLine .= "<span class='SpecialClass'><a href='" . getGtkPlusClassUrl($wd) . "' class='SpecialClass'>" . htmlentities($wd) . "</a></span>";
                                         } else {
                                             $currFormattedLine .= htmlentities("{$wd}");
                                         }
                                     } else {
                                         if (in_array($wd, $wxWidgetsClasses)) {
                                             if ($supportWxWidgetsClasses) {
                                                 $currFormattedLine .= "<span class='SpecialClass'><a href='" . getWxWidgetsClassUrl($wd) . "' class='SpecialClass'>" . htmlentities($wd) . "</a></span>";
                                             } else {
                                                 $currFormattedLine .= htmlentities("{$wd}");
                                             }
                                         } else {
                                             $currFormattedLine .= htmlentities("{$wd}");
                                         }
                                     }
                                 }
                             }
                             break;
                         }
                     }
                     $currFormattedLine .= htmlentities($thisLine[$i]);
                     $nCol++;
                     break;
             }
         }
         if ($in_single_line_comment) {
             //if single line comment and because this is end of line, so end single line comment and end flag
             $currFormattedLine .= "</span>";
             $in_single_line_comment = false;
         }
         if ($this->buildFormattedLines) {
             //push current formatted line ($currFormattedLine) to formattedLines array
             //but note: this is what's used later in getLines($start,$end) function.
             array_push($cppCode->formattedLines, $currFormattedLine);
         }
         if (!$showLineNumber) {
             $currFormattedLine .= "</a>";
         }
         $currFormattedLine .= "</font>";
         $output .= $currFormattedLine;
         $currLine++;
         //next line
     }
     if ($in_char_block || $in_string_block) {
         //if it is in char block or string block then end this before string/char block after parsing finished
         $currFormattedLine .= "</span>";
         if ($this->buildFormattedLines) {
             //append ending </span> to current line in formattedLines array
             $cppCode->formattedLines[$currLines - 1] = $cppCode->formattedLines[$currLines - 1] . $currFormattedLine;
         }
         $output .= $currFormattedLine;
     }
     if ($in_comment_block) {
         //if it is in comment block end this block after parsing finished
         $currFormattedLine .= "</span>";
         if ($this->buildFormattedLines) {
             //append ending </span> to current line in formattedLines array
             $cppCode->formattedLines[$currLines - 1] = $cppCode->formattedLines[$currLines - 1] . $currFormattedLine;
         }
         $output .= $currFormattedLine;
     }
     $output .= "</font></td></tr></table></td></tr></table></pre>";
     //final output
     $cppCode->formattedCode = $output;
     return $cppCode;
 }
Esempio n. 8
0
 /**
  * Visit a node with kind `\ast\AST_METHOD`
  *
  * @param Node $node
  * A node to parse
  *
  * @return Context
  * A new or an unchanged context resulting from
  * parsing the node
  */
 public function visitMethod(Node $node) : Context
 {
     // Bomb out if we're not in a class context
     $clazz = $this->getContextClass();
     $method_name = $node->name;
     $method_fqsen = FullyQualifiedMethodName::fromStringInContext($method_name, $this->context);
     // Hunt for an available alternate ID if necessary
     $alternate_id = 0;
     while ($this->code_base->hasMethod($method_fqsen)) {
         $method_fqsen = $method_fqsen->withAlternateId(++$alternate_id);
     }
     $method = Method::fromNode(clone $this->context, $this->code_base, $node);
     // Override the FQSEN with the found alternate ID
     $method->setFQSEN($method_fqsen);
     $clazz->addMethod($this->code_base, $method);
     if ('__construct' === $method_name) {
         $clazz->setIsParentConstructorCalled(false);
     } else {
         if ('__invoke' === $method_name) {
             $clazz->getUnionType()->addType(CallableType::instance());
         } else {
             if ('__toString' === $method_name) {
                 $clazz->getUnionType()->addType(StringType::instance());
             }
         }
     }
     // Send the context into the method
     $context = $this->context->withMethodFQSEN($method->getFQSEN());
     // Add each method parameter to the scope. We clone it
     // so that changes to the variable don't alter the
     // parameter definition
     foreach ($method->getParameterList() as $parameter) {
         $context->addScopeVariable(clone $parameter);
     }
     return $context;
 }
Esempio n. 9
0
 /**
  * Check to see if the given Clazz is a duplicate
  *
  * @param Method $method
  * The method we're analyzing arguments for
  *
  * @param Node $node
  * The node holding the method call we're looking at
  *
  * @param Context $context
  * The context in which we see the call
  *
  * @param CodeBase $code_base
  *
  * @return null
  *
  * @see \Phan\Deprecated\Pass2::arg_check
  * Formerly `function arg_check`
  */
 private static function analyzeInternalArgumentType(Method $method, Node $node, Context $context, CodeBase $code_base)
 {
     $arglist = $node->children['args'];
     $argcount = count($arglist->children);
     switch ($method->getName()) {
         case 'join':
         case 'implode':
             // (string glue, array pieces),
             // (array pieces, string glue) or
             // (array pieces)
             if ($argcount == 1) {
                 self::analyzeNodeUnionTypeCast($arglist->children[0], $context, $code_base, ArrayType::instance()->asUnionType(), "arg#1(pieces) is %s but {$method->getFQSEN()}() takes array when passed only 1 arg");
                 return;
             } else {
                 if ($argcount == 2) {
                     $arg1_type = UnionType::fromNode($context, $code_base, $arglist->children[0]);
                     $arg2_type = UnionType::fromNode($context, $code_base, $arglist->children[1]);
                     if ((string) $arg1_type == 'array') {
                         if (!$arg1_type->canCastToUnionType(StringType::instance()->asUnionType())) {
                             Log::err(Log::EPARAM, "arg#2(glue) is {$arg2_type} but {$method->getFQSEN()}() takes string when arg#1 is array", $context->getFile(), $context->getLineNumberStart());
                         }
                     } else {
                         if ((string) $arg1_type == 'string') {
                             if (!$arg2_type->canCastToUnionType(ArrayType::instance()->asUnionType())) {
                                 Log::err(Log::EPARAM, "arg#2(pieces) is {$arg2_type} but {$method->getFQSEN()}() takes array when arg#1 is string", $context->getFile(), $context->getLineNumberStart());
                             }
                         }
                     }
                     return;
                 }
             }
             // Any other arg counts we will let the regular
             // checks handle
             break;
         case 'array_udiff':
         case 'array_diff_uassoc':
         case 'array_uintersect_assoc':
         case 'array_intersect_ukey':
             if ($argcount < 3) {
                 Log::err(Log::EPARAM, "call with {$argcount} arg(s) to {$method->getFQSEN()}() which requires {$method->getNumberOfRequiredParameters()} arg(s)", $context->getFile(), $context->getLineNumberStart());
                 return;
             }
             self::analyzeNodeUnionTypeCast($arglist->children[$argcount - 1], $context, $code_base, CallableType::instance()->asUnionType(), "The last argument to {$method->getFQSEN()} must be a callable");
             for ($i = 0; $i < $argcount - 1; $i++) {
                 self::analyzeNodeUnionTypeCast($arglist->children[$i], $context, $code_base, CallableType::instance()->asUnionType(), "arg#" . ($i + 1) . " is %s but {$method->getFQSEN()}() takes array");
             }
             return;
         case 'array_diff_uassoc':
         case 'array_uintersect_uassoc':
             if ($argcount < 4) {
                 Log::err(Log::EPARAM, "call with {$argcount} arg(s) to {$method->getFQSEN()}() which requires {$method->getNumberOfRequiredParameters()} arg(s)", $context->getFile(), $context->getLineNumberStart());
                 return;
             }
             // The last 2 arguments must be a callable and there
             // can be a variable number of arrays before it
             self::analyzeNodeUnionTypeCast($arglist->children[$argcount - 1], $context, $code_base, CallableType::instance()->asUnionType(), "The last argument to {$method->getFQSEN()} must be a callable");
             self::analyzeNodeUnionTypeCast($arglist->children[$argcount - 2], $context, $code_base, CallableType::instance()->asUnionType(), "The second last argument to {$method->getFQSEN()} must be a callable");
             for ($i = 0; $i < $argcount - 2; $i++) {
                 self::analyzeNodeUnionTypeCast($arglist->children[$i], $context, $code_base, ArrayType::instance()->asUnionType(), "arg#" . ($i + 1) . " is %s but {$method->getFQSEN()}() takes array");
             }
             return;
         case 'strtok':
             // (string str, string token) or (string token)
             if ($argcount == 1) {
                 // If we have just one arg it must be a string token
                 self::analyzeNodeUnionTypeCast($arglist->children[0], $context, $code_base, ArrayType::instance()->asUnionType(), "arg#1(token) is %s but {$method->getFQSEN()}() takes string when passed only one arg");
             }
             // The arginfo check will handle the other case
             break;
         case 'min':
         case 'max':
             if ($argcount == 1) {
                 // If we have just one arg it must be an array
                 if (!self::analyzeNodeUnionTypeCast($arglist->children[0], $context, $code_base, ArrayType::instance()->asUnionType(), "arg#1(values) is %s but {$method->getFQSEN()}() takes array when passed only one arg")) {
                     return;
                 }
             }
             // The arginfo check will handle the other case
             break;
         default:
             break;
     }
 }
Esempio n. 10
0
 /**
  * 与えられた値を、指定された型に変換して返します。
  * @link https://heycam.github.io/webidl/#idl-types Web IDL (Second Edition)
  * @link https://www.w3.org/TR/WebIDL/#idl-types Web IDL
  * @param string $type
  * @param mixed $value
  * @param array $pseudoTypes callback interface 型、列挙型、callback 関数型、または dictionary 型の識別子をキーとした型情報の配列。
  * @return mixed
  */
 public static function to($type, $value, $pseudoTypes = null)
 {
     switch ($type) {
         case 'any':
             $returnValue = $value;
             break;
         case 'boolean':
             $returnValue = BooleanType::toBoolean($value);
             break;
         case '[EnforceRange] byte':
             $returnValue = IntegerType::toByte($value, '[EnforceRange]');
             break;
         case '[Clamp] byte':
             $returnValue = IntegerType::toByte($value, '[Clamp]');
             break;
         case 'byte':
             $returnValue = IntegerType::toByte($value);
             break;
         case '[EnforceRange] octet':
             $returnValue = IntegerType::toOctet($value, '[EnforceRange]');
             break;
         case '[Clamp] octet':
             $returnValue = IntegerType::toOctet($value, '[Clamp]');
             break;
         case 'octet':
             $returnValue = IntegerType::toOctet($value);
             break;
         case '[EnforceRange] short':
             $returnValue = IntegerType::toShort($value, '[EnforceRange]');
             break;
         case '[Clamp] short':
             $returnValue = IntegerType::toShort($value, '[Clamp]');
             break;
         case 'short':
             $returnValue = IntegerType::toShort($value);
             break;
         case '[EnforceRange] unsigned short':
             $returnValue = IntegerType::toUnsignedShort($value, '[EnforceRange]');
             break;
         case '[Clamp] unsigned short':
             $returnValue = IntegerType::toUnsignedShort($value, '[Clamp]');
             break;
         case 'unsigned short':
             $returnValue = IntegerType::toUnsignedShort($value);
             break;
         case '[EnforceRange] long':
             $returnValue = IntegerType::toLong($value, '[EnforceRange]');
             break;
         case '[Clamp] long':
             $returnValue = IntegerType::toLong($value, '[Clamp]');
             break;
         case 'long':
             $returnValue = IntegerType::toLong($value);
             break;
         case '[EnforceRange] unsigned long':
             $returnValue = IntegerType::toUnsignedLong($value, '[EnforceRange]');
             break;
         case '[Clamp] unsigned long':
             $returnValue = IntegerType::toUnsignedLong($value, '[Clamp]');
             break;
         case 'unsigned long':
             $returnValue = IntegerType::toUnsignedLong($value);
             break;
         case '[EnforceRange] long long':
             $returnValue = IntegerType::toLongLong($value, '[EnforceRange]');
             break;
         case '[Clamp] long long':
             $returnValue = IntegerType::toLongLong($value, '[Clamp]');
             break;
         case 'long long':
             $returnValue = IntegerType::toLongLong($value);
             break;
         case '[EnforceRange] unsigned long long':
             $returnValue = IntegerType::toUnsignedLongLong($value, '[EnforceRange]');
             break;
         case '[Clamp] unsigned long long':
             $returnValue = IntegerType::toUnsignedLongLong($value, '[Clamp]');
             break;
         case 'unsigned long long':
             $returnValue = IntegerType::toUnsignedLongLong($value);
             break;
         case 'float':
             $returnValue = FloatType::toFloat($value);
             break;
         case 'unrestricted float':
             $returnValue = FloatType::toUnrestrictedFloat($value);
             break;
         case 'double':
             $returnValue = FloatType::toDouble($value);
             break;
         case 'unrestricted double':
             $returnValue = FloatType::toUnrestrictedDouble($value);
             break;
         case 'DOMString':
             $returnValue = StringType::toDOMString($value);
             break;
         case 'ByteString':
             $returnValue = StringType::toByteString($value);
             break;
         case 'USVString':
             $returnValue = StringType::toUSVString($value);
             break;
         case 'object':
             $returnValue = ObjectType::toObject($value);
             break;
         case 'Date':
             $returnValue = ObjectType::toInterface($value, 'DateTimeInterface');
             break;
         case 'RegExp':
             $returnValue = RegExpType::toRegExp($value);
             break;
         case 'Error':
             $returnValue = self::to('(esperecyan\\webidl\\Error or DOMException)', $value, $pseudoTypes);
             break;
         case 'DOMException':
             $returnValue = ObjectType::toInterface($value, 'DOMException');
             break;
         default:
             $pattern = '/^(?:(?<nullable>.+)\\?|sequence<(?<sequence>.+)>|(?<array>.+)\\[]|(?<union>\\(.+\\))|FrozenArray<(?<FrozenArray>.+)>)$/u';
             if (preg_match($pattern, $type, $matches) === 1) {
                 if (!empty($matches['nullable'])) {
                     $returnValue = NullableType::toNullable($value, $matches['nullable'], $pseudoTypes);
                 } elseif (!empty($matches['sequence'])) {
                     $returnValue = SequenceType::toSequence($value, $matches['sequence'], $pseudoTypes);
                 } elseif (!empty($matches['array'])) {
                     $returnValue = SequenceType::toArray($value, $matches['array'], $pseudoTypes);
                 } elseif (!empty($matches['union'])) {
                     $returnValue = UnionType::toUnion($value, $matches['union'], $pseudoTypes);
                 } elseif (!empty($matches['FrozenArray'])) {
                     $returnValue = SequenceType::toFrozenArray($value, $matches['FrozenArray'], $pseudoTypes);
                 }
             } elseif (isset($pseudoTypes[$type])) {
                 $pseudoType = $pseudoTypes[$type];
                 switch ($pseudoType) {
                     case 'callback interface':
                     case 'single operation callback interface':
                         $returnValue = ObjectType::toCallbackInterface($value, $pseudoType === 'single operation callback interface');
                         break;
                     case 'callback function':
                         $returnValue = ObjectType::toCallbackFunction($value);
                         break;
                     default:
                         if (is_string($pseudoType) || isset($pseudoType[0])) {
                             $returnValue = StringType::toEnumerationValue($value, $type, $pseudoType);
                         } else {
                             $returnValue = DictionaryType::toDictionary($value, $type, $pseudoTypes);
                         }
                 }
             } else {
                 $returnValue = ObjectType::toInterface($value, $type);
             }
     }
     return $returnValue;
 }
Esempio n. 11
0
 /**
  * @param string $value
  * @param string[]|string $enum
  * @expectedException \DomainException
  * @expectedExceptionMessage Expected DOMString (a UTF-8 string) and valid EnumTest value, got
  * @dataProvider invalidEnumerationValueProvider2
  */
 public function testInvalidEnumerationValue3($value, $enum)
 {
     StringType::toEnumerationValue($value, 'EnumTest', $enum);
 }