Conditions | 3 |
Paths | 3 |
Total Lines | 55 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
50 | public static function from($clientId, $subjectId, $idpEntityId, $spEntityId, array $responseAttributes, $requestIpAddress) |
||
|
|||
51 | { |
||
52 | Assert::string($subjectId, 'The SubjectId must be a string, received "%s"'); |
||
53 | Assert::string($idpEntityId, 'The IDPentityID must be a string, received "%s"'); |
||
54 | Assert::string($spEntityId, 'The SPentityID must be a string, received "%s"'); |
||
55 | Assert::allString( |
||
56 | array_keys($responseAttributes), |
||
57 | 'The keys of the Response attributes must be strings' |
||
58 | ); |
||
59 | Assert::allIsArray($responseAttributes, 'The values of the Response attributes must be arrays'); |
||
60 | Assert::string($clientId, 'The client ID must be a string, received "%s"'); |
||
61 | Assert::string($requestIpAddress, 'The request IP address must be a string, received "%s"'); |
||
62 | |||
63 | $request = new self; |
||
64 | |||
65 | $subjectIdAttribute = new Attribute; |
||
66 | $subjectIdAttribute->attributeId = self::NAMEIDFORMAT_UNSPECIFIED; |
||
67 | $subjectIdAttribute->value = $subjectId; |
||
68 | |||
69 | $request->accessSubject = new AccessSubject; |
||
70 | $request->accessSubject->attributes = [$subjectIdAttribute]; |
||
71 | |||
72 | $spEntityIdAttribute = new Attribute; |
||
73 | $spEntityIdAttribute->attributeId = 'SPentityID'; |
||
74 | $spEntityIdAttribute->value = $spEntityId; |
||
75 | |||
76 | $idpEntityIdAttribute = new Attribute; |
||
77 | $idpEntityIdAttribute->attributeId = 'IDPentityID'; |
||
78 | $idpEntityIdAttribute->value = $idpEntityId; |
||
79 | |||
80 | $clientIdAttribute = new Attribute; |
||
81 | $clientIdAttribute->attributeId = 'ClientID'; |
||
82 | $clientIdAttribute->value = $clientId; |
||
83 | |||
84 | $request->resource = new Resource; |
||
85 | $request->resource->attributes = [$clientIdAttribute, $spEntityIdAttribute, $idpEntityIdAttribute]; |
||
86 | |||
87 | foreach ($responseAttributes as $id => $values) { |
||
88 | foreach ($values as $value) { |
||
89 | $attribute = new Attribute; |
||
90 | $attribute->attributeId = $id; |
||
91 | $attribute->value = $value; |
||
92 | |||
93 | $request->accessSubject->attributes[] = $attribute; |
||
94 | } |
||
95 | } |
||
96 | |||
97 | $ipAddressAttribute = new Attribute; |
||
98 | $ipAddressAttribute->attributeId = self::XACML_ATTRIBUTE_IP_ADDRESS; |
||
99 | $ipAddressAttribute->value = $requestIpAddress; |
||
100 | |||
101 | $request->accessSubject->attributes[] = $ipAddressAttribute; |
||
102 | |||
103 | return $request; |
||
104 | } |
||
105 | |||
116 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.