Browscap\Data\DataCollection::checkProperty PHP Method

checkProperty() public method

public checkProperty ( string $key, array $properties ) : boolean
$key string
$properties array
return boolean
    public function checkProperty($key, array $properties)
    {
        $this->getLogger()->debug('check if all required propeties are available');
        if (!isset($properties['Version'])) {
            throw new \UnexpectedValueException('Version property not found for key "' . $key . '"');
        }
        if (!isset($properties['Parent']) && !in_array($key, ['DefaultProperties', '*'])) {
            throw new \UnexpectedValueException('Parent property is missing for key "' . $key . '"');
        }
        if (!isset($properties['Device_Type'])) {
            throw new \UnexpectedValueException('property "Device_Type" is missing for key "' . $key . '"');
        }
        if (!isset($properties['isTablet'])) {
            throw new \UnexpectedValueException('property "isTablet" is missing for key "' . $key . '"');
        }
        if (!isset($properties['isMobileDevice'])) {
            throw new \UnexpectedValueException('property "isMobileDevice" is missing for key "' . $key . '"');
        }
        switch ($properties['Device_Type']) {
            case 'Tablet':
                if (true !== $properties['isTablet']) {
                    throw new \UnexpectedValueException('the device of type "' . $properties['Device_Type'] . '" is NOT marked as Tablet for key "' . $key . '"');
                }
                if (true !== $properties['isMobileDevice']) {
                    throw new \UnexpectedValueException('the device of type "' . $properties['Device_Type'] . '" is NOT marked as Mobile Device for key "' . $key . '"');
                }
                break;
            case 'Mobile Phone':
            case 'Mobile Device':
            case 'Ebook Reader':
            case 'Console':
            case 'Digital Camera':
                if (true === $properties['isTablet']) {
                    throw new \UnexpectedValueException('the device of type "' . $properties['Device_Type'] . '" is marked as Tablet for key "' . $key . '"');
                }
                if (true !== $properties['isMobileDevice']) {
                    throw new \UnexpectedValueException('the device of type "' . $properties['Device_Type'] . '" is NOT marked as Mobile Device for key "' . $key . '"');
                }
                break;
            case 'TV Device':
            case 'Desktop':
            default:
                if (true === $properties['isTablet']) {
                    throw new \UnexpectedValueException('the device of type "' . $properties['Device_Type'] . '" is marked as Tablet for key "' . $key . '"');
                }
                if (true === $properties['isMobileDevice']) {
                    throw new \UnexpectedValueException('the device of type "' . $properties['Device_Type'] . '" is marked as Mobile Device for key "' . $key . '"');
                }
                break;
        }
        return true;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * tests if no error is raised if all went well
  *
  * @group data
  * @group sourcetest
  */
 public function testCheckPropertyOk()
 {
     $this->object->setLogger($this->logger);
     $properties = array('Version' => 'abc', 'Parent' => '123', 'Device_Type' => 'Desktop', 'isTablet' => false, 'isMobileDevice' => false);
     self::assertTrue($this->object->checkProperty('test', $properties));
 }