Browscap\Formatter\PhpFormatter::formatPropertyValue PHP Method

formatPropertyValue() public method

formats the name of a property
public formatPropertyValue ( string $value, string $property ) : string
$value string
$property string
return string
    public function formatPropertyValue($value, $property)
    {
        $valueOutput = $value;
        $propertyHolder = new PropertyHolder();
        switch ($propertyHolder->getPropertyType($property)) {
            case PropertyHolder::TYPE_STRING:
                $valueOutput = '"' . trim($value) . '"';
                break;
            case PropertyHolder::TYPE_BOOLEAN:
                if (true === $value || $value === 'true') {
                    $valueOutput = '"true"';
                } elseif (false === $value || $value === 'false') {
                    $valueOutput = '"false"';
                } else {
                    $valueOutput = '';
                }
                break;
            case PropertyHolder::TYPE_IN_ARRAY:
                try {
                    $valueOutput = '"' . $propertyHolder->checkValueInArray($property, $value) . '"';
                } catch (\InvalidArgumentException $ex) {
                    $valueOutput = '';
                }
                break;
            default:
                if (preg_match('/[^a-zA-Z0-9]/', $valueOutput)) {
                    $valueOutput = '"' . $valueOutput . '"';
                }
                // nothing t do here
                break;
        }
        return $valueOutput;
    }

Usage Example

Esempio n. 1
0
 /**
  * tests formatting a property value
  *
  * @dataProvider propertyNameTypeDataProvider
  *
  * @param string $propertyName
  * @param string $inputValue
  * @param string $expectedValue
  *
  * @group formatter
  * @group sourcetest
  */
 public function testFormatPropertyValue($propertyName, $inputValue, $expectedValue)
 {
     $actualValue = $this->object->formatPropertyValue($inputValue, $propertyName);
     self::assertSame($expectedValue, $actualValue, "Property {$propertyName} should be {$expectedValue} (was {$actualValue})");
 }