Skip to content

Commit 91299f3

Browse files
committed
SDK-766: Clarify handling of CONTENT_TYPE_UNDEFINED and CONTENT_TYPE_STRING
1 parent f5d4ddc commit 91299f3

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/Yoti/Util/Profile/AttributeConverter.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212

1313
class AttributeConverter
1414
{
15-
const CONTENT_TYPE_JSON = 5;
16-
const CONTENT_TYPE_PNG = 4;
15+
const CONTENT_TYPE_UNDEFINED = 0;
16+
const CONTENT_TYPE_STRING = 1;
1717
const CONTENT_TYPE_JPEG = 2;
1818
const CONTENT_TYPE_DATE = 3;
19+
const CONTENT_TYPE_PNG = 4;
20+
const CONTENT_TYPE_JSON = 5;
1921
const CONTENT_TYPE_MULTI_VALUE = 6;
2022

2123
/**
@@ -62,7 +64,7 @@ private static function convertValueBasedOnContentType($value, $contentType)
6264
case self::CONTENT_TYPE_JPEG:
6365
case self::CONTENT_TYPE_PNG:
6466
$imageExtension = self::imageTypeToExtension($contentType);
65-
$value = new Image($value, $imageExtension);
67+
return new Image($value, $imageExtension);
6668
break;
6769

6870
case self::CONTENT_TYPE_JSON:
@@ -71,18 +73,24 @@ private static function convertValueBasedOnContentType($value, $contentType)
7173
if (json_last_error()) {
7274
throw new AttributeException("Error converting attr to a JSON Object");
7375
}
76+
return $value;
7477
break;
7578

7679
case self::CONTENT_TYPE_DATE:
77-
$value = self::convertTimestampToDate($value);
80+
return self::convertTimestampToDate($value);
7881
break;
7982

8083
case self::CONTENT_TYPE_MULTI_VALUE:
81-
$value = self::convertMultiValue($value);
84+
return self::convertMultiValue($value);
8285
break;
83-
}
8486

85-
return $value;
87+
case self::CONTENT_TYPE_UNDEFINED:
88+
throw new AttributeException("Content Type is undefined");
89+
90+
case self::CONTENT_TYPE_STRING:
91+
default:
92+
return $value;
93+
}
8694
}
8795

8896
/**

tests/Util/Profile/AttributeConverterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class AttributeConverterTest extends TestCase
1818
* Content Types.
1919
*/
2020
const CONTENT_TYPE_STRING = 1;
21-
const CONTENT_TYPE_PNG = 4;
2221
const CONTENT_TYPE_JPEG = 2;
22+
const CONTENT_TYPE_PNG = 4;
2323
const CONTENT_TYPE_MULTI_VALUE = 6;
2424

2525
/**

0 commit comments

Comments
 (0)