Skip to content

Commit 41a71b5

Browse files
committed
Merge branch 'release/2.0.2'
2 parents a724eb7 + 1d94292 commit 41a71b5

File tree

7 files changed

+26
-54
lines changed

7 files changed

+26
-54
lines changed

.php_cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,6 @@ $finder = PhpCsFixer\Finder::create()
77
return PhpCsFixer\Config::create()
88
->setUsingCache(false)
99
->setRules(array(
10-
'@PSR2' => true,
1110
'@PhpCsFixer' => true,
12-
'array_syntax' => [
13-
'syntax' => 'short',
14-
],
15-
'binary_operator_spaces' => true,
16-
'no_whitespace_in_blank_line' => true,
17-
'ternary_operator_spaces' => true,
18-
'cast_spaces' => true,
19-
'trailing_comma_in_multiline_array' => true,
20-
'concat_space' => [
21-
'spacing' => 'one',
22-
],
23-
'blank_line_before_statement' => [
24-
'statements' => [
25-
'return',
26-
'declare',
27-
],
28-
],
29-
'php_unit_test_class_requires_covers' => false,
3011
))
3112
->setFinder($finder);

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# CHANGELOG
22

3+
## 2.0.2 - 2021/02/03
4+
- Review .php_cs settings, apply PHP CS Fixer
5+
- Fix minor typo
6+
7+
## 2.0.1 - 2021/01/28
8+
- Improve Travis CI settings and badge
9+
310
## 2.0.0 - 2021/01/26
4-
- use `splitbrain/phpfarm:jessie` as Docker image and fix docker image settings
11+
- Use `splitbrain/phpfarm:jessie` as Docker image and fix docker image settings
512
- Code requires PHP >= 7.4
613
- Code cleaning
714
- Update README

src/Element.php

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,26 @@ class Element
3535

3636
/**
3737
* Array of attributes that must contains the element.
38-
*
39-
* @var array
4038
*/
4139
protected array $attributes = [];
4240

4341
/**
4442
* The namespace the element belongs to.
45-
*
46-
* @var string
4743
*/
4844
protected string $namespace = '';
4945

5046
/**
5147
* Nonce used to generate digest password.
52-
*
53-
* @var string
5448
*/
5549
protected string $nonceValue;
5650

5751
/**
5852
* Timestamp used to generate digest password.
59-
*
60-
* @var int
6153
*/
6254
protected int $timestampValue;
6355

6456
/**
6557
* Current DOMDocument used to generate XML content.
66-
*
67-
* @var DOMDocument|null
6858
*/
6959
protected static ?DOMDocument $dom = null;
7060

@@ -74,7 +64,8 @@ public function __construct(string $name, string $namespace, $value = null, arra
7464
->setName($name)
7565
->setNamespace($namespace)
7666
->setValue($value)
77-
->setAttributes($attributes);
67+
->setAttributes($attributes)
68+
;
7869
}
7970

8071
/**
@@ -93,7 +84,8 @@ protected function __toSend(bool $asDomElement = false)
9384
// Define element value, add attributes if there are any
9485
$this
9586
->appendValueToElementToSend($this->getValue(), $element)
96-
->appendAttributesToElementToSend($element);
87+
->appendAttributesToElementToSend($element)
88+
;
9789

9890
// Returns element content
9991
if ($asDomElement) {
@@ -108,7 +100,6 @@ public function getName(): string
108100
return $this->name;
109101
}
110102

111-
112103
public function setName($name): self
113104
{
114105
$this->name = $name;
@@ -185,8 +176,6 @@ public function setNonceValue(string $nonceValue): self
185176
}
186177

187178
/**
188-
* @param bool $formatted
189-
*
190179
* @return int|string
191180
*/
192181
public function getTimestampValue(bool $formatted = false)
@@ -203,8 +192,6 @@ public function setTimestampValue(int $timestampValue): self
203192

