/** * @dataProvider variableNameDataProvider * @param mixed $value * @param integer $occurence * @param string $expected */ public function testVariableName($value, $occurence, $expected) { $this->assertEquals($expected, PhpMarshallingUtils::variableName($value, $occurence)); }
/** * Generates a suitable variable name to be used for a given value. * * @param mixed $value A value. * @return string A variable name without the leading dollar sign ('$'). */ public function generateVariableName($value) { $occurence = 0; if (is_object($value) === true) { $counter = $this->getObjectCount(); $className = get_class($value); if (isset($counter[$className]) === false) { $occurence = 0; $counter[$className] = $occurence; } else { $occurence = $counter[$className]; } $counter[$className] += 1; $this->setObjectCount($counter); } else { if (is_null($value) === true) { $type = 'null'; } else { $type = gettype($value); } $counter = $this->getDatatypeCount(); $occurence = $counter[$type]; $counter[$type] += 1; $this->setDatatypeCount($counter); } return PhpMarshallingUtils::variableName($value, $occurence); }