コード例 #1
0
 /**
  * use an input item's data type to work out which method we should
  * call
  *
  * @param  mixed $item
  *         the item we want to dispatch
  * @param  array $dispatchTable
  *         the list of methods that are available
  * @param  string $fallback
  *         the value to return if there's no suitable entry for $item
  *         in $dispatchTable
  * @return string
  *         the name of the method to call
  */
 public static function using($item, array $dispatchTable, $fallback = TypeMapper::FALLBACK_RESULT)
 {
     $itemTypes = GetStrictTypes::from($item);
     // do any of these types appear in our dispatch table?
     foreach ($itemTypes as $itemType) {
         if (isset($dispatchTable[$itemType])) {
             return $dispatchTable[$itemType];
         }
     }
     // if we get here, then there's no entry in the dispatch table
     // for $item
     return $fallback;
 }
コード例 #2
0
/**
 * return any data type's type name list
 *
 * @param  mixed $item
 *         the item to examine
 * @return array
 *         the list of type(s) that this item can be
 */
function get_strict_types($item)
{
    return GetStrictTypes::from($item);
}
コード例 #3
0
 /**
  * @covers ::from
  */
 public function testDetectsCallableStrings()
 {
     // ----------------------------------------------------------------
     // setup your test
     $data = 'is_string';
     $expectedResult = ['callable' => 'callable', 'string' => 'string'];
     // ----------------------------------------------------------------
     // perform the change
     $actualResult = GetStrictTypes::from($data);
     // ----------------------------------------------------------------
     // test the results
     $this->assertEquals($expectedResult, $actualResult);
 }