204193
/**
205194
* Returns the element to send as WS-Security header.
206-
*
207-
* @return string
208195
*/
209196
public function toSend(): string
210197
{
@@ -216,8 +203,7 @@ public function toSend(): string
216203
/**
217204
* Handle adding value to element according to the value type.
218205
*
219-
* @param mixed $value
220-
* @param DOMElement $element
206+
* @param mixed $value
221207
*
222208
* @return Element
223209
*/
@@ -269,26 +255,25 @@ protected function appendAttributesToElementToSend(DOMElement $element): self
269255

270256
/**
271257
* Returns the name with its namespace.
272-
*
273-
* @return string
274258
*/
275259
protected function getNamespacedName(): string
276260
{
277261
return sprintf('%s:%s', $this->getNamespacePrefix(), $this->getName());
278262
}
279263

280-
/**
281-
* @return string
282-
*/
283264
private function getNamespacePrefix(): string
284265
{
285266
$namespacePrefix = '';
267+
286268
switch ($this->getNamespace()) {
287269
case self::NS_WSSE:
288270
$namespacePrefix = self::NS_WSSE_NAME;
271+
289272
break;
273+
290274
case self::NS_WSSU:
291275
$namespacePrefix = self::NS_WSSU_NAME;
276+
292277
break;
293278
}
294279

src/Password.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public function __construct(string $password, string $typeValue = self::TYPE_PAS
2121
$this
2222
->setTypeValue($typeValue)
2323
->setTimestampValue($timestampValue ? $timestampValue : time())
24-
->setNonceValue((string) mt_rand());
24+
->setNonceValue((string) mt_rand())
25+
;
2526

2627
parent::__construct(self::NAME, $namespace, $this->convertPassword($password), [
2728
self::ATTRIBUTE_TYPE => $typeValue,
@@ -39,16 +40,13 @@ public function convertPassword(string $password): string
3940

4041
/**
4142
* When generating the password digest, we define values (nonce and timestamp) that can be used in other place.
42-
*
43-
* @param string $password
44-
* @return string
4543
*/
4644
public function digestPassword(string $password): string
4745
{
4846
$packedNonce = pack('H*', $this->getNonceValue());
4947
$packedTimestamp = pack('a*', $this->getTimestampValue(true));
5048
$packedPassword = pack('a*', $password);
51-
$hash = sha1($packedNonce . $packedTimestamp . $packedPassword);
49+
$hash = sha1($packedNonce.$packedTimestamp.$packedPassword);
5250
$packedHash = pack('H*', $hash);
5351

5452
return base64_encode($packedHash);

src/Security.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ public function __construct(bool $mustUnderstand = false, ?string $actor = null,
2525
parent::__construct(self::NAME, $namespace);
2626

2727
if (true === $mustUnderstand) {
28-
$this->setAttribute($envelopeNamespace . self::ATTRIBUTE_MUST_UNDERSTAND, $mustUnderstand);
28+
$this->setAttribute($envelopeNamespace.self::ATTRIBUTE_MUST_UNDERSTAND, $mustUnderstand);
2929
}
3030

3131
if (!empty($actor)) {
32-
$this->setAttribute($envelopeNamespace . self::ATTRIBUTE_ACTOR, $actor);
32+
$this->setAttribute($envelopeNamespace.self::ATTRIBUTE_ACTOR, $actor);
3333
}
3434
}
3535

src/WsSecurity.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protected function __construct(
1919
int $addExpires = 0,
2020
bool $mustUnderstand = false,
2121
?string $actor = null,
22-
?String $usernameId = null,
22+
?string $usernameId = null,
2323
bool $addNonce = true,
2424
string $envelopeNamespace = Security::ENV_NAMESPACE
2525
) {
@@ -46,7 +46,7 @@ public static function createWsSecuritySoapHeader(
4646
int $addExpires = 0,
4747
bool $returnSoapHeader = true,
4848
bool $mustUnderstand = false,
49-
?String $actor = null,
49+
?string $actor = null,
5050
?string $usernameId = null,
5151
bool $addNonce = true,
5252
string $envelopeNamespace = Security::ENV_NAMESPACE
@@ -102,7 +102,7 @@ protected function setCreated(int $addCreated): self
102102
{
103103
$passwordDigest = $this->getPassword()->getTypeValue();
104104
$timestampValue = $this->getPassword()->getTimestampValue();
105-
if (($addCreated || Password::TYPE_PASSWORD_DIGEST === $passwordDigest) && $timestampValue > 0) {
105+
if (($addCreated || Password::TYPE_PASSWORD_DIGEST === $passwordDigest) && 0 < $timestampValue) {
106106
$this->getUsernameToken()->setCreated(new Created($timestampValue));
107107
}
108108

tests/WsSecurityTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
/**
1111
* @internal
12+
* @coversDefaultClass
1213
*/
1314
final class WsSecurityTest extends TestCase
1415
{

0 commit comments

Comments
 (0)