Skip to content

Commit e5656af

Browse files
LuborRodRodion Liuborets
andauthored
SDK-2090 getAttributeById (#280)
* SDK-2090 getAttributeById * SDK-2090 Refactor test Co-authored-by: Rodion Liuborets <[email protected]>
1 parent 4f20d25 commit e5656af

31 files changed

+800
-181
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +0,0 @@
1-
parameters:
2-
ignoreErrors:
3-
-
4-
message: "#^Instanceof between Yoti\\\\Protobuf\\\\Sharepubapi\\\\IssuingAttributes and Yoti\\\\Protobuf\\\\Sharepubapi\\\\IssuingAttributes will always evaluate to true\\.$#"
5-
count: 1
6-
path: src/Profile/Util/ExtraData/ThirdPartyAttributeConverter.php
7-

src/Profile/Attribute.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,29 @@ class Attribute
1919
private $value;
2020

2121
/**
22-
* @var \Yoti\Profile\Attribute\Anchor[]
22+
* @var Anchor[]
2323
*/
2424
private $anchors;
2525

26+
/**
27+
* @var string|null
28+
*/
29+
private $id;
30+
2631
/**
2732
* Attribute constructor.
2833
*
2934
* @param string $name
3035
* @param mixed $value
31-
* @param \Yoti\Profile\Attribute\Anchor[] $anchors
36+
* @param Anchor[] $anchors
37+
* @param string|null $id
3238
*/
33-
public function __construct(string $name, $value, array $anchors)
39+
public function __construct(string $name, $value, array $anchors, string $id = null)
3440
{
3541
$this->name = $name;
3642
$this->value = $value;
3743
$this->anchors = $anchors;
44+
$this->id = $id;
3845
}
3946

4047
/**
@@ -54,15 +61,15 @@ public function getValue()
5461
}
5562

5663
/**
57-
* @return \Yoti\Profile\Attribute\Anchor[]
64+
* @return Anchor[]
5865
*/
5966
public function getSources(): array
6067
{
6168
return $this->filterAnchors(Anchor::TYPE_SOURCE_NAME);
6269
}
6370

6471
/**
65-
* @return \Yoti\Profile\Attribute\Anchor[]
72+
* @return Anchor[]
6673
*/
6774
public function getVerifiers(): array
6875
{
@@ -77,7 +84,7 @@ public function getVerifiers(): array
7784
* ...
7885
* ]
7986
*
80-
* @return \Yoti\Profile\Attribute\Anchor[]
87+
* @return Anchor[]
8188
*/
8289
public function getAnchors(): array
8390
{
@@ -87,7 +94,7 @@ public function getAnchors(): array
8794
/**
8895
* @param string $type
8996
*
90-
* @return \Yoti\Profile\Attribute\Anchor[]
97+
* @return Anchor[]
9198
*/
9299
private function filterAnchors(string $type): array
93100
{
@@ -99,4 +106,14 @@ function (Anchor $anchor) use ($type): bool {
99106
);
100107
return array_values($filteredAnchors);
101108
}
109+
110+
/**
111+
* Gets the ID of the attribute
112+
*
113+
* @return string|null
114+
*/
115+
public function getId(): ?string
116+
{
117+
return $this->id;
118+
}
102119
}

src/Profile/BaseProfile.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@ public function getAttributesByName(string $attributeName): array
5555
return $this->attributesMap[$attributeName] ?? [];
5656
}
5757

58+
/**
59+
* Retrieves an attribute which matches the ID specified.
60+
*
61+
* @param string $attributeId
62+
*
63+
* @return Attribute
64+
*/
65+
public function getAttributeById(string $attributeId): ?Attribute
66+
{
67+
foreach ($this->attributesList as $attribute) {
68+
if ($attribute->getId() == $attributeId) {
69+
return $attribute;
70+
}
71+
}
72+
return null;
73+
}
74+
5875
/**
5976
* @param string $attributeName.
6077
*

src/Profile/Util/Attribute/AttributeConverter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,12 @@ public static function convertToYotiAttribute(
160160
$attrValue,
161161
$attrName
162162
);
163+
$attrId = $protobufAttribute->getEphemeralId();
163164
$yotiAttribute = new Attribute(
164165
$attrName,
165166
$attrValue,
166-
$yotiAnchors
167+
$yotiAnchors,
168+
$attrId
167169
);
168170
} catch (AttributeException $e) {
169171
$logger->warning(

src/Protobuf/Attrpubapi/Anchor.php

Lines changed: 32 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Protobuf/Attrpubapi/Attribute.php

Lines changed: 94 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Protobuf/Attrpubapi/AttributeAndId.php

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)